{"id":19112891,"url":"https://github.com/chipslays/phrase","last_synced_at":"2025-08-25T10:14:00.905Z","repository":{"id":62501864,"uuid":"377612268","full_name":"chipslays/phrase","owner":"chipslays","description":"🌐 Internationalization library for PHP.","archived":false,"fork":false,"pushed_at":"2021-09-25T09:20:12.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-31T19:56:01.975Z","etag":null,"topics":["internationalization-library","lightweight","localization","php","translation"],"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/chipslays.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-16T19:56:43.000Z","updated_at":"2021-09-25T09:20:14.000Z","dependencies_parsed_at":"2022-11-02T12:01:19.659Z","dependency_job_id":null,"html_url":"https://github.com/chipslays/phrase","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/chipslays/phrase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphrase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphrase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphrase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphrase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chipslays","download_url":"https://codeload.github.com/chipslays/phrase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphrase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267277007,"owners_count":24063226,"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-07-26T02:00:08.937Z","response_time":62,"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":["internationalization-library","lightweight","localization","php","translation"],"created_at":"2024-11-09T04:34:26.982Z","updated_at":"2025-07-27T00:38:04.118Z","avatar_url":"https://github.com/chipslays.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌐 Phrase\n\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/chipslays/phrase/tests)\n![GitHub](https://img.shields.io/github/license/chipslays/phrase?color=%23a6957c)\n\nInternationalization library for PHP.\n\n## Features\n* Translations based on [`JSON`](examples/locales/json), [`YAML`](examples/locales/yaml) files;\n* Easy addition of new [sources files](src/Engine);\n* Interpolated translations;\n* Pluralization;\n\n## Installation\n\n```bash\ncomposer require chipslays/phrase\n```\n\n## Setup\n\nLocale file: `locales/yaml/en_US.yml`\n```yaml\n# interpolated message\nhello: Hello {name}!\n\n# pluralization\nplural: I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.\n\n# message can be a array\narray:\n  text: This is my flag.\n  image: images/en-flag.jpg\n  myKey: myValue\n```\n\nLocale file: `locales/json/en_US.json`\n```json\n{\n    \"hello\": \"Hello {name}!\",\n    \"plural\": \"I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.\",\n    \"array\": {\n        \"text\": \"This is my flag.\",\n        \"image\": \"images/en-flag.jpg\"\n    }\n}\n```\n\n## Usage\n\n### Create `Phrase` instance\n\n```php\n// Engine constructor\n__construct(string $root, string $locale, ?string $fallback);\n```\n\n```php\nuse Chipslays\\Phrase\\Phrase;\nuse Chipslays\\Phrase\\Engine\\JsonEngine;\n\n$engine = new JsonEngine(__DIR__ . '/locales/json', 'en_US');\n$phrase = new Phrase($engine);\n$phrase-\u003eget(...);\n```\n\n```php\nuse Chipslays\\Phrase\\Phrase;\nuse Chipslays\\Phrase\\Engine\\YamlEngine;\n\n$engine = new YamlEngine(__DIR__ . '/locales/yaml', 'en_US');\n$phrase = new Phrase($engine);\n$phrase-\u003eget(...);\n```\n\n```php\nuse Chipslays\\Phrase\\Phrase;\nuse Chipslays\\Phrase\\Engine\\JsonEngine;\n\n$engine = new JsonEngine(__DIR__ . '/locales/json', 'en_US');\nPhrase::setEngine($engine);\nPhrase::get(...);\n```\n\n### Get message\n\n```php\n$phrase-\u003eget(string $key, ?array $replace = null, ?string $locale = null);\n\n# key - locale message key\n# replace - array with interpolation\n# locale - force locale (useful when using multiple locales at the same time)\n```\n\n\n```php\n$phrase-\u003eget('hello');\nPhrase::get('hello');\n__('hello');\n```\n\nPass language code for force use.\n\n```php\n$phrase-\u003eget('hello', null, 'ru_RU');\nPhrase::get('hello', null, 'ru_RU');\n__('hello', null, 'ru_RU');\n```\n\n### Interpolation\n\nPass named arguments to interpolate your translations.\n\n```php\n$phrase-\u003eget('hello', ['{name}' =\u003e 'John Doe']);\nPhrase::get('hello', ['{name}' =\u003e 'John Doe']);\n__('hello', ['{name}' =\u003e 'John Doe']);\n\n// Hello John Doe!\n```\n\n### Pluralization\n\nEnglish pluralization phrase:\n```\n{{eng:{count},melon}}\n```\n\nRussian pluralization phrase:\n```\n{{rus:{count},арбуз,арбуза,арбузов}}\n```\n\n```yaml\n# english locale file\n# for english plural word have 1 form\n...\nplural: I have {count} {{eng:{count},melon}} and {money} {{eng:{money},dollar}}.\n....\n```\n\n```yaml\n# russian locale file\n# for russian plural word have 3 forms\n...\nplural: У меня есть {count} {{rus:{count},арбуз,арбуза,арбузов}} и {money} {{rus:{money},рубль,рубля,рублей}}\n....\n```\n\n```php\n$phrase-\u003eget('plural', ['{count}' =\u003e 1, '{money}' =\u003e 100])\nPhrase::get('plural', ['{count}' =\u003e 1, '{money}' =\u003e 100])\n__('plural', ['{count}' =\u003e 1, '{money}' =\u003e 100])\n\n// I have 1 melon and 100 dollars.\n```\n\n### Merge locale messages (`load`, `patch`)\n\nUse `patch` method if you need to add messages to an already loaded file.\n\nIf this locale was not previously loaded, it will simply be loaded.\n\nUse `load` method for delete and overwrite all previous messages by locale.\n\n```php\nuse Chipslays\\Phrase\\Phrase;\nuse Chipslays\\Phrase\\Engine\\YamlEngine;\n\n$engine = new YamlEngine(__DIR__ . '/locales/yaml', 'en_US');\n$phrase = new Phrase($engine);\n\n// this method loaded en_US.yml file from MyPlugin dir and merge with previously loaded locale en_US\n$phrase-\u003epatch(__DIR__ . '/locales/plugins/MyPlugin/', 'en_US');\n\n// this method delete and overwrite all previous messages\n$phrase-\u003eload(__DIR__ . '/locales/yaml', 'en_US');\n\n```\n\n```php\nuse Chipslays\\Phrase\\Plural;\n\necho Plural::eng(10, 'melon'); // melons\necho Plural::rus(10, ['арбуз', 'арбуза', 'арбузов']); // арбузов\n```\n\n### Helpers\n```php\n__(string $key, ?array $replace = null, ?string $locale = null): string|array\n```\n\n```php\n__('hello', ['{name}' =\u003e 'John Doe'], 'en_US');\n```\n\n### Custom locale file (Engine)\n\nExample for `YamlEngine`:\n\n```php\nuse Chipslays\\Phrase\\Engine\\AbstractEngine;\nuse Chipslays\\Phrase\\Exceptions\\PhraseException;\n\nclass YamlEngine extends AbstractEngine\n{\n    /**\n     * @param string $locale\n     * @return void\n     *\n     * @throws PhraseException\n     */\n    protected function load(string $locale): void\n    {\n        $path = $this-\u003eroot . '/' . $locale . '.yml';\n\n        if (!file_exists($path)) {\n            throw new PhraseException(\"Locale file not found in path {$path}\", 1);\n        }\n\n        $this-\u003elocales[$locale] = yaml_parse_file($path);\n    }\n}\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fphrase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchipslays%2Fphrase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fphrase/lists"}