npm install i18n-js
Import just translations.js once in your main file, then use I18n everywhere.
| { | |
| "foo": { | |
| "bar": "Foo bar", | |
| "baz": { | |
| "foo": "Foo baz-foo.", | |
| "bar": "Foo baz-bar.", | |
| } | |
| } | |
| } |
| import I18n from 'i18n-js'; | |
| const label = I18n.t('foo.baz.bar'); | |
| // Foo baz-bar. |
| import I18n from 'i18n-js'; | |
| import fr from './fr.json'; | |
| I18n.fallbacks = true; | |
| I18n.defaultLocale = 'fr'; | |
| I18n.translations = { fr }; |