Warning and Error Messages"

From Documentation
m
 
(30 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{ZKDevelopersGuidePageHeader}}
+
{{ZKDevelopersReferencePageHeader}}
  
 
__TOC__
 
__TOC__
  
Messages are stored in properties files which are located at the <tt>/metainfo/mesg</tt> directory of the classpath. Each module is associated with an unique name. In addition, the Locale is appended to the property file, too. For example, the message file of <tt>zk.jar</tt> for Germany messages is <tt>msgzk_de_DN.properties</tt> or <tt>msgzk_de.properties</tt>.
+
=Overview=
  
=== Translate messages to another language ===
+
ZK's system locale dependent messages (such as warnings and errors) are stored in ZK jar with 2 formats:
 +
# [ZK-JAR]<code>/metainfo/mesg/*.properties</code>, Java properties files
 +
#:[ZK-JAR] could be zcommon.jar, zweb.jar, zk.jar or zul.jar.
 +
# <code>zk.jar /web/js/zk/lang/*.js</code>
 +
# <code>zul.jar/web/js/zul/lang/*.js</code>
  
If you want to translate messages to another language, you can add your own property files named with the correct locale to the <tt>/metainfo/mesg</tt> directory of the classpath. Of course, it is always better to contribute it back at [http://docs.zkoss.org/wiki/ZK_Mesgs ZK Mesgs]
+
These files are Locale depedent. For example, the message file in <code>zk.jar</code> for German messages are
 +
* <code>/metainfo/mesg/msgzk_de.properties</code>,  
 +
* <code>/web/js/zk/lang/msgzk_de.js</code>
  
=== Change particular message ===
+
= Translate messages to another language =
  
[since 5.1.0]
+
If you want to translate messages to another language, you can add your own property files named with the correct Locale, and put them to the <code>/metainfo/mesg</code> directory of the classpath. Of course, it is always better to contribute 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 notify us at info@zkoss.org.
  
If you want to change a particular message, you can add it to i3-label.properties. For example, let us see you want to customize <code>MZk.NOT_FOUND</code> in German translation, then you can add the following to <code>WEB-INF/i3-label_de.properties</code>:
+
= Change particular message =
 +
Look for the specific message you want to change at [[ZK Messages]] first. Then, override it according to the following sections.
 +
 
 +
== Defined in a Properties File ==
 +
{{versionSince| 6.0.0}}
 +
 
 +
If you want to change a particular message, you need to create  <code>WEB-INF/zk-label.properties</code> (or <code>WEB-INF/zk-label_[LOCALE].properties</code>) and add key-value pairs in it. For example, assuming you want to customize <code>MZk.NOT_FOUND</code> in German translation (<code>msgzk_de.properties</code>), then you can add the following to <code>WEB-INF/zk-label_de.properties</code>:
  
 
<source lang="xml">
 
<source lang="xml">
Line 19: Line 31:
 
</source>
 
</source>
  
where 3000 is the error code and you can find it at [http://docs.zkoss.org/wiki/ZK_Mesgs ZK Mesgs]
+
Notice the prefix <code>MZk</code>, and <code>3000</code> is the error code and you can find it at [[ZK_Messages/German/msgzk_de.properties]]
 +
 
 +
The same pattern applies to the [[ZK_Messages/German | other message files]] such as
 +
 
 +
{|  class="wikitable" | width="100%"
 +
!  <center>File</center>
 +
! <center>Prefix of a Key</center>
 +
! <center>Key Example</center>
 +
|-
 +
| msgzk_[LOCALE].properties
 +
| <code>MZk</code>
 +
| MZk.1000= my text
 +
|-
 +
|msgzul_[LOCALE].properties
 +
| <code>MZul</code>
 +
| MZul.2400=mytext
 +
|-
 +
| msgcommon_[LOCALE].properties
 +
| <code>MCommon</code>
 +
| MCommon.1234= my text
 +
|-
 +
| msgweb_[LOCALE].properties
 +
| <code>MWeb</code>
 +
| MWeb.1234= my test
 +
|}
 +
 
 +
== Defined in a JS File ==
 +
 
 +
=== Using local override===
 +
For messages defined in <code>msgzk.js / msgzul.js</code> you can create a js file and include it via <code>lang-addon.xml</code>. For example for overriding <code>msgzk.LOADING</code> for CEZH language create a file <code>test_cs.js</code> and override particular message <code>msgzk.LOADING=CS langauge specific message"</code> and include this js file via <code>lang-addon.xml</code> as below
 +
<source lang="xml">
 +
<language-addon>
 +
  <addon-name>test</addon-name>
 +
  <language-name>xul/html</language-name>
 +
 
 +
  <javascript src="/js/test*.js" />
 +
</language-addon>
 +
</source>
 +
 
 +
Note: You can use any prefix other than "test" and add language-specific suffixes to your js files and include all of them by using <code>*</code> wild card as shown above
 +
 
 +
Finally include your lang-addon.xml in zk.xml using language-config element as shown below
 +
<source lang="xml">
 +
<language-config>
 +
    <addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
 +
</language-config>
 +
</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=
  
 +
{| class='wikitable' | width="100%"
 +
! Version !! Date !! Content
 +
|-
 +
| 6.0.0
 +
| n/a
 +
| Allows applications to override a particular message with <code>zk-label</code>.
 +
|}
  
{{ ZKDevelopersGuidePageFooter}}
+
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 03:15, 1 February 2024


Warning and Error Messages


Overview

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

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

These files are Locale depedent. For example, the message file in zk.jar for German messages are

  • /metainfo/mesg/msgzk_de.properties,
  • /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 them to the /metainfo/mesg directory of the classpath. Of course, it is always better to contribute 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 notify us at info@zkoss.org.

Change particular message

Look for the specific message you want to change at ZK Messages first. Then, override it according to the following sections.

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

The same pattern applies to the other message files such as

File
Prefix of a Key
Key Example
msgzk_[LOCALE].properties MZk MZk.1000= my text
msgzul_[LOCALE].properties MZul MZul.2400=mytext
msgcommon_[LOCALE].properties MCommon MCommon.1234= my text
msgweb_[LOCALE].properties MWeb MWeb.1234= my test

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 suffixes 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

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



Last Update : 2024/02/01

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