-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
i have searched without success about the handling of internationalization in zul in the case of setting a 'default' value when the key is not found.
sample:
...
<label value="${labels.roles.granted, 'default text'}" />
or
<label value="${c:l('roles.granted', 'default text') }" />
thanks Stephan
You can register the Labels.getLabel(String, String)
method in your zul file and access it like this (also check the documentation):
assume you have a /WEB-INF/zk-label.properties containing the label property existing=existing value
<?xel-method prefix="my" name="labelDefault"
class="org.zkoss.util.resource.Labels"
signature="java.lang.String getLabel(java.lang.String, java.lang.String)"?>
<zk>
<window border="normal" title="hello">
<label value="${my:labelDefault('existing', 'default for existing')}"/>
<label value="${my:labelDefault('not.existing', 'default for not existing')}"/>
</window>
</zk>
the first label would output the label, the second one would fallback to the default given.
Robert
Thanks Robert, works.
WHY is this not inBuild ?? it's a lot of more code.
<label value="${labels.roles.granted, 'default text'}" />
seems very smaller than add a xel method in every zul page.
Stephan
Terry,
Actually it can be done in zul only :
<label value="@load(labels.roles.granted eq null?'default text':labels.roles.granted)"/>
Greetz chill.
Hi Terry,
I don't really understand the meaning of this syntax
<label value="${labels.roles.granted, 'default text'}" />
is the ',' something like a fallback operator? JSP EL/ZEL does not define this operator.
You could define a general purpose function similar to the SQL coalesce function, that returns the first non-null value.
and use it like this:
<label value="${my:coalesce(labels.roles.granted, 'default text')}" />
WHY is this not inBuild ??
It is not built-in since ZK offers lots of customization possibilities, and I18N already has fallback mechanisms for unavailable translations e.g: de_DE->de->defaultLocale
To avoid repetition of the xel-method directive in every page you can create your own taglib containing all the methods you want to use, and import them once with a taglib directive in the same way as you include the built-in functions:
Please refer to the documentation on taglibs, custom taglibs and an example.
the previous example above could look like this:
<?taglib uri="/WEB-INF/tld/my.tld" prefix="my"?>
<zk>
<window border="normal" title="hello">
<label value="${my:l('not.existing', 'default for not extisting')}"/>
<label value="${my:l('existing', 'default for extisting')}"/>
</window>
</zk>
and the taglib would be:
<taglib>
<function>
<name>l</name>
<function-class>org.zkoss.util.resource.Labels</function-class>
<function-signature>
java.lang.String getLabel(java.lang.String, java.lang.String)
</function-signature>
<description>Retrieve a label with a default.</description>
</function>
<!-- any number of functions are allowed -->
</taglib>
Regards,
Robert
OK, Thanks Robert and chill.
I'm now using the taglib proposal. So it's an one page app with the dynamic contents in the borderlayout center area it's enough to define one time the taglib in the main zul file.
thanks Stephan
Asked: 2014-05-04 11:40:21 +0800
Seen: 32 times
Last updated: May 06 '14
Locale problem in DoubleSpinner on IOS (Ipad, Iphone)
Table grand total internationalization
How to get a label value for all the different international label file?
Internationalization properties for custom component
ZK9 internationalization java.lang.IllegalStateException
Labels from DB using Spring Boot
How to access static member field of a class in zul without zscript