{"id":19125203,"url":"https://github.com/crimx/val-i18n-react","last_synced_at":"2026-05-18T14:36:11.044Z","repository":{"id":65407781,"uuid":"590278198","full_name":"crimx/val-i18n-react","owner":"crimx","description":"React goodies for val-i18n","archived":false,"fork":false,"pushed_at":"2024-02-22T08:56:18.000Z","size":499,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-14T07:06:10.386Z","etag":null,"topics":["gettext","globalization","hook","i18n","internationalization","l10n","localization","react","react-hooks","reactjs","translation"],"latest_commit_sha":null,"homepage":"https://crimx.github.io/val-i18n-react/","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/crimx.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":"2023-01-18T03:08:14.000Z","updated_at":"2023-07-22T14:17:50.000Z","dependencies_parsed_at":"2024-02-22T09:53:55.524Z","dependency_job_id":null,"html_url":"https://github.com/crimx/val-i18n-react","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"0294335664b3b8eea3f75a78110e590f38f2b973"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crimx%2Fval-i18n-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crimx%2Fval-i18n-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crimx%2Fval-i18n-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crimx%2Fval-i18n-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crimx","download_url":"https://codeload.github.com/crimx/val-i18n-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240190909,"owners_count":19762590,"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","globalization","hook","i18n","internationalization","l10n","localization","react","react-hooks","reactjs","translation"],"created_at":"2024-11-09T05:35:00.401Z","updated_at":"2026-05-18T14:36:11.039Z","avatar_url":"https://github.com/crimx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [val-i18n-react](https://github.com/crimx/val-i18n-react)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"https://raw.githubusercontent.com/crimx/val-i18n/main/assets/val-i18n.svg\"\u003e\n\u003c/p\u003e\n\n[![Build Status](https://github.com/crimx/val-i18n-react/actions/workflows/build.yml/badge.svg)](https://github.com/crimx/val-i18n-react/actions/workflows/build.yml)\n[![npm-version](https://img.shields.io/npm/v/val-i18n-react.svg)](https://www.npmjs.com/package/val-i18n-react)\n[![Coverage Status](https://img.shields.io/coveralls/github/crimx/val-i18n-react/master)](https://coveralls.io/github/crimx/val-i18n-react?branch=master)\n[![minified-size](https://img.shields.io/bundlephobia/minzip/val-i18n-react)](https://bundlephobia.com/package/val-i18n-react)\n\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?maxAge=2592000)](http://commitizen.github.io/cz-cli/)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-brightgreen.svg?maxAge=2592000)](https://conventionalcommits.org)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nReact goodies for [val-i18n](https://github.com/crimx/val-i18n).\n\n## Install\n\n```bash\nnpm add val-i18n-react val-i18n value-enhancer\n```\n\n## API\n\n- `I18nProvider` to provide `i18n` context for descendant components.\n- `useTranslate` hook to subscribe and get the latest `i18n.t`.\n- `useLang` hook to subscribe and get the latest `i18n.lang`.\n- `useI18n` hook to subscribe and get the latest `i18n` instance.\n- `\u003cTrans\u003e` component to insert React elements into translation template messages.\n\n## Usage\n\nSee live example on [CodeSandbox](https://codesandbox.io/s/val-i18n-react-o887n0).\n\n```jsx\nimport { I18n } from \"val-i18n\";\nimport { I18nProvider, useTranslate } from \"val-i18n-react\";\n\nconst i18n = new I18n(\"en\", { en: { fruit: \"apple\" } });\n\nconst MyComponent = () =\u003e {\n  const t = useTranslate();\n  return \u003cdiv\u003e{t(\"fruit\")}\u003c/div\u003e;\n};\n\nconst App = () =\u003e {\n  return (\n    \u003cI18nProvider i18n={i18n}\u003e\n      \u003cMyComponent /\u003e\n    \u003c/I18nProvider\u003e\n  );\n};\n```\n\n### Cascading I18nProvider\n\nYou can nest multiple `\u003cI18nProvider\u003e`s to create cascading i18n contexts.\n\n```tsx\nimport { I18n } from \"val-i18n\";\nimport { I18nProvider, useTranslate } from \"val-i18n-react\";\n\nconst baseI18n = new I18n(\"en\", { en: { confirm: \"Confirm\" } });\nconst loginI18n = new I18n(\"en\", { en: { login: \"Login\" } });\n\nconst MyComponent = () =\u003e {\n  const t = useTranslate();\n  return (\n    \u003cdiv\u003e\n      \u003cbutton\u003e{t(\"confirm\")}\u003c/button\u003e\n      \u003cbutton\u003e{t(\"login\")}\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n\nconst App = () =\u003e {\n  return (\n    \u003cI18nProvider i18n={baseI18n}\u003e\n      \u003cI18nProvider i18n={loginI18n}\u003e\n        \u003cMyComponent /\u003e\n      \u003c/I18nProvider\u003e\n    \u003c/I18nProvider\u003e\n  );\n};\n```\n\n### Trans Component\n\nTo insert React elements into the translation message:\n\n```jsx\nimport { Trans, useTranslate } from \"val-i18n-react\";\nimport { I18n, I18nProvider } from \"val-i18n\";\n\nconst locales = {\n  en: {\n    author: \"CRIMX\",\n    fruit: \"apple\",\n    eat: \"{{name}} eats {{fruit}}.\",\n  },\n};\n\nconst i18n = new I18n(\"en\", locales);\n\nconst MyComponent = () =\u003e {\n  const t = useTranslate();\n\n  return (\n    \u003cTrans message={t(\"eat\")}\u003e\n      \u003cstrong data-t-slot=\"name\"\u003e{t(\"author\")}\u003c/strong\u003e\n      \u003ci style={{ color: \"red\" }} data-t-slot=\"fruit\"\u003e\n        {t(\"fruit\")}\n      \u003c/i\u003e\n    \u003c/Trans\u003e\n  );\n};\n\nconst App = () =\u003e {\n  return (\n    \u003cI18nProvider i18n={i18n}\u003e\n      \u003cMyComponent /\u003e\n    \u003c/I18nProvider\u003e\n  );\n};\n```\n\n↓Outputs:\n\n```jsx\n\u003c\u003e\n  \u003cstrong data-t-slot=\"name\"\u003eCRIMX\u003c/strong\u003e eats \u003ci style={{ color: \"red\" }} data-t-slot=\"fruit\"\u003eapple\u003c/i\u003e.\n\u003c\u003e\n```\n\n`data-t-slot` can be ignored if there is only one placeholder.\n\n```jsx\n\u003cTrans message=\"a{{b}}c\"\u003e\n  \u003ch1\u003eB\u003c/h1\u003e\n\u003c/Trans\u003e\n```\n\n↓Outputs:\n\n```jsx\n\u003c\u003e\n  a\u003ch1\u003eB\u003c/h1\u003ec\n\u003c/\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrimx%2Fval-i18n-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrimx%2Fval-i18n-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrimx%2Fval-i18n-react/lists"}