translations
translations api for node.js, browsers and the command line.
Installation
npm install translations
Usage
var locale = require('locales/de-DE.json');
var locale = window.locale;
var t = translations(locale);
var t = translations(locale, true);
t('How are you?');
t('Hello {name}, how are you?', { name: 'Max' });
t('Hello {name}, how is {thing}?', { name: 'Max', thing: t('the weather') });
t('undefined key in locale');
t('Hello {name}, how is {thing}?', { name: 'Max' });
de-DE.json
{
"How are you?": "Wie geht es dir?",
"Hello {name}, how are you?": "Hallo {name}, wie geht es dir?",
"Hello {name}, how is {thing}?": "Hallo {name}, wie ist {thing}?",
"the weather": "das Wetter"
}
Command Line
Installation
npm install translations -g
sync
translations sync <master> <target>
translations sync locales/en.json locales/de-DE.json
translations sync
syncs the master
translations file with the target
one:
If target
has values that are not strings, it throws an error.
If target
does not exist yet, a copy of master
will be created with the target’s name (de-DE.json
).
If target
does already exist, the command does the following:
- every key not found in
master
is removed - every key not found in
target
is added
export
translations export <inputDirectory> <outputDirectory> --assign <variable>
translations export
will create or overwrite the given output directory with js files for valid locales in the input directory. Each js
file assigns the locale’s translations to the given variable (or window.locale
by default).
LICENSE
MIT (2015) Maximilian Hoffmann