{"id":20540581,"url":"https://github.com/utopia-php/locale","last_synced_at":"2025-10-23T19:08:17.077Z","repository":{"id":46665048,"uuid":"183949799","full_name":"utopia-php/locale","owner":"utopia-php","description":"Lite \u0026 fast micro PHP locale library that is **easy to use**.","archived":false,"fork":false,"pushed_at":"2025-08-12T12:59:24.000Z","size":80,"stargazers_count":25,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-06T23:02:51.315Z","etag":null,"topics":["hacktoberfest","locale","php","utopia","utopia-framework"],"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/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-04-28T19:27:03.000Z","updated_at":"2025-08-21T08:03:45.000Z","dependencies_parsed_at":"2025-10-06T23:01:40.136Z","dependency_job_id":null,"html_url":"https://github.com/utopia-php/locale","commit_stats":{"total_commits":54,"total_committers":10,"mean_commits":5.4,"dds":0.6111111111111112,"last_synced_commit":"8c4e8b34c8203d3421556e865070dfedb9e99c92"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/locale","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Flocale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Flocale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Flocale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Flocale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/locale/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Flocale/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278692948,"owners_count":26029408,"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-10-06T02:00:05.630Z","response_time":65,"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":["hacktoberfest","locale","php","utopia","utopia-framework"],"created_at":"2024-11-16T01:16:24.344Z","updated_at":"2025-10-06T23:04:13.821Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utopia Locale\n\n[![Build Status](https://travis-ci.org/utopia-php/locale.svg?branch=master)](https://travis-ci.com/utopia-php/locale)\n![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/locale.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord)\n\nUtopia framework locale library is simple and lite library for managing application translations and localization. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).\n\nAlthough this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free and can be used as standalone with any other PHP project or framework.\n\n## Getting Started\n\nInstall using composer:\n\n```bash\ncomposer require utopia-php/locale\n```\n\nInit in your application:\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../../vendor/autoload.php';\n\nuse Utopia\\Locale\\Locale;\n\n// Init translations\nLocale::setLanguageFromArray('en-US', [\n    'hello' =\u003e 'Hello',\n    'world' =\u003e 'World',\n    'likes' =\u003e 'You have {{likesAmount}} likes and {{commentsAmount}} comments.'\n]); // Set English\nLocale::setLanguageFromArray('he-IL', ['hello' =\u003e 'שלום',]); // Set Hebrew\nLocale::setLanguageFromJSON('hi-IN', 'path/to/translations.json'); // Set Hindi\n\n// Create locale instance\n$locale = new Locale('en-US'); // en-US will be set as default language\n\n// Get translation\necho $locale-\u003egetText('hello'); // prints \"Hello\"\necho $locale-\u003egetText('world'); // prints \"World\"\n\n// Use placeholders\necho $locale-\u003egetText('likes', [ 'likesAmount' =\u003e 12, 'commentsAmount' =\u003e 55 ]); // prints \"You have 12 likes and 55 comments.\"\necho $locale-\u003egetText('likes'); // prints \"You have {{likesAmount}} likes and {{commentsAmount}} comments.\". If you don't provide placeholder value, the string is returned unchanged.\n\n// Get translation of different language\n$locale-\u003esetDefault('he-IL');\necho $locale-\u003egetText('hello'); // prints \"שלום\"\n```\n\n## Expected Structure of Translations\n\nEach translation is a **key-value** pair. The **key** is an identifier that represents a string in your app. The value is the translation in the specified locale.\n\nWhen using `setLanguageFromArray($code, $translations)` for the `en-US` locale, you need to specify the translation array in the following format:\n\n### Translations Array\n\n```php\n\u003c?php\n    $translations = [\n        'app.landing.title' =\u003e 'Welcome to My App.',\n        'app.landing.cta' =\u003e 'Click Here!',\n    ]\n```\n\nWhen using `setLanguageFromJSON($code, $path)` for the `en-US` locale you need to specify a path to the translation JSON file which should be in the following format:\n\n### JSON File\n\n```json\n{\n \"app.landing.title\": \"Welcome to My App.\",\n \"app.landing.cta\": \"Click Here!\"\n}\n```\n\n## System Requirements\n\nUtopia Framework requires PHP 7.4 or later. We recommend using the latest PHP version whenever possible.\n\n## Tests\n\nTo run the tests, first you need to install libraries:\n\n```shell\ndocker run --rm --interactive --tty \\\n  --volume $PWD:/app \\\n  composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist\n```\n\nFinally, you can run the tests:\n\n```shell\ndocker run --rm -v $(pwd):$(pwd):rw -w $(pwd) php:7.4-cli-alpine sh -c \"vendor/bin/phpunit tests/Locale/LocaleTest.php\"\n```\n\n## Copyright and license\n\nThe MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Flocale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Flocale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Flocale/lists"}