Specifying Locale- and browser-dependent URL
ZK can handle this for you automatically by specifying a URL with asterisk
*. This feature is supported by all components that accept a URL, e.g. the src of <script> or <?script?>. The algorithm is as follows.
Absolute Path Only
You can only specify an absolute path to load a locale-dependent resource. Relative path is not supported.
One "*" for Locale Code
If you specify only one
* in a URL, such as
* will be replaced with a locale code depending on the current locale that ZK detects. For example:
- User's preferences (current locale):
Then ZK looks for files in the order below one-by-one in your web site until any of them is found:
Two "*" for Locale and Browser Code
Such as "/my*/lang*.css", then the first "*" will be replaced with a browser code as follows:
iefor Internet Explorer
saffor Chrome, Safari
mozfor firefox and other browsers.
Moreover, the last asterisk will be replaced with a proper Locale as described in the previous rule. In summary, the last asterisk represents the Locale, while the first asterisk represents the browser type.
<style src="/i18n/css-*/mycss*.css" />
The result in an HTML with Chrome:
<link ... href="/i18n/css-saf/mycss.css" ...>
All other "*" are ignored
The last 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 a 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.
- ↑ In the future editions, we will use different codes for browsers other than Internet Explorer, Firefox and Safari.
In the following example, we assume the preferred Locale is
de_DE and the browser is Internet Explorer.
Locating Locale- and browser-dependent resources in Java
In addition to ZUML, you can also load browser- and Locale-dependent resources in Java. Here is a list of methods that you can use.
includemethods in Execution for encoding URL, forwarding to another page and including a page. In most cases, these methods are all you need.
includemethod in Servlets for locating Web resouces. You rarely need them when developing ZK applications, but useful for writing a servlet, portlet or filter.
encodeURLmethod in Encodes for encoding URL. You rarely need them when developing ZK applications, but useful for writing a Servlet, Portlet or Filter.
locatemethod in Locators for locating class resources.