To successfully localize your apps and services, you need to internationalize them first.
Internationalization mainly carries out the following two tasks: marking text strings for translation and formatting locale-sensitive data. Text strings of your apps and services need to be marked for translation. Formatting locale-sensitive data, such as dates, times, numbers or currency, for different locales and cultural conventions are also required. These are done by using an external internationalization library for each supported programming language.
Internationalization in webOS OSE is available for different programming languages. See Overview for the list of supported programming languages.
Note This page only provides guides for marking strings for translation. For more information about formatting locale-sensitive data, please refer to the user guide of the provided internationalization library for each programming language.
JavaScript
For web apps developed in JavaScript, use iLib to internationalize your code.
Enact framework offers the $L component as part of its i18n library, which provides functions to map to translated strings.
Example for $L usage
import $L, {toIString} from '@enact/i18n/$L';
$L('Close'); // => "Close" in the current locale
toIString('Close'); // => an ilib IString representing "Close" in the current locale
For web apps that do not utilize Enact framework, use the getString() API of ResBundle feature in iLib.
Making and Importing Your Own iLib
First, make your own iLib build version and import it into your app as follows:
Extract iLib features in your app.
iLib-js provides ilib-scanner. This utility generates webpack metafiles, and the metafiles include only those iLib classes that your code actually needs.
After making and importing iLib, use the ResBundle.getString() method of iLib as follows:
Example for a non-Enact web app
var rb =new ResBundle({locale:"en-US"});
var str = rb.getString("String 1"); // str is iLib string object
var jsStr = str.toString(); // jsStr is js string object
C++/C
If you are developing apps or services in C++/C, use libwebosi18n to internationalize your code.
The following shows an example which uses the getLocString() API of libwebosi18n in C++ and C: