Tiles2 Struts Switch Locale

I am new to struts2 and tiles2, I have an application where I use struts2 as mvc framework and tiles2 as a component of the view. In my application, I use 2 languages ​​English and Marathi, the corresponding locales en_US and mr_IN I have tiles.xml and tiles_mr_IN.xml when I switch the language from the browser, the code works fine but I want to switch between English and Marathi and the user needs to be redirected on one action with the same request parameters. I tried the satting request_locale parameter, but it did not work. I could find that if I could switch the locale in the request header or pass the locale from struts2 to lisner tile or something like that please help

0
source share
1 answer

This issue should be resolved with a pair of 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

This shows how to take the s2 url, add a parameter, and then use it to set the locale.

If the i18n interceptor has a parameter called "request_locale", it will use it according to the language preferences of user agents.

To make the example more suitable for changing the template

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

to

 <s:url includeParams="get"> 

Please note that the action name was omitted, this will be the default current action (which is perfect for your template). next includeParams = "get" will add all parameters back to the URL so that they are passed in when you use the anchor. In includeParams can be "no", "receive" or "all" (do what you expect). For more information on the url s2 tag see: http://struts.apache.org/2.2.1.1/docs/url.html

Note that the s2 tag tags have much of the same functionality as the s2 url tag that uses this:

 <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> 
+1
source

Source: https://habr.com/ru/post/1336864/


All Articles