Obtaining LCMessages, LCMonetary, LCNumeric, and LCTime objects
When the current locale is initialized, new LCMessages, LCMonetary, LCNumeric, and LCTime objects are created, initialized, and stored. The current LCMessages, LCMonetary, LCNumeric, and LCTime objects can be retrieved by sending the lcMessages, lcMonetary, lcNumeric, and lcTime messages to the current locale (Locale current).
Multiple instances
VAST Platform supports the use of multiple LCMessages, LCMonetary, LCNumeric, and LCTime objects. Each instance of these classes maintains information for a particular locale and can be created using the for: protocol. The argument to the for: message is an array of two strings specifying the language and territory for which information is to be retrieved.
New instances for the platform default locale
New instances of the LCMessages, LCMonetary, LCNumeric, and LCTime classes can be created and initialized for the platform default locale using the for: protocol and an array of two empty strings--that is, #('' '')--as the parameter. This platform default value is always guaranteed to be available. The following code example answers a new LCMonetary object initialized for the platform default locale.
LCMonetary for: #('' '')
New instances for different locales
New instances of the
LCMessages,
LCMonetary,
LCNumeric, and
LCTime classes can be created, and initialized, for a particular locale using the
for: protocol and an array containing the language and territory strings of the requested locale as the argument. For a complete list of valid language and territory combinations, refer to
Table 53. You can see what language and territory combinations your operating system supports by evaluating
Locale knownLocales.
If the information for the requested locale is not available, the for: message answers nil. Otherwise, the newly created and initialized object is answered. The following code fragment queries the operating system for the monetary formatting information for the territory 'us' and language 'english.' Note that the territory and language strings must be in lowercase.
LCMonetary for: #('english' 'us')
Example usage of locale-specific information
The following method uses the current Locale and LCMessages, to print a list of items using the locale-defined data separator:
printedItems: anIndexableCollection
"Print the items in anIndexableCollection separated by the data separator
for the current locale."
| stream sep |
sep := Locale current lcMessages dataSeparator.
stream := WriteStream on: Locale current preferredStringClass new.
1 to: anIndexableCollection size - 1 do: [:index |
(anIndexableCollection at: index) printOn: stream.
stream nextPutAll: sep].
anIndexableCollection last printOn: stream.
^stream contents
Last modified date: 02/21/2021