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 |
---|---|---|---|---|
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" |
Â