Portlet Locale & Internationalization
llengcai Jun 7, 2010 12:14 PMI am trying to get the portlet to display the correct value from the resource bundle by setting the following (as per portlet jsr 168 spec) values in the portlet.xml and deployed it in GateIn 3.0.0-GA
<supported-locale>en</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>zh</supported-locale>
<resource-bundle>locale.portlet.gadget.GadgetPortlet</resource-bundle>
one the of the jsp file contains the following taglib
<fmt:setBundle basename="locale.portlet.gadget.GadgetPortlet"/>
<fmt:message key="total.summary" />
What I would expect is, once the use choose the language from the "Change Language" link on the top right of the portal page, the jsp will display the value of "total.summary" to the selected language. Unfortunately it doesn't work.
After some digging around and tracing, I notice the PortletRequest.getLocale() eventually delegated the call to org.exoplatform.portal.webui.application.ExoUserContext.getLocale():
public Locale getLocale() {
return clientRequest != null ? clientRequest.getLocale()
: Locale.ENGLISH;
}
The clientRequest is the servlet request object from the catalina container. My guess is this servlet request object will just grep the locale value from the Accept-Language http request header sent by the browser. The Accept-Language header value doesn't seems to have any corelation with the "Change Language" action which actually update the locale setting in the portal by calling the
org.exoplatform.portal.webui.workspace.UIPortalApplication.UIPortalApplication.setLocale()
I am able to get the above scenario work if I replace the org.exoplatform.portal.webui.application.ExoUserContext.getLocale() method above with
public Locale getLocale() {
PortalRequestContext context = PortalRequestContext.getCurrentInstance();
if(context != null) {
UIPortalApplication uiPortalApplication = (UIPortalApplication) context.getUIApplication();
Locale locale = uiPortalApplication.getLocale();
if (locale != null) return locale;
}
return clientRequest != null ? clientRequest.getLocale()
: Locale.ENGLISH;
}
Can anyone, especially the core developers here verify if this is the correctly way of fixing the issue I stated above, assuming our intention is to read the locale based on the Change Language settings rather than browser's Accept-Language http header?