translation-dictionary
JavaScript gettext-style translation output library with sprintf-js parameter replace.
Install
Node.js
$ npm install translation-dictionary
Browser
$ bower install translation-dictionary
<!-- with EventEmitter ~9 kb --> <!-- or without EventEmitter ~6.4 kb -->
Usage
var dict = ; dict;dict; dict; // 'Ich habe ein Auto'dict; // 'Ich habe 2 Autos'dict; // 'Hallo John Doe'dict; // 'Name: Doe, Vorname: John'dict; // 'Named arguments inserted'
View example/ for detailed examples.
API
getLocale ()
Return the current locale (default: 'en').
registerPluralizer (locale, pluralizer[, nPlurals=2])
Set a pluralizer for a locale with the number of plurals.
;
registerTranslation (locale, translations)
Merge translations to a locale.
// nPlurals=2 in german; // nPlurals=3 in czechdict;
setBaseLocale (locale[, nPlurals=2])
Set the applications base language.
setLocale (locale)
Set the current locale.
translate (arguments)
Translate a singular text.
arguments[0] The text to translate. [arguments[n]] Optional parameters for sprintf to replace markers in the text.
Depending on the markers a list of parameters, an array, or an object can be used.
;;;;
__ (arguments)
Alias for translate ().
translatePlural (arguments)
Translate a text as singular or plural, depending on the count.
arguments[0] The singular text to translate. arguments[1..(nPlurals-1)] The plural text to translate. arguments[nPlurals..n] The count and parameters for sprintf to replace markers in the text.
Depending on the markers a list of parameters, an array, or an object can be used.
;;;;
_p (arguments)
Alias for translatePlural ().