{"id":33981826,"url":"https://github.com/waq-r/read-time","last_synced_at":"2025-12-13T03:49:55.881Z","repository":{"id":48235311,"uuid":"386299052","full_name":"waq-r/read-time","owner":"waq-r","description":"Get estimated read time of an article. Similar to medium.com's \"x min read\". Multilingual including right-to-left written languages. Supports JSON, Array and String output.","archived":false,"fork":false,"pushed_at":"2021-08-04T23:08:11.000Z","size":70,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-03T21:04:07.352Z","etag":null,"topics":["article","blog","read","time"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waq-r.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-15T13:25:39.000Z","updated_at":"2023-06-10T12:21:07.000Z","dependencies_parsed_at":"2022-09-05T11:31:09.820Z","dependency_job_id":null,"html_url":"https://github.com/waq-r/read-time","commit_stats":null,"previous_names":["vaqar-ahmed/read-time","waqar3/read-time","waq-r/read-time"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/waq-r/read-time","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waq-r%2Fread-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waq-r%2Fread-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waq-r%2Fread-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waq-r%2Fread-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waq-r","download_url":"https://codeload.github.com/waq-r/read-time/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waq-r%2Fread-time/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27699660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["article","blog","read","time"],"created_at":"2025-12-13T03:49:55.357Z","updated_at":"2025-12-13T03:49:55.874Z","avatar_url":"https://github.com/waq-r.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Read Time\n\nCalculates the read time of an article.\n\n### Output string\ne.g: `x min read` or `5 minutes read`.\n\n### Features\n- Multilingual translations support.\n- Static to get simple abbreviated output string in English.\n- Static method to get the integer value of the number of minutes required to read the given text.\n- Multilingual and right-to-left language support.\n- Support for Array output\n- Support for JSON output\n\n## Installation\nInstallation using composer\n```bash\ncomposer require waqarahmed/read-time\n```\n## Usage\n### Static Methods\n\nThere are two static methods `minRead(string $text)` and`time(sting $text)`.\n\n### minRead()\nUse this method for a simple `x min read` message. It returns a rounded minutes number with a `min read` message.\n\n```php\n$text = str_repeat('ad bc ', 251); //502 words in $text\necho ReadTime::minRead($text);\n```\nThe output:\n\n`2 min read`\n\n### time()\n`time()` method returns an array of the number of `minutes` and `seconds` required to read the given $text.\n```php\n$text = str_repeat('ad bc ', 251); //502 words in $text\nReadTime::time($text);\n```\nThe output:\n```php\n['minutes' =\u003e 2, 'seconds' =\u003e 12]\n```\n\n### Class Methods\nCreate an instance of the class to use \n- translation\n- right-to-left language support \n- JSON output\n- array output\n\n### constructor()\nThe Constructor takes and sets these parameters:\n```php\npublic function __construct(\n  string $text, \n  array $translation = null, \n  bool $abbreviate = true, \n  bool $rtl = false, \n  string $language = null,\n  int $wordsPerMinute = 228\n  )\n  ```\n  #### Class defaults\n  - `$wordsPerMinute` default value is `200`\n  - `$rtl` language direction right-to-left is `false` by default\n  - `$translation` default is `null` class outputs the English language by default\n  - `$abbreviate` Abbreviate the word 'minute/minutes' to 'min' is `true` by default\n\n\n### getTime()\nAfter initiating a new class object, call the `getTime()` method to get the result.\nExample:\n`4 minutes read` or `1 minute read` or abbreviated `4 min read`.\n\n### setTextLanguge()\nReading time of different languages vary significantly (S. Klosinski,  K. Dietz). Class method setTextLanguage() has estimated reading times of 17 languages taken from this study.\n\nReference: \"Standardized Assessment of Reading Performance: The New International Reading Speed Texts IReST\"\n\n#### Language (iso-code) Words-per-minutes\nArabic (ar) 138, Chinese (zh) 158, Dutch (nl) 202, English (en) 228, Finnish (fi) 161, French (fr) 195, German (el) 179, Hebrew (he) 187, Italian (it) 188, Japanese (jp) 193, Polish (pl) 166, Portoguese (pt) 181, Russian (ru) 184, Slovenian (sl) 180, Spanish (es) 218, Swedish (sv) 199, Turkish (tr) 166.\n\nEnglish is the default language. Set different languages by passing two letters (ISO 639-1) language codes to the setTextLanguag() method. \n\nAn example: Setting Turkish as the input language.\n ```php\n $text = str_repeat('ad bc ', 251); //502 words in $text\n $result = new ReadTime($this-\u003egenerateText(), ['minute' =\u003e 'dakika', 'minutes' =\u003e 'dakika', 'read' =\u003e 'okuman'], false, false, 'tr');\n echo $result-\u003egetTime();\n ```\n\n### Translation\nPass translation array to the class to set the translations of the words: `minute`, `minutes`, `min` and `read`.\nA passed array must be an associative array with any number of translation strings.\n#### Default property of $translation\n```php\n$translation = [\n        'min'     =\u003e 'min',\n        'minute'  =\u003e 'minute',\n        'minutes' =\u003e 'minutes',\n        'read'    =\u003e 'read',\n    ];\n\n```\n#### Example translation input\n```php\n$text = str_repeat('ad bc ', 251); //502 words in $text\n$result = new ReadTime($this-\u003egenerateText(), ['minute' =\u003e 'minuto', 'minutes' =\u003e 'minutos', 'read' =\u003e 'leer'], false);\necho $result-\u003egetTime();\n```\nThe Spanish translated output: `2 minutos leer`.\n\n#### Right-to-Left Language Translation\nSet `$rtl` property to `true` and pass `$translation` of languages written right-to-left.\n```php\n$text = str_repeat('ad bc ', 251);\n$result = new ReadTime($this-\u003egenerateText(), ['minute' =\u003e 'دقیقه', 'minutes' =\u003e 'دقایق', 'read' =\u003e 'خواندن'], false, true);\necho $result-\u003egetTime();\n```\nPersian translated output: `'خواندن دقایق 2'`\n\n### getJSON()\nMethod to get JSON output of claculated read time and class properties.\n\nA class instance with default properties outputs:\n```php\n$text = str_repeat('hello world ', 251);\n$result = new ReadTime($text);\necho $result-\u003egetJSON();\n```\n\noutputs:\n```javascript\n{\n    \"minutes\": 2,\n    \"time\": {\n        \"minutes\": 2,\n        \"seconds\": 12\n    },\n    \"wordCount\": 502,\n    \"translation\": {\n        \"min\": \"min\",\n        \"minute\": \"minute\",\n        \"minutes\": \"minutes\",\n        \"read\": \"read\"\n    },\n    \"abbreviate\": true,\n    \"wordsPerMinute\": 228\n}\n```\n\n### getArray()\nMethod to get array output of calculated read time and instance properties.\nA class instance with default properties:\n```php\n$text = str_repeat('hello world ', 251);\n$result = new ReadTime($text);\necho $result-\u003egetArray();\n```\nOutputs:\n```php\narray(6) {\n  [\"minutes\"]=\u003e\n  int(2)\n  [\"time\"]=\u003e\n  array(2) {\n    [\"minutes\"]=\u003e\n    int(2)\n    [\"seconds\"]=\u003e\n    int(12)\n  }\n  [\"wordCount\"]=\u003e\n  int(502)\n  [\"translation\"]=\u003e\n  array(4) {\n    [\"min\"]=\u003e\n    string(3) \"min\"\n    [\"minute\"]=\u003e\n    string(6) \"minute\"\n    [\"minutes\"]=\u003e\n    string(7) \"minutes\"\n    [\"read\"]=\u003e\n    string(4) \"read\"\n  }\n  [\"abbreviate\"]=\u003e\n  bool(true)\n  [\"wordsPerMinute\"]=\u003e\n  int(228)\n}\n```\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaq-r%2Fread-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaq-r%2Fread-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaq-r%2Fread-time/lists"}