The framework supports internationalization (i18n) in two different places: the UI tags and the action/field error messages, including the Validation messages.
Resource Bundle Search Order
Wiki Markup |
---|
{snippet:id=searchorder|javadoc=true|url=com.opensymphony.xwork.util.LocalizedTextUtil} |
For more, see the LocalizedTextUtil class.
Tip |
---|
|
Wiki Markup |
---|
{snippet:id=packagenote|javadoc=true|url=com.opensymphony.xwork.util.LocalizedTextUtil} |
|
Examples
There are several ways to access the message resources, including getText
, the text
tag, and the i18n
tag.
Using getText
To display i18n text, use a call to getText
in the property tag, or any other tag, such as the UI tags. (The getText
technique is especially useful for labels of UI tags.)
Wiki Markup |
---|
{snippet:id=i18nExample|javadoc=true|lang=xml|url=org.apache.struts.action2.components.Property} |
Using the text
tag
The text tag retrieves a message from the default resource bundle.
Wiki Markup |
---|
{snippet:id=i18nExample|javadoc=true|lang=xml|url=org.apache.struts.action2.components.Text} |
Using the I18n
tag
The i18n tag pushes an arbitrary resource bundle on to the value stack. Other tags within the scope of the i18n tag can display messages from that resource bundle.
Wiki Markup |
---|
{snippet:id=i18nExample|javadoc=true|lang=xml|url=org.apache.struts.action2.components.I18n} |
Tip |
---|
| i18n with SiteMesh |
---|
| i18n with SiteMesh |
---|
|
Internationalizing SiteMesh decorators is possible, but there are quirks. See SiteMesh for more. |
I18n Interceptor
Essentially, the i18n Interceptor pushes a locale into the ActionContext map upon every request. The framework components that support localization all utilize the ActionContext locale. See I18n Interceptor for details.
Global Resources (struts.custom.i18n.resources) in struts.properties
Wiki Markup |
---|
{snippet:id=globalresource|javadoc=true|url=com.opensymphony.xwork.util.LocalizedTextUtil} |
Comparison with Strits 1
Wiki Markup |
---|
{snippet:id=strutscomparison|javadoc=true|url=com.opensymphony.xwork.util.LocalizedTextUtil} |