1. opensymphony
  2. webwork


webwork / docs / wikidocs / Internationalization.html

        <title>WebWork 2 : Internationalization</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    

	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            WebWork 2 : Internationalization
				    <div class="pagesubheading">
					    This page last changed on Jun 18, 2004 by <font color="#0050B2">plightbo</font>.

				    <p class="paragraph">WebWork supports internationalization (in short, i18n) in two different places: the UI tags and the action/field error messages.</p><ul type="square" class="minus">
<li> <a href="UI Tags.html" title="UI Tags">UI Tags</a></li>
<li> <a href="Validation Examples.html" title="Validation Examples">Validation Examples</a></li>
Resource bundles are searched in the following order:<br/>

<ul class="star">
<li> ActionClass.properties</li>
<li> BaseClass.properties (all the way to Object.properties)</li>
<li> Interface.properties (every interface and sub-interface)</li>
<li> package.properties (every of every base class, all the way to java/lang/package.properties)</li>
To display i18n text, you can use a call to getText() in the property tag, or any other tag such as the UI tags (this is especially useful for labels of UI tags):<br/>

<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;ww:property value=<span class="xml&#45;quote">&quot;getText(&#039;some.key&#039;)&quot;</span>/&gt;</span></pre>
</div></div><p class="paragraph">You may also use the text tag:</p><div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;ww:text name=<span class="xml&#45;quote">&quot;&#039;some.key&#039;&quot;</span>/&gt;</span></pre>
</div></div><p class="paragraph">Also, note that there is an i18n tag that will push a resource bundle on to the stack, allowing you to display text that would otherwise not be part of the resource bundle search hierarchy mentioned previously.</p><div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;ww:i18n name=<span class="xml&#45;quote">&quot;some/package/bundle&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;ww:text name=<span class="xml&#45;quote">&quot;&#039;some.key&#039;&quot;</span>/&gt;</span>&#10;<span class="xml&#45;tag">&lt;/ww:i18n&gt;</span></pre>
</div></div><p class="paragraph"><h2 class="heading2"><a name="Internationalization-Usingamasterapplicationcatalog"> Using a master application catalog</a></h2></p>Struts users should be familiar with the application.properties resource bundle, where you can put all the messages in the application that are going to be translated. WebWork2, though, splits the resource bundles per action or model class, and you may end up with duplicated messages in those resource bundles. A quick fix for that is to create a file called ActionSupport.properties in com/opensymphony/xwork and put it on your classpath. This will only work well if all your actions subclass ActionSupport.<p class="paragraph">If this is not the case, another solution is to create a ServletContextListener and have it call LocalizedTextUtil.addDefaultResourceBundle(String resourceBundleName). You can also use a Servlet that&#039;s initialized on startup to do that.</p>

	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			    <td align="center"><font color="grey">Document generated by Confluence on Oct 15, 2004 02:03</font></td>