Warning and Error Messages"

From Documentation
(6 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
=Overview=
 
=Overview=
  
ZK's system locale dependent messages (such as warnings and errors) are stored in property files (<code>*.properties</code>) inside a jar file's <tt>/metainfo/mesg</tt>, such as zcommon.jar, zweb.jar, zk.jar and zul.jar. These files are Locale depedent. For example, the message file in <tt>zk.jar</tt> for Germany messages is <tt>msgzk_de.properties</tt> or <tt>msgzk_de_DN.properties</tt>.
+
ZK's system locale dependent messages (such as warnings and errors) are stored in ZK jar with 2 formats:
 +
* [ZK-JAR]<tt>/metainfo/mesg/*.properties</tt>, Java properties files
 +
*:[ZK-JAR] could be zcommon.jar, zweb.jar, zk.jar or zul.jar.
 +
* [zk.jar | zul.jar]<tt>/web/zk/js/lang/*.js</tt>
 +
 
 +
These files are Locale depedent. For example, the message file in <tt>zk.jar</tt> for Germany messages is <tt>msgzk_de.properties</tt>, <tt>msgzk_de_DN.properties</tt>, or <tt>zk.jar/web/js/zk/lang/msgzk_de.js</tt>.
  
 
= Translate messages to another language =
 
= Translate messages to another language =
Line 23: Line 28:
  
 
Notice the prefix <tt>MZk</tt>, and <tt>3000</tt> is the error code and you can find it at [[ZK_Messages/German/msgzk_de.properties]]
 
Notice the prefix <tt>MZk</tt>, and <tt>3000</tt> is the error code and you can find it at [[ZK_Messages/German/msgzk_de.properties]]
 +
 +
A same pattern applies to the [[ZK_Messages/German | other message files]] such as
 +
*<tt>msgzul_de.properties</tt>,
 +
*<tt>msgcommon_de.properties</tt>
 +
*<tt>msgweb_de.properties</tt>.
 +
Where you use the following prefixes to customize a message
 +
<source lang="xml">
 +
MZul.1234=abc
 +
MCommon.1234=...
 +
MWeb.1234=...
 +
</source>
  
 
== Defined in a JS File ==
 
== Defined in a JS File ==
  
 +
=== Using local override===
 
For messages defined in <tt> msgzk.js / msgzul.js</tt> you can create a js file and include it via <tt>lang-addon.xml</tt>. For example for overriding <tt>msgzk.LOADING</tt> for CEZH language create a file <tt>test_cs.js</tt> and override particular message <code>msgzk.LOADING=CS langauge specific message"</code> and include this js file via <tt>lang-addon.xml</tt> as below
 
For messages defined in <tt> msgzk.js / msgzul.js</tt> you can create a js file and include it via <tt>lang-addon.xml</tt>. For example for overriding <tt>msgzk.LOADING</tt> for CEZH language create a file <tt>test_cs.js</tt> and override particular message <code>msgzk.LOADING=CS langauge specific message"</code> and include this js file via <tt>lang-addon.xml</tt> as below
 
<source lang="xml">
 
<source lang="xml">
Line 44: Line 61:
 
</language-config>
 
</language-config>
 
</source>
 
</source>
 +
 +
Note: messages updated by a custom javascript will override the default once.
 +
If the messages are reloaded using Clients.reloadMessages(Locale), the customization will be lost. To support locale reload, please refer to the next section.
 +
 +
=== Adding a custom language loader ===
 +
A custom language loader will find matching messages depending on the user locale, and will be reloaded even if the Clients.reloadMessages(Locale) is triggered.
 +
 +
It can be defined in a language addon using the <message-loader-class> element.
 +
Please refer to the [[ZK_Client-side_Reference/Language_Definition/message-loader-class|client-side reference]] documentation for more details.
  
 
=Version History=
 
=Version History=

Revision as of 04:36, 21 February 2019


Warning and Error Messages


Overview

ZK's system locale dependent messages (such as warnings and errors) are stored in ZK jar with 2 formats:

  • [ZK-JAR]/metainfo/mesg/*.properties, Java properties files
    [ZK-JAR] could be zcommon.jar, zweb.jar, zk.jar or zul.jar.
  • [zk.jar | zul.jar]/web/zk/js/lang/*.js

These files are Locale depedent. For example, the message file in zk.jar for Germany messages is msgzk_de.properties, msgzk_de_DN.properties, or zk.jar/web/js/zk/lang/msgzk_de.js.

Translate messages to another language

If you want to translate messages to another language, you can add your own property files named with the correct Locale, and put it to the /metainfo/mesg directory of the classpath. Of course, it is always better to contribute it back. Please take a look at ZK Messages for all available translations. If you'd like to contribute, just add the language to it and notice us at info at zkoss dot org.

Change particular message

Defined in a Properties File

[since 6.0.0]

If you want to change a particular message, you need to create WEB-INF/zk-label.properties (or WEB-INF/zk-label_[LOCALE].properties) and add key-value pairs in it. For example, assuming you want to customize MZk.NOT_FOUND in German translation (msgzk_de.properties), then you can add the following to WEB-INF/zk-label_de.properties:

MZk.3000=my customized message here

Notice the prefix MZk, and 3000 is the error code and you can find it at ZK_Messages/German/msgzk_de.properties

A same pattern applies to the other message files such as

  • msgzul_de.properties,
  • msgcommon_de.properties
  • msgweb_de.properties.

Where you use the following prefixes to customize a message

MZul.1234=abc
MCommon.1234=...
MWeb.1234=...

Defined in a JS File

Using local override

For messages defined in msgzk.js / msgzul.js you can create a js file and include it via lang-addon.xml. For example for overriding msgzk.LOADING for CEZH language create a file test_cs.js and override particular message msgzk.LOADING=CS langauge specific message" and include this js file via lang-addon.xml as below

<language-addon>
  <addon-name>test</addon-name>
  <language-name>xul/html</language-name>

  <javascript src="/js/test*.js" />
</language-addon>

Note: You can use any prefix other than "test" and add language specific suffix to your js files and include all of them by using * wild card as shown above

Finally include your lang-addon.xml in zk.xml using language-config element as shown below

<language-config>
    <addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
</language-config>

Note: messages updated by a custom javascript will override the default once. If the messages are reloaded using Clients.reloadMessages(Locale), the customization will be lost. To support locale reload, please refer to the next section.

Adding a custom language loader

A custom language loader will find matching messages depending on the user locale, and will be reloaded even if the Clients.reloadMessages(Locale) is triggered.

It can be defined in a language addon using the <message-loader-class> element. Please refer to the client-side reference documentation for more details.

Version History

Last Update : 2019/02/21


Version Date Content
6.0.0 n/a Allows applications to override a particular message with zk-label.



Last Update : 2019/02/21

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