Open C Localization |
Locale defines the subset of a user's environment that depends on language and cultural conventions. It is made up from one or more categories. Each category is identified by its name and controls specific aspects of the behavior of components of the system's components.
The convention followed in POSIX to identify the locale is as follows:
Example: en_US.ISO-8859-1, where en represents English language, US represents the United States of America, and ISO-8859-1 is the character set.
NOTE! The Symbian OS implementation supports only the LC_MONETARY, LC_NUMERIC, and LC_TIME categories.
Character set information is stored as text files in the /usr/share/i18n/charmaps/ directory.
The entry in the file looks as shown below :
<U0030> /x30 DIGIT ZERO, where U0030 is a UNICODE-16 value and x30 is an ISO-8859-1 value, which is followed by the description of the character. Locale information related to a particular country is stored in a locale definition file in the text format in the/usr/share/i18n/locales/ directory.
NOTE! The Symbian OS implementation does not use the above-mentioned mechanisms for character sets or for storing locale information.
In Symbian OS locale-specific information is built as a DLL. The user can change the locale information related to a specific country by loading the appropriate DLL.
The convention followed in naming the DLL is as follows:
elocl.language_index - The list of languages supported by Symbian OS is enumerated in TLanguage. Each value in the TLanguage enumeration uniquely identifies a language. TLanguage enumeration can be found in the e32Const.h header file.
Examples:
Symbian OS provides the TLocale class to set the system-wide locale settings and to retrieve system-wide locale setting. The TLocale class provides methods for setting the following information: calendar settings, country code, currency format, date and time formatting, numeric values, time zone information, and units of distance.
In Symbian OS most applications do not need to change the locale settings; they just use the system setting instead.
The user can load the appropriate locale-specific DLL to fetch the locale data. The function given below is a way to fetch the locale-specific information.
void LoadLanguageDLL() { //Finnish _LIT(KDllName, "elocl.09"); RLoader loader; TInt r = loader.Connect(); if(KErrNone == r) { //Load the language variant DLL TInt size = KNumLocaleExports * sizeof(TLibraryFunction); TPtr8 functionListBuf((TUint8*) data, size, size); r = loader.SendReceive(ELoadLocale, TIpcArgs(0, KDllName, &functionListBuf ) ); if(KErrNone == r) { ((TLibFn)data[FnLocaleData])(&iLocale); retVal = (TText*) aLocale.Ptr(); } loader.Close(); } }
Setting the locale by writing a program in POSIX is easier compared to the locale settings in Symbian OS. In POSIX the user does not need to be aware of the locale information, whereas in Symbian OS the user should be aware of it.
Example: The code below sets the monetary information of Finland using POSIX:
#include <stdio.h> #include <locale.h> int main() { //before fetching the monetray information it is assumed that locale is set to finnish struct lconv* localeinfo = localeconv(); return 0; }
The lconv structure has the complete monetary information.
The code below sets the monetary information of Finland using Symbian C++:
#include <e32std.h> void doExampleL() { TLocale locale; locale. SetCurrencySymbolPosition(ELocaleAfter); locale. SetCurrencySpaceBetween(ETrue); locale. SetCurrencyDecimalPlaces(2); locale. SetCurrencyTriadsAllowed(ETrue); locale. SetNegativeCurrencyFormat(TLocale::ELeadingMinusSign); //similarly other monetary information should be set individually. }
©Nokia 2007 |