# Labels.getLabel with default

18691 1 10 129

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 retag edit

## 2 Replies

icecuber
1

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

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? answered 2015-11-27 12:51:48 +0800 chillworld 5322 4 9 https://github.com/chillw... 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')}/>

[hide preview]