translations
translations api for node.js, browsers and the command line.
Installation
npm install translations
Usage
var locale = ; // node.js;var locale = windowlocale; // browser example var t = ; // production mode: ignores most errorsvar t = ; // development mode: throws more errors ;// "Wie geht es dir?" ;// "Hallo Max, wie geht es dir?" ;// "Hallo Max, wie ist das Wetter?" ;// throws error in development mode for undefined keys// returns empty string in production mode ;// throws error in development mode for undefined variables// prints placeholders in production mode
de-DE.json
Command Line
Installation
npm install translations -g # if you want to use the cli globally
sync
# sync locales translations sync <master> <target> # example 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
# export locales for browser usage 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