Localising strings in Symbian Web Runtime
This code snippet demonstrates how to localise strings in Symbian Web Runtime.
Article Metadata
Code Example
Tested with
Compatibility
Article
Overview
To localise the strings, you should place the files for the default language into the root directory of your widget and the localised files into subfolders named "***.lproj", without quotes, where *** is the language code. For example:
/strings.js (the JavaScript file containing strings for the default language)
/en.lproj/strings.js (the JavaScript file containing English strings)
/ru.lproj/strings.js (the JavaScript file containing Russian strings)
/de.lproj/strings.js (the JavaScript file containing German strings)
For the list of language codes, see Web Runtime localisation support.
Source file: wrtstub.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="StyleSheet" href="style/general.css" type="text/css" />
<script type="text/javascript" src="script/common.js" />
<script type="text/javascript" src="strings.js"/>
<script type="text/javascript" src="script/wrtstub.js" />
<title>WRT Stub</title>
</head>
<body>
<div id="bodyContent" class="bodyContent">
<hr />
<div id="txt"></div>
<hr />
</div>
</body>
</html>
Source file: infoplist.strings
DisplayName = "DEF_Localization"
Source file: en.lproj/infoplist.strings
DisplayName = "EN_Localization"
Source file: de.lproj/infoplist.strings
DisplayName = "DE_Lokalisierung"
Source file: ru.lproj/infoplist.strings
DisplayName = "RU_Локализация"
Source file: localizationStrings.js
// Executes the snippet.
function executeSnippet() {
showLocalizedString();
}
/**
* Shows a localized string.
*/
function showLocalizedString() {
document.getElementById('txt').innerHTML = '<p>' + mainString + '</p>';
}
Source file: strings.js
var mainString = 'DEF_Localization';
Source file: en.lproj/strings.js
var mainString = 'English string';
Source file: de.lproj/strings.js
var mainString = 'Deutsch zeile';
Source file: ru.lproj/strings.js
var mainString = 'Русская строка';
Postconditions
Upon installation, the application sets its name according to the currently used language.
When the user selectes the Execute snippet menu item, the application shows a string between two horizontal lines in the currently used language. For example, on a device with English language, the user will see a string in English.
There are strings for English, German, and Russian languages, and one default string.
Supplementary material
This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful to developers. The version of the WRT stub application used as a template in this snippet is v1.1.
- The patched, executable application that can be used to test the features described in this snippet is available for download at Media:Localizing strings in WRT.zip.
- You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in Media:LocalizingStrings.diff.zip.
- For general information on applying the patch, see Using Diffs.
- For unpatched stub applications, see Example app stubs with logging framework.


(no comments yet)