{"id":19004835,"url":"https://github.com/dhis2/d2-i18n","last_synced_at":"2025-04-22T18:33:51.491Z","repository":{"id":29923334,"uuid":"123128950","full_name":"dhis2/d2-i18n","owner":"dhis2","description":"I18n for DHIS 2","archived":false,"fork":false,"pushed_at":"2023-11-20T14:15:20.000Z","size":719,"stargazers_count":2,"open_issues_count":9,"forks_count":1,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-17T10:24:24.637Z","etag":null,"topics":["synced-settings","web-lib"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhis2.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":"2018-02-27T12:54:34.000Z","updated_at":"2023-04-17T08:44:19.000Z","dependencies_parsed_at":"2024-06-19T00:28:08.406Z","dependency_job_id":"ebb3180d-9244-438a-a73e-449f8f3b0fa7","html_url":"https://github.com/dhis2/d2-i18n","commit_stats":{"total_commits":82,"total_committers":11,"mean_commits":7.454545454545454,"dds":"0.35365853658536583","last_synced_commit":"e62eb18731bbb49eb9300467cab568e7bc1111bb"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fd2-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fd2-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fd2-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fd2-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhis2","download_url":"https://codeload.github.com/dhis2/d2-i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250297255,"owners_count":21407178,"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":["synced-settings","web-lib"],"created_at":"2024-11-08T18:24:41.478Z","updated_at":"2025-04-22T18:33:51.449Z","avatar_url":"https://github.com/dhis2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Purpose\n\nProvides internationization support for d2 frontend Apps.\n\n-   i18n\n-   Date/Time\n-   Calendar\n-   Monitoring translations [documentation](https://github.com/dhis2/d2-i18n-monitor), [website](https://dhis2.github.io/d2-i18n-monitor/#/)\n\n## Installation\n\n```bash\nyarn add @dhis2/d2-i18n\n```\n\n## Extracting and generating locale strings\n\nExtraction and generation are performed automatically by the `build` and `start` commands of [@dhis2/cli-app-scripts](https://platform.dhis2.nu). Optionally, they can be run independent of the build as well:\n\n```sh\nyarn d2-app-scripts i18n extract\nyarn d2-app-scripts i18n generate\n```\n\n## In App Code\n\nOn dev/build phase _src/locales_ directory would be created. It will contain necessary setup for internationalization, date/time, calendar etc. It is auto-generated, so please don't update it, any changes to it will be lost.\n\nAt the top of _src/index.js_ (assuming it's the main entry point to your App). Add the following,\n\n```js\nimport './locales'\n```\n\n### Changing User Locale\n\nCreate a function _changeLocale_ and _isLangRTL_ as below. You should call this function in App loading phase.\n\n```js\nfunction isLangRTL(code) {\n    const langs = ['ar', 'fa', 'ur']\n    const prefixed = langs.map(c =\u003e `${c}-`)\n    return (\n        langs.includes(code) ||\n        prefixed.filter(c =\u003e code.startsWith(c)).length \u003e 0\n    )\n}\n\nfunction changeLocale(locale) {\n    moment.locale(locale)\n    i18n.changeLanguage(locale)\n    document.documentElement.setAttribute(\n        'dir',\n        isLangRTL(locale) ? 'rtl' : 'ltr'\n    )\n}\n```\n\n### Translations\n\nPass strings to be translated into _i18n.t_ function as below.\n\n```js\nimport i18n from '@dhis2/d2-i18n'\ni18n.t('translation string')\n```\n\n#### Context\n\nPass _context_ property on second arg. to i18n.t\n\n```js\ni18n.t('hello world', {\n    context: 'a customary string to welcome a new born developer',\n})\n```\n\n_extract-pot_ will automatically generate _msgctxt_ field before _msgid_ in the en.pot file, giving translators a better context for translations.\n\n```\nmsgctxt \"a customary string to welcome a new born developer\"\nmsgid \"hello world\"\nmsgstr \"\"\n```\n\n## .gitignore\n\nAppend directory _src/locales_ at the end. Because on dev/build phase _src/locales_ is auto-generated.\n\n## Upgrade\n\n**yarn**\n\n```bash\nyarn upgrade --scope @dhis2\n```\n\n## .travis.yml\n\nIn _.travis.yml_ before build/deploy step add `yarn localize`\n\n## Notes\n\n-   We don't use _react-i18next_ because handling cursor in text editor when ASCII and RTL characters are mixed is impossible to edit. Some ASCII characters move the cursor to one end of the line while RTL characters take cursor to the opposite end. Using variables in RTL language strings do not work because the first _{{_ might be entered correctly when translating but when we go to type the ending sequence _}}_ the cursor ends up in the wrong place making it impossible to translate.\n\n## Report an issue\n\nThe issue tracker can be found in [DHIS2 JIRA](https://jira.dhis2.org)\nunder the [LIBS](https://jira.dhis2.org/projects/LIBS) project.\n\nDeep links:\n\n-   [Bug](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10006\u0026components=11013)\n-   [Feature](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10300\u0026components=11013)\n-   [Task](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10003\u0026components=11013)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhis2%2Fd2-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhis2%2Fd2-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhis2%2Fd2-i18n/lists"}