Localizing widget resources

You might need to localize widget resources, such as images, to support multiple languages.

To localize widget resources

  1. Create localized versions of the resources for the languages that require localization.

  2. Store the files into the appropriate language project directories.

  3. Provide default resources in the widget root directory.

    If a specific language does not require resource localization, the resource files do not need to be included in the corresponding language project directory. When that language is set as the device language, the default resources are loaded and used.

When loading a localized resource, specify the path to the resource file as relative to the widget root directory.

Example

The following pieces of code provide an example of widget resource localization for Finnish, English and for a default case.

  1. Add the Finnish flag for use when system language is Finnish:

    [root]\fi.lproj\
       flag.png
  2. Add the English flag for use when the system language is English:

    [root]\en.lproj\
       flag.png
  3. Add the UN flag for use with any other system language:

    [root]\
       flag.png
  4. In the JavaScript file that implements the logic of the widget, create the following code to load and show the appropriate flag dynamically. :

    var flag = document.createElement('img');
    flag.setAttribute('src', 'flag.png');