JSF Localization Tags
About
LocaleMinder.com is designed to make localization as invisible as possible in the development lifecycle. Currently when localizing a file you will often end up with a file that is full of keys that refer to text in external files. For example:
file.xhtml:
<h:outputText value="#{messages['file.para1']}"/>
</p>
<p>
<h:outputText value="#{messages['file.para2']}"/>
</p>
messages_en.properties:
file.para1=Paragraph 1 to be localized. file.para2=Paragraph 2 to be localized.
LocaleMinder.com will process the properties files and return a copy for each language as required. The W3C ITS tag set improves on this further so that you cam embed the actual text into the file. Again LocaleMinder.com will process W3C ITS files and will return a copy for each language as required.
However to make localization simpler still we have created some JSF tags to complement the W3C ITS tag set which allow translations for multiple languages to be put into the same Facelets XHTML file with the relevant translation being chosen at runtime based on the users locale. Currently the selection of translation at runtime is only implemented for JBoss Seam . Support for other frameworks will be added over the coming months however the source code is available in the download if you wish to implement it yourself. If you do you can send us the implementation and we'll include it in future lm-tools releases.
Use
To use these tags the lm-tools.jar file must be included in your web application (/WEB-INF/lib). The lm-tools library and source can be downloaded from here . Then define the 'lm' and 'its' namespaces in your page (Facelets only) as follows:
xmlns:lm="http://www.localeminder.com/jsf/core"
xmlns:its="http://www.w3.org/2005/11/its">
Next you'll need to define some W3C ITS rules that specify that only 'lm' tags and selected tags embedded in 'lm' tags are translatable. Here is a suggested set of rules:
<its:translateRule translate="no" selector="//*"/>
<its:translateRule translate="yes" selector="//lm:forLanguage"/>
<its:translateRule translate="yes" selector="//lm:attrForLanguage/@value"/>
<its:translateRule translate="yes" selector="//lm:forLanguage//h:outputLink"/>
<its:translateRule translate="yes" selector="//lm:forLanguage//a"/>
<its:translateRule translate="yes" selector="//lm:forLanguage//b"/>
<its:withinTextRule withinText="yes" selector="//h:outputLink | //a | //b | //br"/>
</its:rules>
<lm:forLanguage>
The <lm:forLanguage> is used for localization of text nodes in XHTML (or XML) files. The attributes required are:
- id - Id for the text. Must be unique within the file.
For example to localize the text node of a '<h:outputText>' element:
<lm:forLanguage id="text1">
Sample text to be localized
</lm:forLanguage>
</h:outputText>
After processing of the file LocaleMinder.com will output the XHTML file with translations for required languages. For example:
<lm:forLanguage id="text1" xml:lang="en">
Sample text to be localized
</lm:forLanguage>
<lm:forLanguage id="text1" xml:lang="en_US">
Sample text to be localized
</lm:forLanguage>
<lm:forLanguage id="text1" xml:lang="en_GB">
Sample text to be localised
</lm:forLanguage>
<lm:forLanguage id="text1" xml:lang="zh">
示例文本進行本地化
</lm:forLanguage>
</h:outputText>
<lm:attrForLanguage>
The <lm:attrForLanguage> is used for localization of attributes of nodes in XHTML (or XML) files. The attributes required are:
- id - Id for the text. Must be unique within the file.
- attribute - The attribute to generate for the containing element.
- value - The value to output for the attribute.
For example to localize the 'value' attribute for a '<h:commandButton>' element:
<lm:attrForLanguage id="button_text1" attribute="value" value="Sample attribute to be localized"/>
</h:commandButton>
After processing of the file LocaleMinder.com will output the XHTML file with translations for required languages. For example:
<lm:attrForLanguage id="button_text1" xml:lang="en" attribute="value" value="Sample attribute to be localized"/>
<lm:attrForLanguage id="button_text1" xml:lang="en_US" attribute="value" value="Sample attribute to be localized"/>
<lm:attrForLanguage id="button_text1" xml:lang="en_GB" attribute="value" value="Sample attribute to be localised"/>
<lm:attrForLanguage id="button_text1" xml:lang="zh" attribute="value" value="樣本屬性來進行本地化"/>
</h:commandButton>
