-
FEATURED COMPONENTS
First time here? Check out the FAQ!
- I have followed the instruction (Chapter 14 - http://www.zkoss.org/doc/devguide/ch14.html) regarding how to switch user language.
- I have made all the steps required.
- There are 2 properties files with messages in russian and english.
i3-label.properties
locale=Locale
i3-label_ru_RU.properties
locale=Языковой код
- I am setting a user preferred language in the struts action like it described in manual
Locale preferredLocale = org.zkoss.util.Locales.getLocale("ru_RU");
session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
- But It does not make any impact on output
<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix = "zc"%>
...
<z:label id="localeLabel" value="${zc:l('locale')}"/>
...
- Value of label localeLabel is desplayed in English no matter what.
- But if I put some code in zkscript that I can manually change its value
<zkscript>
void changeLocale()
{
preferredLocale = org.zkoss.util.Locales.getLocale(localeName);
session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
String x=org.zkoss.util.resource.Labels.getLabel("locale");
localeLabel.setValue(x+" "+org.zkoss.util.Locales.getCurrent()+" ");
}
</zkscript>
Please refer to this demo.
@dennis.
Hello dennis i need your help to setCurrent locale to English or to Italy using the label click event in zk. Actually i am working with a application in which i had to work on two main languages English and Italy.
Can you help me to. that how to specify the locale attribute or get locale when user select the language as a label available.
Best Regards
Yogendra
Thank you, Dennis, You really helped me
It seems the first solution worked.
In the long run, You are also right about solution 2. It is better to have some filter intercepting all requests and setting a proper locale before letting response come back to client. Filter will check some parameter in session and set locale as a tread local variable.
This is my portal: www.trade4stas.com
On the top right corner there are two flags. Each of them is to select a language. Once language is selected it should be effective during the life of the session unless user changes it.
I wish ZK supported a feature to read locale setting directly from the session like it was documented.
session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
One more time, thank you for the good advice.
another solution is better. Writing a listener for .jsp to do the thing the ZK does (for work around)
1.get Locale attribute form seesion.
2.set locale by Locales.setThreadLocal.
and also post a feature to JSP tags to make ZK JSP Tag better.
Hi, Do you use JSP Tag? the document and example are for ZUL,
Currently, there is no ZK handler to intercept JSP to set the Locale.
Maybe the JSP Tag-page should handle this, but for now, you could use Locales.setThreadLocal to work around.
following example works for me.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="zc"%> <%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="zk"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Locale</title> </head> <body> <zk:page> <zk:zscript> org.zkoss.util.Locales.setThreadLocal(org.zkoss.util.Locales.getLocale("ru_RU")); </zk:zscript> <zk:label id="localeLabel1"> <zk:attribute name="value">ru_RU: ${zc:l("locale")}</zk:attribute> </zk:label> <br/> <zk:zscript> org.zkoss.util.Locales.setThreadLocal(org.zkoss.util.Locales.getLocale("en_US")); </zk:zscript> <zk:label id="localeLabel2"> <zk:attribute name="value">en_US: ${zc:l("locale")}</zk:attribute> </zk:label> </zk:page> </body> </html>
/Dennis
Asked: 2008-12-05 04:24:24 +0800
Seen: 1,156 times
Last updated: Mar 18 '11