{"id":15663701,"url":"https://github.com/jwebcoder/react-multi-lang","last_synced_at":"2025-05-05T22:50:44.422Z","repository":{"id":26842001,"uuid":"110487765","full_name":"JWebCoder/react-multi-lang","owner":"JWebCoder","description":"Multilanguage support for react applications","archived":false,"fork":false,"pushed_at":"2023-03-04T03:31:02.000Z","size":616,"stargazers_count":16,"open_issues_count":4,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-01T21:34:03.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/JWebCoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"JWebCoder","patreon":"jwebcoder","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-11-13T01:57:22.000Z","updated_at":"2025-01-04T02:30:40.000Z","dependencies_parsed_at":"2024-06-18T18:42:28.734Z","dependency_job_id":"794da2d4-eec6-43b5-9198-76ee349576ad","html_url":"https://github.com/JWebCoder/react-multi-lang","commit_stats":{"total_commits":57,"total_committers":5,"mean_commits":11.4,"dds":"0.45614035087719296","last_synced_commit":"a8790880f6cb29d94c1f2e9a5b27a24b1dcd90a3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Freact-multi-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Freact-multi-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Freact-multi-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Freact-multi-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JWebCoder","download_url":"https://codeload.github.com/JWebCoder/react-multi-lang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590528,"owners_count":21772935,"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":[],"created_at":"2024-10-03T13:39:27.492Z","updated_at":"2025-05-05T22:50:44.384Z","avatar_url":"https://github.com/JWebCoder.png","language":"TypeScript","funding_links":["https://github.com/sponsors/JWebCoder","https://patreon.com/jwebcoder"],"categories":[],"sub_categories":[],"readme":"# react-multi-lang\n\nReact Multi-language component.\n\nWorks with React and React Native\n\n## Installation\n\n`npm i -S react-multi-lang`\n\n## Usage\n\n### Hook\n\nSee the example folder for better understanding\n\n```tsx\nimport React from 'react'\n\n// Translation Hook\nimport { setTranslations, setDefaultLanguage, useTranslation } from 'react-multi-lang'\nimport pt from 'pt.json'\nimport en from 'en.json'\n\n// Do this two lines only when setting up the application\nsetTranslations({pt, en})\nsetDefaultLanguage('en')\n\nconst App: React.FC = () =\u003e {\n  const t = useTranslation()\n  return (\n    \u003cdiv\u003e\n      {t('home.Title')}\n      {t('Hello', {name: 'João'})}\n    \u003c/div\u003e\n  )\n}\n\nexport default App\n```\n\n### Higher order component\n\n```tsx\nimport React from 'react'\n\n// Translation Higher Order Component\nimport { setTranslations, setDefaultLanguage, withTranslation } from 'react-multi-lang'\nimport pt from 'pt.json'\nimport en from 'en.json'\nimport type { T } from 'react-multi-lang'\n\n// Do this two lines only when setting up the application\nsetTranslations({pt, en})\nsetDefaultLanguage('en')\n\ntype Props = {\n  t: T\n}\n\nclass SomeComponent extends React.Component\u003cProps\u003e {\n  render () {\n    const { t } = this.props\n    return (\n      \u003cdiv\u003e\n        {t('home.Title')}\n        {t('Hello', {name: 'João'})}\n      \u003c/div\u003e\n    )\n  }\n}\n\nexport default withTranslation(SomeComponent)\n```\n\n## Auto update functions\n\n### useTranslation(basePath)\n\nReact hook that returns the t function\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\nbasePath | string | translation base path used to identify all the next requested translations | no\n\n### withTranslation(component, basePath)\n\nHOC that injects the translation function into the component\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\ncomponent | React Component | React component that requires the translation function | yes\nbasePath | string | translation base path used to identify all the next requested translations | no\n\n## Translation Method\n\nt(path, params)\n\nReturns the translation for the requested path\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\npath | string | translation path that identifies the text | yes\nparams | object | {'param': 'value', ...} each parameter will be set on the string in its correct location | no\n\n## Exported Methods\n\n### setDefaultTranslations(translations)\n\nSets the translations\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\ntranslations | object | {'key': 'translations', ...} | yes\n\n### setTranslations(translations)\n\nSame as setDefaultTranslations, but this will update all components using translations\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\ntranslations | object | {'key': 'translations', ...} | yes\n\n### setDefaultLanguage(key)\n\nSets the default application language\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\nkey    | string | translation key, in this example 'en' or 'pt' | yes\n\n### setLanguage(key)\n\nSame as setDefaultLanguage, but this will update all components using translations\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\nkey    | string | translation key, in this example 'en' or 'pt' | yes\n\n### getLanguage()\n\nReturns the current selected language\n\n### t(key, params)\n\nt(path, params)\n\nReturns the translation for the requested path\n\nParams | Type | Description | Required\n---- | ---- | ---- | ----\npath | string | translation path that identifies the text | yes\nparams | object | {'param': 'value', ...} each parameter will be set on the string in its correct location | no\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Freact-multi-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwebcoder%2Freact-multi-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Freact-multi-lang/lists"}