Each locale item encapsulates the information about a particular object in a locale. Each object within a locale is identified by an item identifier, an instance of TText, that uniquely identifies the purpose of that object regardless of both the data within that object and its locale. For example, the identifier kTypingConfigurationID
identifies the preferred typing configuration for a locale, whether it is the U.S. English configuration, the French configuration, or any other configuration. The TLocale class defines a set of constant identifiers for common items.
Predefined locale items
The following table lists the set of predefined identifiers for items commonly found in any locale. These identifiers are static constant TText instances scoped to the TLocale class.
Identifier | Type of object | Example: U.S.A. locale | Example: French locale | |
kAbbreviatedDateFormatID | TDateTimeFormatter* | Apr 1, 1999 | Jeud 1 avr 99 | |
kBodyTextFontID | TFontIdentifierStyle* | Times | Times | |
kCalendarID | TCalendar* | Gregorian calendar | Gregorian | |
kCountryID | TLocalizableName* | "U.S.A." | "France" | |
kCurrencyFormatID | TNumberFormatter* | $1,234,567.99 $0.00 ($1,234,567.99) | 1 234 567,99 F 0,00 F -1 234 567,99 F | |
kDefaultTimeFormatID | TDateTimeFormatter* | 11:12 PM | 23:12 | |
kFullDateFormatID | TDateTimeFormatter* | Thursday, April 1, 1999, 11:12 PM | Jeudi 1 avril 1999, 23:12 | |
kMenuTitleFontID | TFontIdentifierStyle* | Chicago | Chicago | |
kNumberFormatID | TNumberFormatter* | 1,234,567.9999 | 1 234 567,9999 | |
kNumericDateFormatID | TDateTimeFormatter* | 4/1/99 | 1/4/99 | |
kTextOrderItemID | TTextOrder* | English collation table | French collation table | |
kTimeZoneID | TTimeZone* | Greenwich Mean Time | Greenwich Mean Time | |
kTypingConfigurationID | TTypingConfigHandle* | American keyboard with accent and smart quote transliteration | French keyboard |
Getting a preferred object
To use an object from a particular locale, create a TLocaleItem to represent that object and then copy the object into that TLocaleItem instance.
To retrieve an object from a particular locale:
This example demonstrates how to retrieve the default number formatter from the current locale.
// Get the current locale. TLocale currentLocale = TLocale::GetCurrentLocale(); try { TLocaleItem<TNumberFormatter> numberFormatterItem; TDeleterFor<TNumberFormatter> numberFormatter = numberFormatterItem.CopyItem( TLocale::kNumberFormatID, currentLocale ); } catch (TArchiveException&) { // You can either rethrow the exception or directly // instantiate an acceptable object, in this case, a // concrete subclass of TNumberFormatter. }