Tiles2 Struts 切换语言环境 [英] Tiles2 Struts Switch Locale

查看:11
本文介绍了Tiles2 Struts 切换语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 struts2 和 tiles2 的新手,我有一个应用程序,我使用 struts2 作为 mvc 框架,使用 tiles2 作为视图组件.在我的应用程序中,我使用 2 种语言英语和马拉地语,各自的语言环境是 en_US 和 mr_IN我有tiles.xml 和tiles_mr_IN.xml当我从浏览器切换语言环境时,代码工作正常但我想在英语和马拉地语之间切换,并且用户应该被重定向到具有相同请求参数的相同操作.我试过坐在 request_locale 参数,但它没有用.我可以发现,如果我可以在请求标头中切换语言环境或将语言环境从 struts2 传递到 tile lisner 或类似的东西请帮忙

I am newbee to struts2 and tiles2, I am having an application where i m using struts2 as mvc framework and tiles2 as a view component. In my application I am using 2 languages English and Marathi the respective locales are en_US and mr_IN I have tiles.xml and tiles_mr_IN.xml when i switch locale from browser the code works fine but i want to toggle between English and Marathi and the user should be redirected to same action with same request parameters. I have tried satting request_locale parameter but it didnt work. I could find that if i could switch locale in the request header or pass locale from struts2 to tiles lisner or some thing like that please help

推荐答案

这个问题应该可以用几个 s2 jsp 标签解决.

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

此链接显示了您需要的部分内容:http://struts.apache.org/2.0.14/docs/how-do-we-change-locales.html

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

它展示了如何使用 s2 url 添加一个参数,然后使用它来设置语言环境.

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

如果 i18n 拦截器中有一个名为request_locale"的参数,则会在用户代理语言首选项上使用该参数.

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

使示例更适合模板更改

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

<s:url includeParams="get">

注意动作名称已被省略,这将默认为当前动作(这是您的模板的理想选择)接下来 includeParams="get" 会将所有参数添加回 url,以便将它们传递到使用锚时的动作.includeParams 可能是none"、get"或all"(按照您的期望执行).有关 s2 url 标记的更多信息,请参阅:http://struts.apache.org/2.2.1.1/docs/url.html

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

进一步注意,s2 a 标签与 s2 url 标签共享大部分相同的功能,利用这一点将产生:

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>

这篇关于Tiles2 Struts 切换语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆