Localization

What is localizable?

Within HP webOS applications, application names and JavaScript/HTML text can be localized.

Application Names

The name of a webOS application can be localized by copying the appinfo.json file into the localized resources folder (for example, into /resources/es_us/appinfo.json). The file is encoded in UTF-8. (Please do not define a Byte Order Mark.) Keep all the fields of the original appinfo.json file in the localized version copy, put the translated app name into the "title" value, and also change the paths of index.html and the icon files to their correct relative location:

{
  "title": "translated app name",
  "main": "../../index.html",
  "icon": "../../icon.png",
  "miniicon": "../../icon.png"
}

JavaScript Strings

In JavaScript files, all localizable strings should use the $L() function:

$L("My text here");

If the original string is not appropriate as a key, the $L() function can be called with an explicit key:

$L({value:"Done", key: "done_key"});

At run-time, the result of the call to $L() is the translation of the string passed as value. The translations live in the /resources/<locale>/strings.json file.

Example:

Content of file app_name/resources/es_us/strings.json

{
  "My text here": "Mi texto aquí",
  "done_key": "Listo",
  "Some other string": "Some other string's translation"
}

The strings.json file is encoded in UTF-8 (again, please do not define a BOM), and as its name suggests, it is a JSON file.

Please do not use concatenations, and include your variables inside the localizable strings, since when translated they can change their location and order relative to the rest of the localizable text:

"Not enough memory to #{action} the file #{fname}."

becomes (in Finnish):

"Liian vähän muistia tiedoston #{fname} #{action}."

Also, use templates for localizable strings containing variables:

var data={num:10};
var localizedText = $L("You have #{num} messages").interpolate(data);

or

var template = new Template($L("You have #{num} messages"));
var localizedText = template.evaluate({num: 10});

Note that this concept applies to other areas where such strings are used, for example, in the Mojo.Format.formatChoice method. In this case, the localized strings would be used like this:

return Mojo.Format.formatChoice(
  numComments,
  $L("0##{num} Comments|1##{num} Comment|1>##{num} Comments"),
  {num: numComments}
); 

This is the recommended method for handling plural cases in different languages.

HTML Text

For localizable HTML text, you can include a copy of the localized HTML under app_name/resources/<locale>/views.

Example:

Content of app_name/views/dialogs/text-scene.html:

<div class="row">
  My<br />text <strong>here</strong>!
</div>

Localized content for es_es in app_name/resources/es_es/views/dialogs/text-scene.html:

<div class="row">
  ¡Mi<br />texto <strong>aquí</strong>!
</div>