Tiles2 Struts Switch Locale

大城市里の小女人 提交于 2019-11-29 18:08:11

This issue should be resolvable with a couple s2 jsp tags.

This link shows part of what you need: http://struts.apache.org/2.0.14/docs/how-do-we-change-locales.html

That is it shows how to take a s2 url add a parameter and then use that to set the locale.

If there is a parameter called "request_locale" coming in the i18n interceptor will use that over the user agents language preference.

To make the example better suited for a template change

<s:url id="en" action="Welcome">

to

<s:url includeParams="get">

Notice the action name has been omitted, this will default to the current action (which is ideal for your template) next the includeParams="get" will add all the parameters back into the url so they'll be passed into the action when you use the anchor. The includeParams may be "none", "get" or "all" (doing what you would expect). For more information on the s2 url tag see: http://struts.apache.org/2.2.1.1/docs/url.html

Further note that the s2 a tag shares most of the same funcationality as the s2 url tag taking advantage of this will produce:

<s:a includeParams="get">
  <s:param name="request_locale" value="en_US"/>
  English
</s:a>
&nbsp;
<s:a includeParams="get">
  <s:param name="request_locale" value="mr_IN"/>
  Marathi
</s:a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!