You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Xavier Vanderstukken <xv...@ionicsoft.com> on 2005/10/17 19:39:58 UTC
i18n, localeaction and actions
Hello,
All my site supports i18n mechanism correctly, using Struts LocaleAction
and bean taglib.
However when I try to access messageresource in my action the language
of the messageresource is allways the default one (in my case en_us).
System.out.println(request.getLocale());
if(request.getLocale()!=null)
System.out.println(request.getLocale().getLanguage());
MessageResources
lang=(MessageResources)request.getSession().getAttribute(Globals.MESSAGE_KEY);
--> Output :
en_US
en
and : System.out.println(lang.getMessage("mail.title")); output english
message instead of current locale one.
Am I doing something wrong to read the messageresource in the action
classes, because i18n works correctly in my jsp pages?
Is it due to the use of the Struts LocaleAction?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: i18n, localeaction and actions
Posted by Xavier Vanderstukken <xv...@ionicsoft.com>.
Im ade a mistake in my previous message the correct code is :
System.out.println(request.getLocale());
if(request.getLocale()!=null)
System.out.println(request.getLocale().getLanguage());
MessageResources lang=this.getResources(request); //instead of
MessageResources
lang=(MessageResources)request.getSession().getAttribute(Globals.MESSAGE_KEY);
I have a look at struts action code and methods
protected MessageResources getResources(HttpServletRequest request)
and
protected MessageResources getResources( HttpServletRequest request,
String key) {
are very different :
The first one returns : return ((MessageResources)
request.getAttribute(Globals.MESSAGES_KEY));
and the second one do :
protected MessageResources getResources(
HttpServletRequest request,
String key) {
// Identify the current module
ServletContext context = getServlet().getServletContext();
ModuleConfig moduleConfig =
ModuleUtils.getInstance().getModuleConfig(request, context);
// Return the requested message resources instance
return (MessageResources) context.getAttribute(
key + moduleConfig.getPrefix());
}
Xavier Vanderstukken wrote:
> Hello,
>
> All my site supports i18n mechanism correctly, using Struts
> LocaleAction and bean taglib.
> However when I try to access messageresource in my action the language
> of the messageresource is allways the default one (in my case en_us).
>
>
> System.out.println(request.getLocale());
> if(request.getLocale()!=null)
> System.out.println(request.getLocale().getLanguage());
> MessageResources
> lang=(MessageResources)request.getSession().getAttribute(Globals.MESSAGE_KEY);
>
>
> --> Output :
> en_US
> en
>
> and : System.out.println(lang.getMessage("mail.title")); output
> english message instead of current locale one.
>
> Am I doing something wrong to read the messageresource in the action
> classes, because i18n works correctly in my jsp pages?
> Is it due to the use of the Struts LocaleAction?
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org