Phone API Reference - Extended Classes - Language - translate

Desk Phone API features described in this section are deprecated and supported only on the following models: D40, d45, d50, d60, d62, d65, d70

translate

Description

Look up a language key and test it against the currently specificed language.

Basic Example: 

var string = langObj.translate(parameters);

 

Parameters

Name

Required

Type

Default

Description

Name

Required

Type

Default

Description

key

Yes

string

 

Key to lookup that was exported in strings file.

vars

No

array

[]

Array of variables for substitution. For each %s found in the language string, these variables are substituted in order starting with index 0.

count

No

integer

1

Number of items. Intended for language keys whose value is a pluralized array.

 

Examples

Language.translate for translation

/* 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

Return to Documentation Home I Return to Sangoma Support