Module: siteKiosk.localization.stringTable

This module allows to register multiple translations for strings and to retrieve the correct translation for the current locale. The translations are read as an xml string. A file containing translations could be as follows:

Examples

A sample string table

<?xml version="1.0" encoding="utf-8" ?>
<StringTable DefaultLocale="en">
   <Locale Name="en">
       <String Id="HelloSKApp.Title">HelloSKApp</String>
       <String Id="HelloSKApp.Description">A simple SiteKiosk app.</String>
   </Locale>
   <Locale Name="de">
       <String Id="HelloSKApp.Title">HelloSKApp</String>
       <String Id="HelloSKApp.Description">Eine einfache App für SiteKiosk.</String>
   </Locale>
</StringTable>

String table usage

//assume the xml file above is already loaded into some variable
siteKiosk.localization.stringTable.loadStrings(sampleXMLFileContent);
siteKiosk.localization.stringTable.setLocale("de");

//logs 'Eine einfache App für SiteKiosk.'
console.log("HelloSKApp.Description");

Methods

<static> getLocale() → {string}

Gets the current locale.
Returns:
The current locale
Type
string

<static> getString(key) → {string}

Retrieves a string by key for the current locale.
Parameters:
Name Type Description
key string The name of the localized string, which is typically a number, but can also be a well-known string
Returns:
The localized string or the one from the fallback language or '[n/a - key]'
Type
string

<static> loadStrings(xml)

Registers new translations.
Parameters:
Name Type Description
xml string A XML string, containing translations

<static> setLocale(value)

Sets the current locale.
Parameters:
Name Type Description
value string The locale to be the current locale