1

Missing default value for internationalization in zul [closed]

asked 2014-05-04 11:40:21 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by terrytornado
close date 2014-05-06 09:38:53

5 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-06 09:38:25 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

link publish delete flag offensive edit

Comments

thanks for giving instant feedback! much appreciated

cor3000 ( 2014-05-06 10:03:43 +0800 )edit
0

answered 2014-05-06 04:38:37 +0800

cor3000 gravatar image cor3000
6280 2 7

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

link publish delete flag offensive edit
0

answered 2014-05-05 16:05:55 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9
https://github.com/chillw...

Terry,

Actually it can be done in zul only :

<label value="@load(labels.roles.granted eq null?'default text':labels.roles.granted)"/>

Greetz chill.

link publish delete flag offensive edit
0

answered 2014-05-05 09:46:03 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

link publish delete flag offensive edit
1

answered 2014-05-05 02:23:10 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2014-05-05 02:26:16 +0800

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

link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-05-04 11:40:21 +0800

Seen: 32 times

Last updated: May 06 '14

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