-
Notifications
You must be signed in to change notification settings - Fork 77
Localiztion
The normal model of Java is used throughout OpenELIS. The resource files are MessageRessources.properties, with the standard variations for each language.
We have added some convenience methods in us.mn.state.health.lims.common.util.StringUtil.
getMessageForKey(....) and getContextualMessageForKey(.....)
These methods will return the correct string for the current locale. getContextualMessageForKey was added to support the same label having different wording at different labs. For instance one lab may call an accession number "Accession Number" while a different lab may use the term "Lab. No." They are two different names for the same concept. This worked by post-pending the key with a lab specific identifier. We are moving away from using contextual keys because they are not maintainable at any scale, but you will still see them in the code.
#Localization of database values
The problem being solved is that values from the database are often displayed to the user as a list and even though the language on the page changes, the language for the list doesn't. There are five steps to add the localization.
-
Add a new column to the table for a MessageResource key
The recommended method is to use liquidbase files. But if you must:
ALTER TABLE clinlims.panel ADD COLUMN display_key varchar(60);
-
Override getDefaultLocalizedName() in the java object mapped to the table
The actual code for handling the localization is in BaseObject.java. However if the key in the table is null or not found in MessageResources then something has to be displayed to the user. Each derived class supporting database localization should override this method. If not then unknown will be displayed.
-
Add the mapping to the hibernate mapping file
The following should be added to the hibernate mapping file
<property name="nameKey" type="java.lang.String"> <column name="display_key" length="60" not-null="false" /> </property>
-
Add the localized text to the MessageResource files.
Just do it
-
Consuming code should use getLocalizedName()