{"id":21662548,"url":"https://github.com/php-gettext/js-translator","last_synced_at":"2025-12-12T04:23:42.672Z","repository":{"id":58221464,"uuid":"60961102","full_name":"php-gettext/JS-Translator","owner":"php-gettext","description":"Javascript gettext translator","archived":false,"fork":false,"pushed_at":"2024-06-19T08:07:34.000Z","size":26,"stargazers_count":22,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T08:46:25.434Z","etag":null,"topics":["gettext","json","translator"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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":null,"funding":null,"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}},"created_at":"2016-06-12T10:21:57.000Z","updated_at":"2024-06-19T08:07:38.000Z","dependencies_parsed_at":"2024-11-25T10:16:58.323Z","dependency_job_id":"3de32383-da4b-4415-8832-5f91c7edd2fe","html_url":"https://github.com/php-gettext/JS-Translator","commit_stats":null,"previous_names":["oscarotero/gettext-translator"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FJS-Translator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FJS-Translator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FJS-Translator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-gettext%2FJS-Translator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-gettext","download_url":"https://codeload.github.com/php-gettext/JS-Translator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497903,"owners_count":21113982,"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","json","translator"],"created_at":"2024-11-25T10:16:54.831Z","updated_at":"2025-12-12T04:23:42.595Z","avatar_url":"https://github.com/php-gettext.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gettext translator\n\nJavascript gettext translations replacement to use with [gettext/gettext](https://github.com/php-gettext/Gettext). Use [gettext/json](https://github.com/php-gettext/Json) to generate the json data.\n\n## Installation\n\n```\nnpm install gettext-translator\n```\n\n## Usage\n\nUse the Json generator [gettext/json](https://github.com/php-gettext/Json) library to export the translations to json:\n\n```php\nuse Gettext\\Loader\\PoLoader;\nuse Gettext\\Generator\\JsonGenerator;\n\n//Load the po file with the translations\n$translations = (new PoLoader())-\u003eloadFile('locales/gl.po');\n\n//Export to a json file\n(new JsonGenerator())-\u003egenerateFile($translations, 'locales/gl.json');\n```\n\nLoad the json file in your browser\n\n```js\nimport Translator from 'gettext-translator';\n\nasync function getTranslator() {\n    const response = await fetch('locales/gl.json');\n    const translations = await response.json();\n\n    return new Translator(translations);\n}\n\nconst t = await getTranslator();\n\nt.gettext('hello world'); //ola mundo\n```\n\n## Variables\n\nYou can add variables to the translations. For example:\n\n```js\nt.gettext('hello :who', {':who': 'world'}); //ola world\n```\n\nThere's also a basic support o sprintf (only `%s` and `%d`)\n\n```js\nt.gettext('hello %s', 'world'); //ola world\n```\n\nTo customize the translator formatter, just override the `format` method:\n\n```js\nt.format = function (text, ...args) {\n    //Your custom format here\n}\n```\n\n## Short names\n\nLike in the [php version](https://github.com/php-gettext/Translator), there are the `__` functions that are alias of the long version:\n\n```js\n//Both functions does the same\n\nt.gettext('Foo');\nt.__('Foo');\n```\n\n## API\n\nLong name  | Short name | Description\n-----------| -----------| -----------\ngettext    | __         | Returns a translation\nngettext   | n__        | Returns a translation with singular/plural variations\ndngettext  | dn__       | Returns a translation with domain and singular/plural variations\nnpgettext  | np__       | Returns a translation with context and singular/plural variations\npgettext   | p__        | Returns a translation with a specific context\ndgettext   | d__        | Returns a translation with a specific domain\ndpgettext  | dp__       | Returns a translation with a specific domain and context\ndnpgettext | dnp__      | Returns a translation with a specific domain, context and singular/plural variations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-gettext%2Fjs-translator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-gettext%2Fjs-translator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-gettext%2Fjs-translator/lists"}