Reputation: 49
Is it possible to apply Struts 2 internationalization (i18n) for changing language from English to Hindi on all web pages of the website by a single click?
If it is possible, then how can I resolve this problem?
Upvotes: 0
Views: 471
Reputation: 45583
As mentioned by @RomanC , it is possible to do that, you need to have the i18n
interceptor in your package.
After that you need your JSP page to submit
a form with request_locale
in it, or call an action with request_locale
in its parameters . For example, if you want to do it with select
you can use below:
<s:form id="langselect" action="locale-manager" namespace="/common">
<s:select name="request_locale" headerKey="-1"
headerValue="Language"
list="#{'en_US':'English', 'fa_IR':'فارسی','ar_SA':'العربية','zh_CN':'中国的'}"
onchange="forms['langselect'].submit()" />
</s:form>
Your form action needs nothing to do with changing the locale at all, as the interceptor will do all the job for you.
Changing the locale will change all your 20 pages at once, of course, as soon as you reload your pages.
So if you want to do it with tab
, you need to reload your new pages (for example with ajax) or reload your total site to get localized JSP from Struts.
Upvotes: 0
Reputation: 1
The framework is internationalized.
You need to add the corresponding to each locale resource bundles for the localized messages that you display via the struts tags. Use
text
tag orgetText()
to retrieve a message in the UI.The browser language is passed with the HTTP request and framework create a locale corresponding to the browser settings. Switching locale performed via passing a special parameter
request_locale
toi18n
interceptor that should be on your stack.You can also configure this interceptor to accept user-defined parameters.
Normally switching to a locale persist for the session of the user. So, you don't have to pass a parameter each time on every request, but this case is also supported if needed. See how could you achieve all of the above using localization.
Upvotes: 1