{"_id":"@cosier/ra-i18n-polyglot","_rev":"3-1ccd3350c689ef751e32cb3e593b5530","name":"@cosier/ra-i18n-polyglot","dist-tags":{"latest":"1.0.8"},"versions":{"1.0.0":{"name":"@cosier/ra-i18n-polyglot","version":"1.0.0","license":"MIT","_id":"@cosier/ra-i18n-polyglot@1.0.0","maintainers":[{"name":"cosier","email":"bailey@cosier.ca"}],"homepage":"https://github.com/marmelab/react-admin#readme","bugs":{"url":"https://github.com/marmelab/react-admin/issues"},"dist":{"shasum":"a8f8bec7df083c2aed8197fb7658c33b9b5d3245","tarball":"https://registry.npmjs.org/@cosier/ra-i18n-polyglot/-/ra-i18n-polyglot-1.0.0.tgz","fileCount":5,"integrity":"sha512-TCPrt1aEg12kf8av25USke1Sm+gSUHcMPWlQKwesdhu4AVoZpE7LzswWWKZ80hby//c/bJ3tsvk/QtJ4WK2LLA==","signatures":[{"sig":"MEQCIG8jXDMW+tIX0WzS+KbZFoMxN9nTwFX/q7qElZlhFhdGAiAiPIdD8lFtkvuoFHHClLl3Al7m9VzY+Whgg5b1TLCaEw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12361},"main":"dist/cjs/index.js","types":"dist/cjs/index.d.ts","module":"dist/esm/index.js","authors":["François Zaninotto"],"gitHead":"587df4c27bfcec4a756df4f95e5fc14728dfc0d7","scripts":{"build":"yarn run build-cjs && yarn run build-esm","watch":"tsc --outDir dist/esm --module es2015 --watch","build-cjs":"rimraf ./dist/cjs && tsc --outDir dist/cjs","build-esm":"rimraf ./dist/esm && tsc --outDir dist/esm --module es2015"},"_npmUser":{"name":"cosier","email":"bailey@cosier.ca"},"repository":{"url":"git+https://github.com/marmelab/react-admin.git","type":"git"},"_npmVersion":"11.5.1","description":"Polyglot i18n provider for react-admin","directories":{},"sideEffects":false,"_nodeVersion":"24.6.0","dependencies":{"node-polyglot":"^2.2.2","@cosier/ra-core":"^1.0.10.0"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^3.0.2","cross-env":"^5.2.0","typescript":"^5.1.3"},"_npmOperationalInternal":{"tmp":"tmp/ra-i18n-polyglot_1.0.0_1756488596774_0.6344387642966636","host":"s3://npm-registry-packages-npm-production"}},"1.0.7":{"name":"@cosier/ra-i18n-polyglot","version":"1.0.7","license":"MIT","_id":"@cosier/ra-i18n-polyglot@1.0.7","maintainers":[{"name":"cosier","email":"bailey@cosier.ca"}],"homepage":"https://github.com/marmelab/react-admin#readme","bugs":{"url":"https://github.com/marmelab/react-admin/issues"},"dist":{"shasum":"7f16ddfd67f133c14f6fd07c12293383ae831256","tarball":"https://registry.npmjs.org/@cosier/ra-i18n-polyglot/-/ra-i18n-polyglot-1.0.7.tgz","fileCount":9,"integrity":"sha512-4cghnraqbRLJ3FI0EurMhUQk6eT2Rspx5ra1F4AcpwNbv2hX9Nxxx5x75f8mQCTkuO4VbbCnacnZLcR9hYAh9w==","signatures":[{"sig":"MEUCIQCd3DMdyclYmLOk9E/4RTaGrHQZaFeWdeuX0PjzRmHOMQIgHk1Dq20kZ492UmkuV8RtGdBNchDEjf9YyM7kTgyUiPA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18742},"main":"dist/cjs/index.js","types":"dist/cjs/index.d.ts","module":"dist/esm/index.js","authors":["François Zaninotto"],"gitHead":"587df4c27bfcec4a756df4f95e5fc14728dfc0d7","scripts":{"build":"pnpm run build-cjs && pnpm run build-esm","watch":"tsc --outDir dist/esm --module es2015 --watch","build-cjs":"rimraf ./dist/cjs && tsc --outDir dist/cjs","build-esm":"rimraf ./dist/esm && tsc --outDir dist/esm --module es2015"},"_npmUser":{"name":"cosier","email":"bailey@cosier.ca"},"repository":{"url":"git+https://github.com/marmelab/react-admin.git","type":"git"},"_npmVersion":"11.5.1","description":"Polyglot i18n provider for react-admin","directories":{},"sideEffects":false,"_nodeVersion":"24.6.0","dependencies":{"node-polyglot":"^2.2.2","@cosier/ra-core":"^1.0.10.0"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^3.0.2","cross-env":"^5.2.0","typescript":"^5.1.3"},"_npmOperationalInternal":{"tmp":"tmp/ra-i18n-polyglot_1.0.7_1756490337831_0.8135798023327345","host":"s3://npm-registry-packages-npm-production"}},"1.0.8":{"name":"@cosier/ra-i18n-polyglot","version":"1.0.8","description":"Polyglot i18n provider for react-admin","main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"dist/cjs/index.d.ts","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js","types":"./dist/cjs/index.d.ts"}},"sideEffects":false,"authors":["François Zaninotto"],"repository":{"type":"git","url":"git+https://github.com/marmelab/react-admin.git"},"homepage":"https://github.com/marmelab/react-admin#readme","bugs":{"url":"https://github.com/marmelab/react-admin/issues"},"license":"MIT","scripts":{"build":"pnpm run build-cjs && pnpm run build-esm","build-cjs":"rimraf ./dist/cjs && tsc --outDir dist/cjs","build-esm":"rimraf ./dist/esm && tsc --outDir dist/esm --module es2015","watch":"tsc --outDir dist/esm --module es2015 --watch"},"dependencies":{"node-polyglot":"^2.2.2","@cosier/ra-core":"^1.0.7"},"devDependencies":{"cross-env":"^5.2.0","rimraf":"^3.0.2","typescript":"^5.1.3"},"gitHead":"587df4c27bfcec4a756df4f95e5fc14728dfc0d7","_id":"@cosier/ra-i18n-polyglot@1.0.8","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-bAYOR/KnanIM0l4iJ+sBKOoWaHRmqHmuO+IF4wrJ9VHVTZjs65I5N7ePh1JJHOejiBR/k+WWPZpShbGP696CZw==","shasum":"9661c365eb2b23f25d06d9a0240b31a2468d24ba","tarball":"https://registry.npmjs.org/@cosier/ra-i18n-polyglot/-/ra-i18n-polyglot-1.0.8.tgz","fileCount":13,"unpackedSize":25068,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAZVAw5QD2IKgDtIgjx2ag3PfzSLguv2WsAYoX34B12yAiEAmUwg4BYSaqkyubybYVI8LGbLTW7qFQI48Jmode0+8GQ="}]},"_npmUser":{"name":"cosier","email":"bailey@cosier.ca"},"directories":{},"maintainers":[{"name":"cosier","email":"bailey@cosier.ca"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ra-i18n-polyglot_1.0.8_1756492612317_0.4816928398911613"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-29T17:29:56.657Z","modified":"2025-08-29T18:36:52.693Z","1.0.0":"2025-08-29T17:29:56.954Z","1.0.7":"2025-08-29T17:58:57.990Z","1.0.8":"2025-08-29T18:36:52.503Z"},"bugs":{"url":"https://github.com/marmelab/react-admin/issues"},"license":"MIT","homepage":"https://github.com/marmelab/react-admin#readme","repository":{"type":"git","url":"git+https://github.com/marmelab/react-admin.git"},"description":"Polyglot i18n provider for react-admin","maintainers":[{"name":"cosier","email":"bailey@cosier.ca"}],"readme":"# Polyglot i18n provider for react-admin\n\nPolyglot i18n provider for [react-admin](https://github.com/marmelab/react-admin), the frontend framework for building admin applications on top of REST/GraphQL services. It relies on [polyglot.js](https://airbnb.io/polyglot.js/), which uses JSON files for translations.\n\n[![react-admin-demo](https://marmelab.com/react-admin/img/react-admin-demo-still.png)](https://www.youtube.com/watch?v=bJEo1O1oT6o)\n\n## Installation\n\n```sh\nnpm install --save ra-i18n-polyglot\n```\n\n## Usage\n\nWrap the function exported by this package around a function returning translation messages based on a locale to produce a valid `i18nProvider`.\n\n```jsx\nimport * as React from \"react\";\nimport { Admin, Resource } from 'react-admin';\nimport polyglotI18nProvider from 'ra-i18n-polyglot';\nimport englishMessages from 'ra-language-english';\nimport frenchMessages from 'ra-language-french';\n\nconst messages = {\n    fr: frenchMessages,\n    en: englishMessages,\n};\n\nconst i18nProvider = polyglotI18nProvider(\n    locale => messages[locale],\n    'en',\n    [\n        { locale: 'en', name: 'English' },\n        { locale: 'fr', name: 'Français' },\n    ]\n);\n\nconst App = () => (\n    <Admin i18nProvider={i18nProvider}>\n        ...\n    </Admin>\n);\n\nexport default App;\n```\n\n## Translation Messages\n\nThe `message` returned by the function argument should be a dictionary where the keys identify interface components, and values are the translated string. This dictionary is a simple JavaScript object looking like the following:\n\n```js\n{\n    ra: {\n        action: {\n            delete: 'Delete',\n            show: 'Show',\n            list: 'List',\n            save: 'Save',\n            create: 'Create',\n            edit: 'Edit',\n            cancel: 'Cancel',\n        },\n        ...\n    },\n}\n```\n\nAll core translations are in the `ra` namespace, in order to prevent collisions with your own custom translations. The root key used at runtime is determined by the value of the `locale` prop.\n\nThe default messages are available [here](https://github.com/marmelab/react-admin/blob/master/packages/ra-language-english/src/index.ts).\n\n## Asynchronous Locale Change\n\nThe function passed as parameter of `polyglotI18nProvider` can return a *Promise* for messages instead of a messages object. This lets you lazy load messages upon language change.\n\nNote that the messages for the default locale (used by react-admin for the initial render) must be returned in a synchronous way. \n\n```jsx\nimport polyglotI18nProvider from 'ra-i18n-polyglot';\nimport englishMessages from 'ra-language-english';\n\nconst asyncMessages = {\n    fr: () => import('ra-language-french').then(messages => messages.default),\n    it: () => import('ra-language-italian').then(messages => messages.default),\n};\n\nconst messagesResolver = locale => {\n    if (locale === 'en') {\n        // initial call, must return synchronously\n        return englishMessages;\n    }\n    // change of locale after initial call returns a promise\n    return asyncMessages[params.locale]();\n}\n\n const i18nProvider = polyglotI18nProvider(messageResolver, \"en\", [\n    { locale: 'en', name: 'English' },\n    { locale: 'fr', name: 'Français' },\n    { locale: 'it', name: 'Italiano' },\n]);\n```\n\n## Using Specific Polyglot Features\n\nPolyglot.js is a fantastic library: in addition to being small, fully maintained, and totally framework agnostic, it provides some nice features such as interpolation and pluralization, that you can use in react-admin.\n\n```js\nconst messages = {\n    'hello_name': 'Hello, %{name}',\n    'count_beer': 'One beer |||| %{smart_count} beers',\n};\n\n// interpolation\ntranslate('hello_name', { name: 'John Doe' });\n=> 'Hello, John Doe.'\n\n// pluralization\ntranslate('count_beer', { smart_count: 1 });\n=> 'One beer'\n\ntranslate('count_beer', { smart_count: 2 });\n=> '2 beers'\n\n// default value\ntranslate('not_yet_translated', { _: 'Default translation' });\n=> 'Default translation'\n```\n\nTo find more detailed examples, please refer to [http://airbnb.io/polyglot.js/](https://airbnb.io/polyglot.js/)\n","readmeFilename":"README.md"}