{"id":15296471,"url":"https://github.com/compositephp/localization","last_synced_at":"2026-01-26T08:33:01.615Z","repository":{"id":62035061,"uuid":"556050821","full_name":"compositephp/localization","owner":"compositephp","description":"PHP 8.1 Language localization and pluralization","archived":false,"fork":false,"pushed_at":"2022-10-24T22:13:15.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T05:26:43.554Z","etag":null,"topics":["easy-to-use","localization","php","php81","pluralization","translations"],"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/compositephp.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":"2022-10-23T00:11:20.000Z","updated_at":"2022-10-24T22:16:10.000Z","dependencies_parsed_at":"2022-10-25T12:45:27.516Z","dependency_job_id":null,"html_url":"https://github.com/compositephp/localization","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Flocalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Flocalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Flocalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Flocalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compositephp","download_url":"https://codeload.github.com/compositephp/localization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245407755,"owners_count":20610232,"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","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":["easy-to-use","localization","php","php81","pluralization","translations"],"created_at":"2024-09-30T18:10:39.734Z","updated_at":"2026-01-26T08:32:56.595Z","avatar_url":"https://github.com/compositephp.png","language":"PHP","readme":"# Composite Localization\n\nSimple translation and pluralization php library based on files. \n\nOverview:\n- [Requirements](#requirements) \n- [Installation](#installation) \n- [Localization](#localization) \n- [Pluralization](#pluralization) \n\n## Requirements\n\n* PHP 8.1+\n* PDO Extension with desired database drivers\n\n## Installation\n\nInstall package via composer:\n\n```shell\n$ composer require compositephp/localization\n```\n\n## Localization\n\nFirst, you need to create new class and extend from `Composite\\Localization\\AbstractLocalization`\n\n```php\nuse Composite\\Localization\\AbstractLocalization;\nuse Composite\\Localization\\Language;\n\nclass Localization extends AbstractLocalization\n{\n    public function __construct(Language $language)\n    {\n        parent::__construct(\n            language: $language,\n            sourcePath: '/directory/to/your/locale/files',\n        );\n    }\n\n    public function general(string $text, array $placeholders = []): string\n    {\n        return $this-\u003eget('general', $text, $placeholders);\n    }\n\n    public function profile(string $text, array $placeholders = []): string\n    {\n        return $this-\u003eget('profile', $text, $placeholders);\n    }\n    //other categories\n    //...\n}\n```\n\nUsage:\n\n```php\n\n```\n\nSecond, create category files in your localization source path `/directory/to/your/locale/files`:\n\n```\n- general.php\n- profile.php\n```\n\nExample content of `general.php`\n\n```php\nuse Composite\\Localization\\Language;\n\nreturn [\n    'Hello World!' =\u003e [\n        Language::FR-\u003evalue =\u003e 'Bonjour le monde!'\n    ],\n    'hello_world' =\u003e [\n        Language::EN-\u003evalue =\u003e 'Hello World!',\n        Language::FR-\u003evalue =\u003e 'Bonjour le monde!',\n    ],\n    'Hello {{first_name}} {{last_name}}!' =\u003e [\n        Language::FR-\u003evalue =\u003e 'Bonjour {{first_name}} {{last_name}}!',\n    ],\n    'hello_fullname' =\u003e [\n        Language::EN-\u003evalue =\u003e 'Hello {{first_name}} {{last_name}}!',\n        Language::FR-\u003evalue =\u003e 'Bonjour {{first_name}} {{last_name}}!',\n    ],\n    'Hello {{name}}, you have {{num}} [[new_comment:num]]' =\u003e [\n        Language::FR-\u003evalue =\u003e 'Bonjour {{name}}, vous avez {{num}} [[new_comment:num]]',\n    ],\n];\n```\n\nUsage:\n\n```php\nuse Composite\\Localization\\Language;\n\n$localization = new Localization(Language::FR);\n\n$localization-\u003egeneral('Hello World!'); //Bonjour le monde!\n\n$localization-\u003egeneral('hello_world'); //Bonjour le monde!\n\n$localization-\u003egeneral(\n    'Hello {{first_name}} {{last_name}}!', \n    ['first_name' =\u003e 'John', 'last_name' =\u003e 'Smith']\n); //Bonjour John Smith!\n\n$localization-\u003egeneral(\n    'hello_fullname', \n    ['first_name' =\u003e 'John', 'last_name' =\u003e 'Smith']\n); //Bonjour John Smith!\n\n//if translation not exists localization instance will still output it as is\n\n$localization-\u003egeneral('Bye World!'); //Bye World!\n\n$localization-\u003egeneral('bye_world'); //bye_world\n\n$localization-\u003egeneral(\n    'Bye {{first_name}} {{last_name}}!', \n    ['first_name' =\u003e 'John', 'last_name' =\u003e 'Smith']\n); //Bye John Smith!\n```\n\n## Pluralization\n\nCreate a file `_plural.php` inside folder with translation categories `/directory/to/your/locale/files`:\n\n```php\nuse Composite\\Localization\\Language;\nuse Composite\\Localization\\Plurals\\EnglishPlural;\nuse Composite\\Localization\\Plurals\\FrenchPlural;\n\nreturn [\n    'new_comment' =\u003e [\n        Language::EN-\u003evalue =\u003e new EnglishPlural('new comment', 'new comments'),\n        Language::FR-\u003evalue =\u003e new FrenchPlural('nouveau commentaire', 'nouveaux commentaires'),\n    ],\n];\n```\n\nUsage:\n\n```php\n$localization-\u003egeneral(\n    'Hello {{name}}, you have {{num}} [[new_comment:num]]', \n    ['name' =\u003e 'John', 'num' =\u003e 1]\n); //Bonjour John, vous avez 1 nouveau commentaire\n\n$localization-\u003egeneral(\n    'Hello {{name}}, you have {{num}} [[new_comment:num]]', \n    ['name' =\u003e 'John', 'num' =\u003e 2]\n); //Bonjour John, vous avez 2 nouveaux commentaires\n```\n\n## License:\n\nMIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by Composite PHP.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompositephp%2Flocalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompositephp%2Flocalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompositephp%2Flocalization/lists"}