Labels"

From Documentation
m
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
Developers could separate Locale-dependent data from the ZUML pages (and JSP pages) by storing them in i3-label_''lang''_''CNTY''.properties under the <tt>WEB-INF</tt> directory, where ''lang'' is the language such as en and fr, and ''CNTY'' is the country, such as US and FR.
+
= Overview =
 +
 
 +
For a multilingual application, it is common to display the content in the language that the end user prefers. With EL, it is easy to display the right language by use of any static method an application provides.
 +
 
 +
To simplify the task, ZK provides a utility to retrieve Locale-dependent strings easily. For historical reason, it is called <code>i3-label</code>.
 +
 
 +
==i3-label==
 +
 
 +
ZK provides a utility to retrieve Locale-dependent strings easily.
 +
 
 +
First, you shall put Locale-dependent content into files under the <tt>WEB-INF</tt> directory, and one file per locale. The file shall be named as <code>i3-label_''lang''_''CNTY''.properties</code>, where ''lang'' is the language such as en and fr, and ''CNTY'' is the country, such as US and FR. If you want to use one file to represent a language regardless the country, you could name it <code>i3-label_''lang''.properties</code>, such as <code>i3-label_ja.properties</code>. Furthermore, <code>i3-label.properties</code> is the default file if the user's preferred locale doesn't match any other file.
  
 
To get a Locale-dependent property, you could use <javadoc>org.zkoss.util.resource.Labels</javadoc> in Java, or <tt>${c:l('key')}</tt> in EL expression. To use it in EL, you have to specify the TLD file with the <tt>taglib</tt> directive in your page as follows.
 
To get a Locale-dependent property, you could use <javadoc>org.zkoss.util.resource.Labels</javadoc> in Java, or <tt>${c:l('key')}</tt> in EL expression. To use it in EL, you have to specify the TLD file with the <tt>taglib</tt> directive in your page as follows.

Revision as of 01:59, 12 October 2010

Overview

For a multilingual application, it is common to display the content in the language that the end user prefers. With EL, it is easy to display the right language by use of any static method an application provides.

To simplify the task, ZK provides a utility to retrieve Locale-dependent strings easily. For historical reason, it is called i3-label.

i3-label

ZK provides a utility to retrieve Locale-dependent strings easily.

First, you shall put Locale-dependent content into files under the WEB-INF directory, and one file per locale. The file shall be named as i3-label_lang_CNTY.properties, where lang is the language such as en and fr, and CNTY is the country, such as US and FR. If you want to use one file to represent a language regardless the country, you could name it i3-label_lang.properties, such as i3-label_ja.properties. Furthermore, i3-label.properties is the default file if the user's preferred locale doesn't match any other file.

To get a Locale-dependent property, you could use Labels in Java, or ${c:l('key')} in EL expression. To use it in EL, you have to specify the TLD file with the taglib directive in your page as follows.

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>

<window title="${c:l('app.title')}">
 ...
</window>

When a Locale-dependent label is about to retrieved, one of i3-label_lang_CNTY.properties will be loaded. For example, if the Locale is de_DE, then WEB-INF/i3-label_de_DE.properties will be loaded. If no such file, ZK will try to load WEB-INF/i3-label_de.properties and WEB-INF/i3-label.properties in turn.[1]

To access labels in Java codes (including zscript), use the getLabel method of the Labels class.

In addition, you could extend the label loader to load labels from other locations, say database, by registering a locator, which must implement the LabelLocator interface. Then, invoke the register method of the Labels class.

Notes

  1. For performance issue, the look up sequence for English is different: First:i3-label_en_US.properties, Second:i3-label.properties, Third:i3-label_en.properties

Version History

Last Update : 2010/10/12

Version Date Content
     



Last Update : 2010/10/12

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.