Theme:
Processing...
Description & Source Code
  • Description
  • XML & Java Source
    multilingual.zul
    multilingual_ctrl.zul
    i3-label.properties
    i3-label_fr.properties
    i3-label_de.properties
    i3-label_hi.properties
    i3-label_it.properties
    i3-label_ja.properties
    i3-label_pt.properties
    i3-label_zh_CN.properties
    i3-label_es.properties
    i3-label_zh_TW.properties

Multilingual texts are supported. A viewer sees texts in ZK components as it is defined in his/her browser's preferred language setting.

Multilingual support is achieved with the EL function "l" (language) in taglib, meaning label. Labels are defined in the WEB-INF/i3-label(_*).properties in the war file; developers should specify the following line in the ZUL file to retrieve the text

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
The expression ${labels.password}, ${c:l('key')}, and Labels.getLabel("key") would retrieve the keyed label based on the browser's preferred language setting.The languages supported in this demo as following:
  • English
  • French
  • German
  • Hindi
  • Italian
  • Japanese
  • Portuguese
  • Simplified Chinese
  • Spanish
  • Traditional Chinese

More details in ZK Developer's Reference - Internationalization

multilingual.zul
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<zk>
	<zscript><![CDATA[
		String number = "10";
	]]></zscript>
	<grid id="demoGrid" width="300px">
		<rows>
			<row>
				<!-- Using The Tag Lib -->
				${c:l('username')}<textbox hflex="1"/>
			</row>
			<row>
				<!-- Using EL implicit object labels -->
				*${labels.password} 1 <textbox type="password" hflex="1"/>
			</row>
			<row>
				<!-- Using The Java Way -->
				<label id="pwd" /><textbox type="password" hflex="1"/>
			</row>
		</rows>
		<foot>
			<!-- Properties can get the variable in the page -->
			<footer style="text-align:right;" span="2"><label value="${c:l('message')}" /></footer>
		</foot> 
	</grid>
	<zscript><![CDATA[	                  
		import org.zkoss.util.resource.Labels; //Labels utility included the international functionality 
		pwd.setValue("*" + Labels.getLabel("password") + " 2" );
	]]></zscript>
</zk>
multilingual_ctrl.zul
<zk>
	<groupbox closable="false" sclass="z-demo-config">
		<caption>Locale (Refresh Page)</caption>
		By Alphabet :
		<radiogroup id="rg">
			<attribute name="onCheck"><![CDATA[
				String localeValue = self.getSelectedItem().getValue();
				Locale prefer_locale = localeValue.length() > 2 ? 
						new Locale(localeValue.substring(0,2),localeValue.substring(3)) : new Locale(localeValue);
				session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, prefer_locale);
				session.setAttribute("Demo_Locale", self.getSelectedIndex());
				execution.sendRedirect("");
			]]></attribute>
			<vlayout>
				<radio label="English" value="en"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'en_US' || c:getCurrentLocale() == 'en_GB' }" />
				<radio label="French" value="fr"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'fr_FR' }" />
				<radio label="German" value="de"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'de_DE' }" />
				<radio label="Hindi" value="hi"
					checked="${c:getCurrentLocale() == self.value}" />
				<radio label="Italian" value="it"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'it_IT' }" />
				<radio label="Japanese" value="ja"
					checked="${c:getCurrentLocale() == self.value }" />
				<radio label="Portuguese" value="pt"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'pt_BR' }" />
				<radio label="Simplified Chinese" value="zh_CN"
					checked="${c:getCurrentLocale() == self.value}" />
				<radio label="Spanish" value="es"
					checked="${c:getCurrentLocale() == self.value || c:getCurrentLocale() == 'es_ES' }" />
				<radio label="Traditional Chinese" value="zh_TW"
					checked="${c:getCurrentLocale() == self.value}" />
			</vlayout>
		</radiogroup>
		<zscript><![CDATA[
			if (session.getAttribute("Demo_Locale") != null)
				rg.setSelectedIndex(Integer.parseInt(session.getAttribute("Demo_Locale").toString()));
		]]></zscript>
	</groupbox>
</zk>
i3-label.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Username
password=Password
message=Available Language : ${number}
i3-label_fr.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Nom d'utilisateur
password=Mot de passe
message=Langue disponible : ${number}
i3-label_de.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Benutzername
password=Passwort
message=Verfügbaren Sprachen : ${number}
i3-label_hi.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=उपयोगकर्ता नाम
password=पासवर्ड
message=भाषा उपलब्ध : ${number}
i3-label_it.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Nome utente
password=Parola d'ordine
message=Lingua disponibile : ${number}
i3-label_ja.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=ユーザー名
password=パスワード
message=利用可能な言語 : ${number}
i3-label_pt.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Nome de usuário
password=Senha
message=Língua disponível : ${number}
i3-label_zh_CN.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=用户
password=密码
message=可用语系数量 : ${number}
i3-label_es.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=Nombre de usuario
password=Contraseña
message=Disponible el lenguaje : ${number}
i3-label_zh_TW.properties
#--------------------#
# Label for zkdemo #
#--------------------#

username=用戶
password=密碼
message=可用語系數量 : ${number}