Using indexed external messages
When using indexed external messages, you can perform the following operations:
•Unload to create or add messages
•Load to retrieve messages
•Delete to remove messages
Unloading indexed external messages
The unload:language:territory:characterSet:index: protocol is used to create or add an indexed message to a message catalog file for a particular locale and character set. This protocol can also be used to overwrite the value of an existing indexed external message. Several indexed external messages can be stored in a single message catalog file by making repeated calls using unload:language:territory:characterSet:index:. The following example illustrates the process of unloading indexed messages into a message catalog file. Return values of all NlsMessageCatalog operations must be checked to ensure that the operation has succeeded.
"A code fragment to create a message catalog file called 'demo.cat'
containing a single indexed external message for the #('english' 'us')
locale and the 'iso8859-1' character set."
| catalog |
catalog := NlsMessageCatalog on: 'demo.cat'.
"Create the message catalog file."
(catalog unload: 'This is an indexed external message'
language: 'english'
territory: 'us'
characterSet: 'iso8859-1'
index: 1) ifFalse: [
^self error: 'Unload error: ',catalog currentErrorString].
Loading indexed external messages
The loadLanguage:territory:characterSet:index: protocol retrieves an indexed external message from a message catalog file. The NlsMessageCatalog answers the message retrieved from the catalog, or nil if an error occurs. The following example illustrates the procedure for loading indexed external messages.
"A code fragment to load indexed external message number 1 from an
existing message catalog file called 'demo.cat' for the #('english' 'us')
locale and the 'iso8859-1' character set."
| catalog |
catalog := NlsMessageCatalog on: 'demo.cat'.
(catalog loadLanguage: 'english'
territory: 'us'
characterSet: 'iso8859-1'
intoDictionary: MyNlsMessages
index: 1) isNil ifTrue: [
^self error: 'Load error: ',catalog currentErrorString].
Deleting indexed external messages
You can delete an indexed external message from a message catalog file using the deleteIndex:language:territory:characterSet: protocol. This operation removes only the indexed external message stored for the specified language, territory, character set, and index and does not affect any other indexed external messages or message dictionaries. The following example demonstrates how to delete an indexed external message from a message catalog file.
"Removes the indexed external message number 1 for the
#('english' 'us') locale and the 'iso8859-1' character set."
| catalog |
catalog := NlsMessageCatalog on: 'demo.cat'.
(catalog
deleteIndex: 1
language: 'english'
territory: 'us'
characterSet: 'iso8859-1') ifFalse: [
^self error: 'Deletion error: ',catalog currentErrorString].
Note:
Deleting an indexed external message does not immediately decrease the size of the message catalog file on disk. Deleted indexed external messages are marked as garbage and their space is reclaimed when the message catalog file is compressed. See
Compression for a discussion of the compression of message catalog files.
Deletion is a permanent operation and cannot be undone. After an external message dictionary is deleted, it is lost.
Last modified date: 01/29/2015