Skip to content

Instantly share code, notes, and snippets.

@Tom32i
Last active August 17, 2017 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tom32i/065afb04060579d70552b70c0b04285a to your computer and use it in GitHub Desktop.
Save Tom32i/065afb04060579d70552b70c0b04285a to your computer and use it in GitHub Desktop.
I18n JS

Installation

npm install i18n-js

Usage

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 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment