org.symbian.tools.wrttools.doc.WebDeveloper/html/GUID-C442113C-5FBE-493E-AD5A-CF0A0FB3C5FD.html
author Eugene Ostroukhov <eugeneo@symbian.org>
Fri, 04 Jun 2010 09:44:40 -0700
changeset 345 7723a46fe224
parent 229 716254ccbcc0
permissions -rw-r--r--
Bug 2480 - Excluded resources are still available in preview and debugger


<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="concept"/><meta name="DC.Title" content="Localizing widget display text"/><meta name="abstract" content="Widget display text can be localized at run time to match with the current system language."/><meta name="description" content="Widget display text can be localized at run time to match with the current system language."/><meta name="DC.Relation" scheme="URI" content="GUID-63F29096-C1A3-45DB-9E2F-6110562E0237"/><meta name="DC.Relation" scheme="URI" content="GUID-4CD10DEB-6C79-4320-AC82-F17DD264CF28"/><meta name="DC.Relation" scheme="URI" content="GUID-1EFD7043-E9B8-4B4E-9EA6-A20B3EECC14A"/><meta name="DC.Relation" scheme="URI" content="GUID-E3EA4F85-E0AE-42AB-8E51-EFD3F0E0A51E"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-C442113C-5FBE-493E-AD5A-CF0A0FB3C5FD"/><title>Localizing widget display text </title><script type="text/javascript">
      function initPage() {}
    </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-C442113C-5FBE-493E-AD5A-CF0A0FB3C5FD">Localizing widget display text</h1><div><p>Widget display text can be localized at run time to match with the current system language.</p>
<div><h3>To localize widget display text</h3><ol>
<li id="GUID-B23E2FC2-0CA8-4E4E-ABFC-2842D96C5504"><a name="GUID-B23E2FC2-0CA8-4E4E-ABFC-2842D96C5504"><!----></a><p>Predefine the display text strings in separate JavaScript files that you create for each supported language.</p><p>The name of the JavaScript file is arbitrary, but the name must be identical for all the supported languages so that you need to specify the name only once in the <a href="GUID-C294F32D-CAC7-499C-AD4B-701B9AB57ACA.html#GUID-C294F32D-CAC7-499C-AD4B-701B9AB57ACA">main HTML document</a>.</p></li>
<li id="GUID-7082F7A3-1E8F-4A7D-816F-F42FBB46CA4D"><a name="GUID-7082F7A3-1E8F-4A7D-816F-F42FBB46CA4D"><!----></a><p>In the JavaScript files, use arrays for holding the localized text strings.</p><p>The name and structure of the array are arbitrarily implemented but they must be identical for all languages (except for the localized text strings). For an example of creating the array, see <a href="GUID-8DC78944-809B-462B-BEC2-0114696F8B14.html#GUID-8DC78944-809B-462B-BEC2-0114696F8B14">Localizing STEW</a>.</p></li>
<li id="GUID-2F2F7E2D-1DEE-45C2-8B1E-67AFAC461F49"><a name="GUID-2F2F7E2D-1DEE-45C2-8B1E-67AFAC461F49"><!----></a><p>Store the JavaScript files into the appropriate <a href="GUID-71BE0F0B-B6B2-475C-A87B-A04E207F3292.html#GUID-71BE0F0B-B6B2-475C-A87B-A04E207F3292">language project directories</a>.</p></li>
<li id="GUID-47A66210-F438-4446-9A0E-E296917F3D82"><a name="GUID-47A66210-F438-4446-9A0E-E296917F3D82"><!----></a><p>Provide a JavaScript file for default text strings (for example, in English) and store it in the root directory of the widget.</p><p>The default text strings are used in case the current system language does not match with any provided local language. The name of the default text strings file must be identical to the name of the localized text strings files.</p></li>
</ol></div>
<div><h3>Example</h3><p>The following pieces of code provide an example of localizing display text to English and Finnish:</p><p><em>Specified in the main HTML document:</em></p><pre class="codeblock" id="GUID-04BBDE79-9FEC-4B70-8A85-1CA1E3BC5A71">&lt;script type="text/javascript" src="localizedTextStrings.js" /&gt;</pre><p><em>Implemented in a </em><code>localizedTextStrings.js</code><em> JavaScript file:</em></p><p>English version for the English language directory <code>en.lproj</code>:</p><pre class="codeblock" id="GUID-76CCBB66-06E1-43AA-B3BB-2D92D94FAAE0">  var localizedMenu = new Array();
  localizedMenu['setting'] = "Settings";
  localizedMenu['open'] = "Open";
  localizedMenu['close'] = "Close";
   
  var localizedInfo = new Array();
  localizedInfo['congrat'] = "Congratulations!";
</pre><p>Finnish version for the Finnish language directory <code>fi.lproj</code>:</p><pre class="codeblock" id="GUID-30C8A6A9-C463-4140-9291-E785F9FED4CF">  var localizedMenu = new Array();
  localizedMenu['setting'] = "Asetukset";
  localizedMenu['open'] = "Avaa";
  localizedMenu['close'] = "Sulje";

  var localizedInfo = new Array();
  localizedInfo[0] = "Onneksi olkoon!";
</pre><p>Default version in English to be stored in the widget root directory:</p><pre class="codeblock" id="GUID-3FA7B29E-9354-464C-A839-1C7B5B0260E5">  var localizedMenu = new Array();
  localizedMenu['setting'] = "Settings";
  localizedMenu['open'] = "Open";
  localizedMenu['close'] = "Close";
   
  var localizedInfo = new Array();
  localizedInfo['congrat'] = "Congratulations!";
</pre><p><em>Defined in the JavaScript file that implements the logic of the widget:</em></p><pre class="codeblock" id="GUID-EE1CD136-D67D-4B06-9362-0BBA742B49BF">function init() {
  var settingMenuItem = new MenuItem(loadLocalizedMenu("setting"), 10);
  var openMenuItem = new MenuItem(loadLocalizedMenu("open"), 11);
  var playMenuItem = new MenuItem(loadLocalizedMenu("close"), 12);
  ...
	 displayInfo(0);
}
function displayInfo(index) {
  alert(localizedInfo[index]);
}
function loadLocalizedMenu(index) {
  if (localizedMenu[index])
    return localizedMenu[index];
  else 
    return "not found";
}
</pre></div>
</div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html>