Revision as of 04:58, 1 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Example Localization in WidSets

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Created: User:Mirsilla (26 May 2008)
Last edited: hamishwillee (01 Jul 2012)

This example shows how to localize strings used in widget.

Do the following:

  • Change all "Text string" notations to @text.id notations.
  • Create a [iso2code].properties file for each language, save them in ASCII format, and if possible escape unicode by using the \u1234 notation (use the native2ascii program that comes with JDK).
  • List all properties files in your widget.xml as language resources, with value as "iso2code" and text as the language name.

Known problems

  • Strings defined in widget.xml itself cannot be localized. This includes parameter descriptions and values, info-metadata, and library descriptions.

See also


  const int CMD_BACK    = 1;
  /** Not like this 1
   * MenuItems need to be created and used dynamically to
   * get the current language in use.
   * MenuItem BACK        = new MenuItem(CMD_BACK, @option.back);
   * MenuItem LANGUAGE    = new MenuItem(OPEN_SETTINGS, @option.language);
  /** Not like this 2
   * If you declare this method, the widget is not automatically restarted
   * when parameters (language parameter) are changed and the language
   * of the widget will not change before the widget is reloaded.
   * void parametersChanged()
   * {
   * }
  void startWidget()
    printf("* Staring localization widget: "+getParameter("language"));
    setMinimizedView(createMinimizedView("viewMini", getStyle("default")));

  Shell openWidget()
    Flow flow = new Flow(getStyle("maxi"));
    flow.setPreferredSize(-100, -100);
    Scrollable scroll = new Scrollable(getStyle("maxi"), flow);
    return new Shell(scroll);

  Component createElement(String viewName,
                          String elementId,
                          Style style,
                          Object context)
    //the label used on minimized view
    if ("name".equals(elementId)) {
      return new Label(style, @content.header);
    return null;
  Label createHeader(String text)
    Label l = new Label(getStyle("header"), text);
    return l;
  Text createText(String text)
    Text t = new Text(getStyle("text"), text);
    return t;
  MenuItem getSoftKey(Shell shell, Component focused, int key)
    if (key == SOFTKEY_OK) {
      return new MenuItem(OPEN_SETTINGS, @option.language);
    } else if (key == SOFTKEY_BACK) {
      return new MenuItem(CMD_BACK, @option.back);
    return null;
  void actionPerformed(Shell shell, Component source, int action)
    if (action == CMD_BACK) {


<?xml version="1.0" encoding="utf-8"?>
<widget spec_version="2.0">
    <shortdescription>Localization Example</shortdescription>
    <longdescription>Localization Example</longdescription>
    <tags>example localization</tags>
    <parameter name="widgetname" visible="false">Localization Example</parameter>
    <parameter name="language" description="Language" editable="true" visible="true">
      <option selected="true" value="en">English</option>
      <option value="fi">Finnish</option>
      <option value="sv">Swedish</option>
    <code src="localization.he"/>

    <lang id="en" src="en.properties"/>
    <lang id="fi" src="fi.properties"/>
    <lang id="sv" src="sv.properties"/>
      mini {
        background: solid white;
        color: black;
        align: vcenter hcenter;

      maxi {
        background: solid white;
        color: black;
        align: top hcenter;

      header {
        color: black;
        align: vcenter hcenter;
        font: medium plain;

      text {
        color: black;
        align: top left;
        font: small plain;
  <layout minimizedheight="3em">
    <view id="viewMini" class="mini">
      <script id="name" class="mini" top="0%" bottom="50%"/>
      <label class="mini" top="50%" bottom="100%">[${language}]</label>


option.back = Back
option.language = Language

content.header = Localization example
content.text = English content in English language


option.back = Takaisin
option.language = Kieli

content.header = Lokalisointiesimerkki
content.text = Suomen kielellä olevaa kontenttia suomeksi


option.back = Tillbaka
option.language = Språk

content.header = Localization exämppel
content.text = Svenska text
This page was last modified on 1 July 2012, at 04:58.
34 page views in the last 30 days.