Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

However, you can create your own Language object and use its translate method.

Code Block
 /* Let's assume we have two string files for our app and they look like the following. [strings-en_us.js] exports.keys = { 'T_MY_APP' : 'My App', 'T_SETTINGS' : 'Settings' 'T_HAVE_DOGS' : ['I have %s dog', 'I have %s dogs'] }; [string-es_mx.js] exports.keys = { 'T_MY_APP' : 'Mi aplicación', 'T_HAVE_DOGS' : ['Tengo un perro', ' Tengo %s perros'] }; /* instantiate Language object set to es_mx (Spanish/Mexico) with a default of en_us (English/USA). If a key is missing from es_mx, the library will try to find it in the default language's strings file. */
var langObj = new Language({'langLocale' : 'es_mx', 'defaultLangLocale' : 'en_us'});
  
var str = langObj.translate({'key' : 'T_APP_TITLE'});  // returns "Mi aplicación"
var str2 = langObj.translate({'key' : 'T_SETTINGS'});  // returns "Settings" because the key does not exist in the es_mx file
var str3 = langObj.translate({'key' : 'T_HAVE_DOGS', 'count' : 4, 'vars' : ['4']}); //returns Tengo 4 perros