I want to make a site multilingual.
I have an normal interceptor stack which contains
<interceptor-ref name="i18n" />
A common jsp for changing locale:
<s:a action="locale-manager" namespace="/common">
<s:param name="request_locale">fa_IR</s:param>
فارسی
</s:a>
<s:a action="locale-manager" namespace="/common">
<s:param name="request_locale">en_US</s:param>
English
</s:a>
And a simple LocaleManager action
public class LocaleManager extends ActionSupport{
private static final Logger log = LoggerFactory.getLogger(LocaleManager.class);
public String execute() {
log.debug("Change the local to {}", getLocale() );
return "homepage";
}
}
In the above scenario the i18n interceptor always run for all actions, which is not got solution. Because the locale only change when user clicks on locale-manager action.
I tried to remove the interceptor stack and add i18n interceptor only to LocaleManager as below
@InterceptorRefs({ @InterceptorRef("i18n") })
public class LocaleManager extends ActionSupport{
.........
But it did not worked ?! Am I missing something, or should I write my own interceptor ?
Always run
I18nInterceptor
interceptor for every Action... It is part of thedefaultStack
(configured in the struts-default.xml), it is there for a reason.It works in a simple way: if there is a request parameter named
request_locale
, it sets the new locale into session. That value will be then read when callinggetText()
or similar functions to get the proper message from the localized bundle.From the official documentation:
Some usage examples: