Locale-Dependent Resources"

From Documentation
Line 4: Line 4:
 
Many resources depend on the Locale and, sometimes, the browser. For example, you might need to use a larger font for Chinese characters to have better readability.
 
Many resources depend on the Locale and, sometimes, the browser. For example, you might need to use a larger font for Chinese characters to have better readability.
  
ZK can handle this for you automatically, if you specify the URL of the style sheet with "*". The algorithm is as follows.
+
=Specifying Locale- and browser-dependent URL=
 +
 
 +
ZK can handle this for you automatically, if you specify the URL with "*". The algorithm is as follows.
  
 
# If there is one "*" is specified in an URI such as <tt>/my*.css</tt>, then "*" will be replaced with a proper Locale depending on the preferences of user's browser.For example, user's preferences is <tt>de_DE</tt>, then ZK searches <tt>/my_de_DE.css</tt>, <tt>/my_de.css</tt>, and <tt>/my.css</tt> one-by-one from your Web site, until any of them is found. If none of them is found, <tt>/my.css </tt>is still used.
 
# If there is one "*" is specified in an URI such as <tt>/my*.css</tt>, then "*" will be replaced with a proper Locale depending on the preferences of user's browser.For example, user's preferences is <tt>de_DE</tt>, then ZK searches <tt>/my_de_DE.css</tt>, <tt>/my_de.css</tt>, and <tt>/my.css</tt> one-by-one from your Web site, until any of them is found. If none of them is found, <tt>/my.css </tt>is still used.
Line 18: Line 20:
 
'''Tip''': We can apply this rule to specify an URI depending on the browser type, but not depending on the Locale. For example, "/my/lang*.css*" will be replaced with "/my/langie.css" if Internet Explorer is the current user's browser.
 
'''Tip''': We can apply this rule to specify an URI depending on the browser type, but not depending on the Locale. For example, "/my/lang*.css*" will be replaced with "/my/langie.css" if Internet Explorer is the current user's browser.
  
'''Notes'''
+
<blockquote>
 +
----
 
<references/>
 
<references/>
 +
</blockquote>
  
 
+
==Example==
 
In the following examples, we assume the preferred Locale is <tt>de_DE</tt> and the browser is Internet Explorer.
 
In the following examples, we assume the preferred Locale is <tt>de_DE</tt> and the browser is Internet Explorer.
  
Line 73: Line 77:
 
|}
 
|}
  
=== Locating Browser and Locale Dependent Resources in Java ===
+
= Locating Locale- and browser-dependent resources in Java =
In additions to component attributes and ZUML attributes, you could handle browser and Locale dependent resource programmingly in Java. Here are a list of methods that you could use.
+
 
 +
In additions to ZUML<ref>It is also supported by all components that accept an URL.</ref>, you could handle browser- and Locale-dependent resource in Java. Here are a list of methods that you could use.
  
 
* The <tt>encodeURL</tt>, <tt>forward</tt>, and <tt>include</tt> methods in <javadoc>org.zkoss.zk.ui.Execution</javadoc> for encoding URL, forwarding to another page and including a page. In most cases, these methods are all you need.
 
* The <tt>encodeURL</tt>, <tt>forward</tt>, and <tt>include</tt> methods in <javadoc>org.zkoss.zk.ui.Execution</javadoc> for encoding URL, forwarding to another page and including a page. In most cases, these methods are all you need.
 
* The <tt>locate</tt>, <tt>forward</tt>, and <tt>include</tt> method in <javadoc>org.zkoss.web.servlet.Servlets</javadoc> for locating Web resouces. You rarely need them when developing ZK applications, but useful for writing a servlet, portlet or filter.
 
* The <tt>locate</tt>, <tt>forward</tt>, and <tt>include</tt> method in <javadoc>org.zkoss.web.servlet.Servlets</javadoc> for locating Web resouces. You rarely need them when developing ZK applications, but useful for writing a servlet, portlet or filter.
* The <tt>encodeURL</tt> method in <javadoc>org.zkoss.web.servlet.http.Encodes</javadoc> for encoding URL. You rarely need them when developing ZK applications, but useful for writing a servlet, portlet or filter.
+
* The <tt>encodeURL</tt> method in <javadoc>org.zkoss.web.servlet.http.Encodes</javadoc> for encoding URL. You rarely need them when developing ZK applications, but useful for writing a Servlet, Portlet or Filter.
  
 
* The <tt>locate</tt> method in <javadoc>org.zkoss.util.resource.Locators</javadoc> for locating class resources.
 
* The <tt>locate</tt> method in <javadoc>org.zkoss.util.resource.Locators</javadoc> for locating class resources.
 +
 +
<blockquote>
 +
----
 +
<references/>
 +
</blockquote>
  
 
=Version History=
 
=Version History=

Revision as of 06:31, 12 October 2010


Locale-Dependent Resources


Overview

Many resources depend on the Locale and, sometimes, the browser. For example, you might need to use a larger font for Chinese characters to have better readability.

Specifying Locale- and browser-dependent URL

ZK can handle this for you automatically, if you specify the URL with "*". The algorithm is as follows.

  1. If there is one "*" is specified in an URI such as /my*.css, then "*" will be replaced with a proper Locale depending on the preferences of user's browser.For example, user's preferences is de_DE, then ZK searches /my_de_DE.css, /my_de.css, and /my.css one-by-one from your Web site, until any of them is found. If none of them is found, /my.css is still used.
  2. If two or more "*" are specified in an URI such as "/my*/lang*.css", then the first "*" will be replaced with "ie" for Internet Explorer, "saf" for Safari, and "moz" for other browsers[1]. Moreover, the last asterisk will be replaced with a proper Locale as described in the above step.In summary, the last asterisk represents the Locale, while the first asterisk represents the browser type.
  3. All other "*" are ignored.

Note: The lat asterisk that represents the Locale must be placed right before the first dot ("."), or at the end if no dot at all. Furthermore, no following slash (/) is allowed, i.e., it must be part of the filename, rather than a directory. If the last asterisk doesn't fulfill this constraint, it will be eliminated (not ignored).

For example, "/my/lang.css*" is equivalent to "/my/lang.css".

In other words, you can consider it as neutral to the Locale.

Tip: We can apply this rule to specify an URI depending on the browser type, but not depending on the Locale. For example, "/my/lang*.css*" will be replaced with "/my/langie.css" if Internet Explorer is the current user's browser.


  1. In the future editions, we will use different codes for browsers other than Internet Explorer, Firefox and Safari.

Example

In the following examples, we assume the preferred Locale is de_DE and the browser is Internet Explorer.


URI
Resources that are searched
/css/norm*.css # /norm_de_DE.css
  1. /norm_de.css
  2. /norm.css


/css-*/norm*.css # /css-ie/norm_de_DE.css
  1. /css-ie/norm_de.css
  2. /css-ie/norm.css


/img*/pic*/lang*.png # /imgie/pic*/lang_de_DE.png
  1. /imgie/pic*/lang_de.png
  2. /imgie/pic*/lang.png


/img*/lang.gif # /img/lang.gif


/img/lang*.gif* # /img/langie.gif


/img*/lang*.gif* # /imgie/lang*.gif


Locating Locale- and browser-dependent resources in Java

In additions to ZUML[1], you could handle browser- and Locale-dependent resource in Java. Here are a list of methods that you could use.

  • The encodeURL, forward, and include methods in Execution for encoding URL, forwarding to another page and including a page. In most cases, these methods are all you need.
  • The locate, forward, and include method in Servlets for locating Web resouces. You rarely need them when developing ZK applications, but useful for writing a servlet, portlet or filter.
  • The encodeURL method in Encodes for encoding URL. You rarely need them when developing ZK applications, but useful for writing a Servlet, Portlet or Filter.
  • The locate method in Locators for locating class resources.

  1. It is also supported by all components that accept an URL.

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.