{"id":21662556,"url":"https://github.com/php-gettext/translator","last_synced_at":"2025-04-09T18:18:28.352Z","repository":{"id":35614959,"uuid":"218164683","full_name":"php-gettext/Translator","owner":"php-gettext","description":"Gettext translator functions","archived":false,"fork":false,"pushed_at":"2025-01-09T09:21:16.000Z","size":35,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T18:18:23.985Z","etag":null,"topics":["gettext","i18n","internationalization","translator"],"latest_commit_sha":null,"homepage":null,"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/php-gettext.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"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},"funding":{"github":"oscarotero","patreon":"misteroom","custom":"https://paypal.me/oscarotero"}},"created_at":"2019-10-28T23:32:53.000Z","updated_at":"2025-01-09T09:20:28.000Z","dependencies_parsed_at":"2024-06-18T16:58:52.438Z","dependency_job_id":"8fb0b43b-b817-4420-8a19-1663a1a622d8","html_url":"https://github.com/php-gettext/Translator","commit_stats":{"total_commits":25,"total_committers":5,"mean_commits":5.0,"dds":0.48,"last_synced_commit":"a4fa5ed740f304a0ed7b3e169b2b554a195c7570"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FTranslator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FTranslator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FTranslator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FTranslator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-gettext","download_url":"https://codeload.github.com/php-gettext/Translator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085326,"owners_count":21045139,"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":["gettext","i18n","internationalization","translator"],"created_at":"2024-11-25T10:16:56.883Z","updated_at":"2025-04-09T18:18:28.327Z","avatar_url":"https://github.com/php-gettext.png","language":"PHP","funding_links":["https://github.com/sponsors/oscarotero","https://patreon.com/misteroom","https://paypal.me/oscarotero"],"categories":[],"sub_categories":[],"readme":"# Translator\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE)\n[![Total Downloads][ico-downloads]][link-downloads]\n\nCreated by Oscar Otero \u003chttp://oscarotero.com\u003e \u003coom@oscarotero.com\u003e (MIT License)\n\nTranslator functions to use with [gettext/gettext](https://github.com/php-gettext/Gettext). Useful if you don't have the native gettext extension for php or want to avoid problems with it.\n\n## Installation\n\n```\ncomposer require gettext/translator\n```\n\n## Translator\n\n```php\nuse Gettext\\Translator;\n\n//Create a new instance of the translator\n$t = new Translator();\n\n//Load the translations from php files (generated by Gettext\\Extractors\\PhpArray)\n$t-\u003eloadTranslations(\n    'locales/gl/domain1.php',\n    'locales/gl/domain2.php',\n    'locales/gl/domain3.php',\n);\n\n//Now you can use it in your templates\necho $t-\u003egettext('apple');\n```\n\n## GettextTranslator\n\nThe class `Gettext\\GettextTranslator` uses the gettext extension. It's useful because combines the performance of using real gettext functions but with the same API than `Translator` class, so you can switch to one or other translator without change code of your app.\n\n```php\nuse Gettext\\GettextTranslator;\n\n//Create a new instance\n$t = new GettextTranslator();\n\n//It detects the environment variables to set the locale, but you can change it:\n$t-\u003esetLanguage('gl');\n\n//Load the domains:\n$t-\u003eloadDomain('messages', 'project/Locale');\n//this means you have the file \"project/Locale/gl/LC_MESSAGES/messages.mo\"\n\n//Now you can use it in your templates\necho $t-\u003egettext('apple');\n```\n\n## Translator functions\n\nTo ease the use of translations in your php templates, you can use the provided functions:\n\n```php\nuse Gettext\\TranslatorFunctions;\n\n//Register the translator to use the global functions\nTranslatorFunctions::register($t);\n\necho __('apple'); // it's the same than $t-\u003egettext('apple');\n```\n\nYou can scan the php files containing these functions and extract the values with the PhpCode extractor:\n\n```html\n\u003c!-- index.php --\u003e\n\u003chtml\u003e\n    \u003cbody\u003e\n        \u003c?= __('Hello world'); ?\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n---\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/gettext/translator.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/gettext/translator.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/gettext/translator\n[link-downloads]: https://packagist.org/packages/gettext/translator\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-gettext%2Ftranslator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-gettext%2Ftranslator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-gettext%2Ftranslator/lists"}