Building Localized Apps

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

If you have users who speak different languages, you don't have to build multiple apps. This guide explains how one app can use your translation library along with properly named string files to provide multiple language experiences.

 

Language Files

Your app can include multiple language/locale-based string files. Each file should be included in your app.zip file and must be named in this way:

strings-[language]_[locale].js strings-es_mx.js

 

Each file exports a 'keys' object of key-value pairs that are a language key and a language string. The values are mapped to arrays, which can (optionally) contain singular and pluralized versions of the string. For example:

exports.keys = {     'TRANS_KEY_FOO' : ['Foo translation string.'],     'TRANS_KEY_BAR' : ['I have %s banana', 'I have %s bananas'] };

Using the Language APIs

In your application, when you want to display a string, do not put the language string in the app. Instead, pass the language key to the translator. The phone uses the correct file, finds the string, and displays it to the user.

The phone's chosen localization setting determines which language file the phone uses. However, if the app.zip does not include a language file for the chosen language, the phone uses the en_us language file or whichever you have indicated by the defaultLangLocale parameter you use when you initialize the app (app.init).

Using app.t is the prefered way to utilize translation. 

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

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

Return to Documentation Home I Return to Sangoma Support