NlsMessageCatalog supports
compatibilities, a mechanism to facilitate the sharing of translations among locales. Compatibilities can also be used to describe the default messages to be used in the event that the message catalog file does not contain messages for the current locale and character set.
NlsMessageCatalog compatibilities are stored in a sequenceable collection (array) of arrays. The first element of each array describes the primary language, territory, and character set (locale triple) for which localized message strings are actually stored in the catalog file. The remaining elements of each array describe locales which are compatible with, and can use the messages of, the primary locale. A catalog file contains one set of compatibilities.
NlsMessageCatalog>>localeCompatibleWithLanguage:territory:characterSet: can be used to determine the locale whose messages are compatible with a given language, territory, and character set. The compatibilities depicted in the example above indicate that the catalog contains messages for primary locales
japanese-japan-ibm-932,
german-germany-iso8859-1, and
english-us-ansi-ascii.
Given a locale triple, localeCompatibleWithLanguage:territory:characterSet: first determines if messages are explicitly stored for that locale. In the above example, the locale
japanese-japan-ibm-932 is actually stored in the catalog. Therefore,
localeCompatibleWithLanguage:territory:characterSet uses the messages of this locale without consulting the compatibility information. Similarly, locales
german-germany-iso8859-1 and
english-us-ansi-ascii use their stored messages.
If messages for the given locale are not explicitly stored in the catalog, localeCompatibleWithLanguage:territory:characterSet: uses the compatibility information to determine the compatible locale. The process starts with the first array (for example,
('japanese-japan-ibm-932' 'japanese-japan-microsoft-shiftjis') in the previous example) and proceeds sequentially until the last array (for example,
(english-us-ansi-ascii' '*-*-*') in the previous example). If an element of an array matches the given locale the messages of the primary locale (for example,
japanese-japan-ibm-932) are considered to be compatible with the given locale. Compatibility matching stops after the first match is found.
The last compatibility illustrated in the previous example, #('english-us-ansi-ascii' '*-*-*'), indicates that if no other array was able to match the given locale triple, use
*-*-* to match the locale triple, and default to using
english-us-ansi-ascii messages. ANSI-ASCII characters are contained in the lower portion of many character sets and thus provide a reasonable fall-back.
NlsMessageCatalog provides the
compatibilities and
compatibilities: methods to retrieve and store message catalog compatibilities. The following example illustrates the process of storing and retrieving message catalog compatibilities.
Copyright 2005, 2020 Instantiations, Inc. All rights reserved.