Phone API Reference - Extended - app.t

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

app.t

Description

Returns the translated string of the specified language key. 

Basic Example: 

var text = app.t(key[, vars, count]);

 

Parameters

Name

Required

Type

Default

Description

Name

Required

Type

Default

Description

key

Yes

string

 

The language key used to fetch a string. If no string is found for the key, then the key is returned as the string.

vars

No

array

 

An array of variables to use for substitution in your string. For example, if your string is "This %s belongs to %s" and you pass ['Pizza', 'Bob'] for vars, the string returned will be "This Pizza belongs to Bob".

count

No

integer

1

The integer to use for pluralization. This is used if you provide different forms of your string based on the pluralization. For example, your lang key might define the following ['I have one index', 'I have many indices']. If you pass a value of 1 for vars then the first string will be returned by the translate function, if you pass a value of more than 1, then the second form will be returned.

 

Examples

Various examples of app.t

/*   For the purpose of this example, lets assume we have included a strings-en_us.js file in our   package and it looks like this.   This covers each combination of ways the translation library can be used.       exports.keys = {      "T_HELLO_WORLD" : ["Hello World"],      "T_MY_NAME_IS" : ['My Name is %s"],      "T_DOG" : ["Dog", "Dogs"],      "T_PERSON_PPL" : ["I employ %s person", "I employ %s people."],      "T_MY_ADDRESS" : ["My address is %s; %s, %s %s"]  };  */    app.t("T_HELLO_WORLD");  // returns "Hello World" app.t("T_MY_NAME_IS", ["Ryan"]);  // returns "My Name is Ryan" app.t("T_DOG", [], 1); // returns "Dog" app.t("T_DOG", [], 2);  // returns "Dogs" app.t("T_PERSON_PPL", [1], 1);  // returns "I employ 1 person." app.t("T_PERSON_PPL", [3], 3);  // returns "I employ 3 people." app.t("T_MY_ADDRESS". ["12 Brown St.", "San Diego", "CA", "91211"]);  // returns "My address is 12 Brown St.; San Diego, CA 91211"

 

Return to Documentation Home I Return to Sangoma Support