Skip to main content

%Library.MessageDictionary

class %Library.MessageDictionary extends %Library.RegisteredObject

For information on this class, see String Localization and Message Dictionaries.

The %MessageDictionary is introduced to allow easy localization of program messages and CSP page content. A %MessageDictionary is a dictionary of messages. Each message in the dictionary is any ObjectScript string and is indexed by any ObjectScript value. A %MessageDictionary is then defined for each language and domain needed by your application. Each message is indexed by language, domain and id.

In order for a %MessageDictionary object to be created (New'ed), a language and domain must be specified for the message dictionary. The format of the specification string is "<language>:<domain>". <language> is an optional RFC 1766 language tag. If not specified the default system language is used. <domain> is a required domain specification, for example "en-us:titles" or ":names".

Property Inventory

Method Inventory

Properties

property Domain as %String;
The Domain attribute defines the logical grouping of messages in the Message Dictionary. If the domain name begins with %, then the Message Dictionary is considered a system Message Dictionary that is visible in all namespaces. Application Message Dictionaries are visible in only the namespace in which they are defined.
Property methods: DomainDisplayToLogical(), DomainGet(), DomainIsValid(), DomainLogicalToDisplay(), DomainLogicalToOdbc(), DomainNormalize(), DomainSet()
property Language as %String;
The Language attribute defines the language of the messages in the Message Dictionary. Language is any RFC 1766 defined language tag. In summary, a language tag is composed of 1 or more parts: A primary language tag optionally followed by a hyphen (-) separated secondary subtag. The Language string will be normalized to all lower case characters.
Property methods: LanguageDisplayToLogical(), LanguageGet(), LanguageIsValid(), LanguageLogicalToDisplay(), LanguageLogicalToOdbc(), LanguageNormalize(), LanguageSet()

Methods

method %OnNew(initvalue) as %Status
Inherited description: This callback method is invoked by the %New() method to provide notification that a new instance of an object is being created.

If this method returns an error then the object will not be created.

It is passed the arguments provided in the %New call. When customizing this method, override the arguments with whatever variables and types you expect to receive from %New(). For example, if you're going to call %New, passing 2 arguments, %OnNew's signature could be:

Method %OnNew(dob as %Date = "", name as %Name = "") as %Status If instead of returning a %Status code this returns an oref and this oref is a subclass of the current class then this oref will be the one returned to the caller of %New method.

classmethod Delete(languages As %String = "", flag As %String = "") as %Status
Delete all Message Dictionary(s) for the specified languages. Languages is an optional comma separated list of languages whose Message Dictionaries are to be deleted. If languages is not specified, Message Dictionaries for all languages are deleted. The "s", system flag, is an optional flag indicating whether system "s" or application Message Dictionaries are to be dleeted. The default value is to delete application Message Dictionaries.

The messages names associated with include files are always deleted, but not any previously geenrated include files. The "d", display, flag is supported.

classmethod Export(file As %String, languages As %String = "", flag As %String = "") as %Status
Export Message Dictionaries to XML file(s). languages is an optional comma separated list of languages. If languages is not specified, all languages are exported. Each language in the list is exported to a separate file. The template for the filename is given by the file argument that is of the format "<filepath>.<ext>". The file will be named by concatenating the language to the <filepath> with an extension of <ext>. The "s", system flag, is an optional flag indicating whether system "s" or application Message Dictionaries are to be exported.
classmethod ExportDomainList(file As %String, domainList As %String, language As %String) as %Status
Export Message Dictionaries for the specified languages and domains. fil is the path of the file to be written. domainList is a comma separated list of domains to be exported. language is an optional language that default to the current session language, $$$SessionLanguage.
method FormatMessage(id As %String, default As %String, args...) as %String
Get and format message text from this Message Dictionary. The default argument is used for the message if no message is found for id. If the default argument is not specified, then string for the default language or English is used as the default. Arguments of the form %1, %2, etc will be replaced by arguments that follow the id argument.
classmethod FormatText(text As %String, args...) as %String
Format the specified message text. Arguments of the form %1, %2, etc will be replaced by arguments that follow the text argument.
classmethod GenerateInclude(includeName As %String, flag As %String = "", DomainList="", UseDomainName As %Boolean = 0) as %Status
Generate an include file mapping the Name attributes of each message in any Message Dictionary to the message id.

The name of the include file to be generated is includeName. The DomainList argument is a comma separated list of names of the domains for which the include file is to generated. If Domain is not specified or "", then all domains are included in the include file. If UseDomainName is true (1), then the domain name as "" is prepended to the message code in the include file. The "s", system flag, is an optional flag indicating whether system, "s", or application Message Dictionaries are to be exported. The "d", display, flag is supported.

classmethod GetDomains(language As %String = "", flag As %String = "") as %ListOfDataTypes
GetDomains returns a list of all domains that have messages loaded for the specified language. If language="" is specifed, the default language is used. The "s", system flag, is an optional flag indicating whether languages supported by system ("s") or application Message Dictionaries are to be returned. The default value is to return the domains for application Message Dictionaries.
classmethod GetLanguages(domain As %String = "", flag As %String = "") as %ListOfDataTypes
GetLanguages returns a list of all languages that have messages loaded for the specified domain or all languages if domain="" Each language is in the standard RFC1766 format and all in lower case. The "s", system flag, is an optional flag indicating whether languages supported by system ("s") or application Message Dictionaries are to be returned. The default value is to return the languages for application Message Dictionaries.
method GetMessage(id As %String, default As %String = "") as %String
Get message text from this Message Dictionary. The default argument is used for the message if no message is found for id. No message formatting is supported by this method.
method GetNextMessage(ByRef id As %String) as %String
Return the text and id of the next message. The text and id of the message with the next id are returned. If the input id = "", then the text and id of the first message are returned. Return an empty string for the message text and id, if the input id was for the last message. Language is optional and the current language is used if language is "" or not specified. Language will be converted to lower case before being used. Domain can be a system domain beginning with % or a application domain.
classmethod GetSessionLanguage() as %String
GetSessionLanguage retrieves the default session language for the messages in the Message Dictionary. The language returned is a RFC 1766 defined language tag.
In summary, a language tag is composed of 1 or more parts: A primary language tag optionally followed by a hyphen (-) separated secondary subtag. The Language string will be normalized to all lower case characters.
classmethod Import(filepath As %String, flag As %String = "") as %Status
Import the Message Dictionary(s) in an XML file specified by filepath. All Message Dictionaries in the file will be imported. The "d", display, flag is supported.

One or more Message Dictionaries may be specified by the XML file in the format given by the DTD at <instance base directory>\dev\csp\rules\CacheMessages.dtd, or url /studio/rules/CacheMessages.dtd. The file may contain Message Dictionaries for only one language and multiple domains. In summary, the file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<MsgFile Language="language">
<MsgDomain Domain="domain">
<Message Id="message_id" Name="message name">message text</Message>
.
.
.
</MsgDomain>
.
.
.
</MsgFile>

We recommend using the UTF-8 encoding for these files whenever possible. Sometimes local platform encodings, such as shift-jis, are needed for ease of editing. The encoding that is picked must be supported by the locale for the application and be able to express the messages for this file's language.

classmethod ImportDir(directory As %String, flag As %String = "") as %Status
Import the Message Dictionary(s) in all of the XML file in the specified directory. The "d", display, flag is supported.

The format of the XML files is described with the Import().

classmethod MatchLanguage(languages As %String, domain As %String = "", flag As %String = "") as %String
Get the best language match to a language in the list languages for the specified domain using HTTP 1.1 matching rules (RFC 2616). The list of languages is a comma separated list of RFC 1766 format language names. Each language in the list MAY be given an associated quality value which represents an estimate of the user's preference for the languages specified by the input list. The quality value defaults to "q=1". For example, "da, en-gb;q=0.8, en;q=0.7" would mean: "I prefer Danish, but will accept British English and other types of English." A language from the list matches a supported language tag if it exactly equals the tag, or if it exactly equals a prefix of the tag such that the first tag character following the prefix is "-". The special language "*", if present in the input list, matches every supported language not matched by any other language present in the list. The language quality factor assigned to a supported language tag by the is the quality value of the longest language in the list thatt matches the language-tag. The language that is returned is the supported language that has been assigned the highest quality factor. The "s", system flag, is an optional flag indicating whether system, "s", or application Message Dictionaries are to be matched.
classmethod SetSessionLanguage(language As %String) as %String
SetSessionLanguage sets the default session language for the messages in the Message Dictionary. The language argument is a RFC 1766 defined language tag. The return value is the previous default session language. In summary, a language tag is composed of 1 or more parts: A primary language tag optionally followed by a hyphen (-) separated secondary subtag. The Language string will be normalized to all lower case characters.

Inherited Members

Inherited Methods

FeedbackOpens in a new tab