0

Labels.getLabel with default

asked 2007-10-23 11:01:53 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4583875

By: khainodd

Hello all,

I don't know if I should put the desired features directly in the tracker or if I should wait until someone in the team asks me to. So, I'd rather wait for someone to tell me if I can post it in the tracker.

I think it would be a good idea if Labels.getLabel("hello") would return "[[hello]]"
or something like if the label does not exist in the properties file. So it would be easier to debug and complete the labels forgotten when writing code.

Thank you all, and keep the good work! :)

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2015-11-27 11:04:27 +0800

icecuber gravatar image icecuber
1

We are in 2015 and this is not possible!? i try to override LabelLoader:

<library-property> <name>org.zkoss.util.resource.LabelLoader.class</name> <value>my.package.LabelLoader</value> </library-property>

but for some reasons did not work the way i expected: not called from: <label value="${labels.app.title}" <="" p="">

but from Labels.getLabel from java class & from zul 'system' files...

any idea i can do it?

link publish delete flag offensive edit

answered 2015-11-27 12:51:48 +0800

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

updated 2015-11-27 12:52:10 +0800

Actually this is already possible from the moment taglibs are there.

It's already provided in the Label class long time ago but never got into the core taglib.

So you could create your own taglib (under WEB-INF/tld/xxx.tld):

<taglib>
    <!-- Retrieve an I18N string with a default value -->
    <function>
        <name>labelDef</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>
</taglib>

and usage :

<?taglib uri="/WEB-INF/tld/xxx.tld" prefix="i18n"?>
<label value="${i18n:labelDef('mykey','default value')}/>
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

Follow

RSS

Stats

Asked: 2007-10-23 11:01:53 +0800

Seen: 483 times

Last updated: Nov 27 '15

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