HiveMind Localization |
Every HiveMind module may have its own set of messages. Messages are stored alongside the module deployment descriptor, as META-INF/hivemodule.properties (within the module's JAR).
Services can gain access to localized messages, as an instance of Messages , which includes methods for accessing messages and formatting messages with arguments.
In a module descriptor, within the <contribution> and <invoke-factory> elements, you can reference a localized message in an attribute or element content simply by prefixing the message key with '%'. Examples:
<contribution configuration-id=...> <some-item <message="%message.key"> %other.message.key </some-item> </contribution>
The two keys (message.key and other.message.key ) are searched for in the contributing module's messages.
HiveMind gracefully recovers from undefined messages. If a message is not in the properties file, then HiveMind provides a substitute value by converting the key to upper-case and adding brackets, i.e. [MESSAGE.KEY]. This allows your application to continue running, but clearly identifies missing messages.
By adding additional files, message localization can be accomplished. For example, adding a second file, META-INF/hivemodule_fr.properties would provide French language localizations. Any common keys between the two files defer to the more specific file.
Setting the locale
When a Registry is created by the RegistryBuilder, a locale is specified. This is the locale for the Registry and, by extension, for all Modules in the registry. The locale may not be changed.