Custom internationalized messages on custom client constraints

asked 2012-06-19 14:45:38 +0800

cvarona gravatar image cvarona
554 1 6


I have written some client constraints and I would like to endow them with internationalized messages, just like zk shipped simple constraints. By peeping into the source js code I've learned the labels in the mefainfo/mesg/msgzul bundles get loaded into the global js var msgzul and then can be used by the constraint code, like this:

outOfRangeValue: function () {
		return msgzul.OUT_OF_RANGE + ': ' + (this._beg != null ? this._end != null ?
				new zk.fmt.Calendar(null, this._localizedSymbols).formatDate(this._beg, this.format) + " ~ "
					+ new zk.fmt.Calendar().formatDate(this._end, this.format) :
					">= " + new zk.fmt.Calendar().formatDate(this._beg, this.format):
					"<= " + new zk.fmt.Calendar().formatDate(this._end, this.format));

As a matter of fact I've created an specialized msgzul_es_ES.properties file in order to rewrite most of the messages and they get loaded fine. But I've been unable to understand

1) how placeholder i18nized messages like

Debe especificar una fecha, en lugar de {0}.
Formato: {1}.
work. I've been unable to find any ocurrence in the whole zul js code of such messages.

2) what's the purpose of the codes (2042 in the example above) that make up the keys in these properties files
3) what's the magic that makes #-=DATE_REQUIRED appear as a member in the msgzul global js var
4) why the magic does not work if I write something like

2060=Número total de dígitos
and then attempt to refer it in my js constraint code like msgzul.TOTAL_DIGIT_COUNT (it just returns 'undefined').

With kind regards

César Varona

delete flag offensive retag edit

1 Reply

Sort by » oldest newest

answered 2012-06-20 06:31:25 +0800

cvarona gravatar image cvarona
554 1 6

I finally managed to solve it, although not the way I'd preferred. I found the code that populates the msgzul js object; it's to be found in zul's zk.wpd:

<function class="org.zkoss.zul.impl.Utils" signature="java.lang.String outLocaleJavaScript()"/>

I mimicked the outLocaleJavaScript() code and invoked the js it generates on the client side via Clients.evalJavaScript. Everything works fine, but I'd rather do it in a cleaner way, if available.

By the way, this section explains how to change a particular zk message for a given locale. But, what if I'd like to completely replace one msgzul_*.properties with another? Can I write my own, say msgzul_es.properties, and place it somewhere so that zk loads it instead of the shipped msgzul_es.properties?

With kind regards

César Varona

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2012-06-19 14:45:38 +0800

Seen: 158 times

Last updated: Jun 20 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More