Locale-Dependent Resources"
Line 26: | Line 26: | ||
* <tt>moz</tt> for firefox and other browsers<ref>In the future editions, we will use different codes for browsers other than Internet Explorer, Firefox and Safari.</ref>. | * <tt>moz</tt> for firefox and other browsers<ref>In the future editions, we will use different codes for browsers other than Internet Explorer, Firefox and Safari.</ref>. | ||
− | 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. | + | 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. |
+ | |||
+ | For example: | ||
+ | |||
+ | '''zul''' | ||
+ | <source lang='xml'> | ||
+ | <style src="/i18n/css-*/mycss*.css" /> | ||
+ | </source> | ||
+ | |||
+ | |||
+ | The result in an HTML with Chrome: | ||
+ | <source lang='html'> | ||
+ | <link ... href="/i18n/css-saf/mycss.css" ...> | ||
+ | </source> | ||
== All other "*" are ignored == | == All other "*" are ignored == |
Revision as of 07:11, 31 March 2021
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 asterisk *. The algorithm is as follows.
One "*" is specified in an URI
Such as /my*.css, then "*" will be replaced with a proper locale code depending on the preferences of user's browser. For example:
- URI: /my*.css
- User's preferences: de_DE
Then ZK look for files in the order below one-by-one in your web site until any of them is found.:
- /my_de_DE.css
- /my_de.css
- /my.css
Two or more "*" are specified in a URI
Such as "/my*/lang*.css", then the first "*" will be replaced with a browser code as follows:
- ie for Internet Explorer
- saf for Chrome, Safari
- moz for firefox and other browsers[1].
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.
For example:
zul
<style src="/i18n/css-*/mycss*.css" />
The result in an HTML with Chrome:
<link ... href="/i18n/css-saf/mycss.css" ...>
All other "*" are ignored
Note
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.
Example
In the following example, we assume the preferred Locale is de_DE and the browser is Internet Explorer.
/css/norm*.css |
|
/css-*/norm*.css |
|
/img*/pic*/lang*.png |
|
/img*/lang.gif |
|
/img/lang*.gif* |
|
/img*/lang*.gif* |
|
Locating Locale- and browser-dependent resources in Java
In addition 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.
- ↑ It is also supported by all components that accept an URL.
Version History
Version | Date | Content |
---|---|---|