0

Dynamic labels load based on DB value

asked 2017-09-04 16:05:34 +0800

ajamardo gravatar image ajamardo
11 1

I have a message, in a variable selectedMessage, and in the object, I have a message type coming from the DB, which is a String value, for example, OPERATIONAL . So, now, I want to translate this value to another language, so I have the labels in the file, as:

app.user.messages.type.OPERATIONAL=Operacional

Is there any way to load that value?

I've tried several things, but non worked... like:

<label value="${ c:cat('labels.app.user.messages.type.', vmApp.selectedMessage.msgType) }"/>

<label value="${ c:l(c:cat('labels.app.user.messages.type.', vmApp.selectedMessage.msgType)) }"/>

<label value="@load(c:l(c:cat('labels.app.user.messages.type.', vmApp.selectedMessage.msgType)) )"/>

Thanks in advance

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-09-06 16:27:39 +0800

ajamardo gravatar image ajamardo
11 1

Well, I finally found a way, so I'm gonna reply my own question.

Here it is, as the last example not working that I provided, when you use the l taglib, you don't need the labels. part

<label value="@load(c:l(c:cat('app.user.messages.type.', vmApp.selectedMessage.msgType)) )"/>

link publish delete flag offensive edit

Comments

thanks for sharing your result... I just added another way

cor3000 ( 2017-09-07 02:13:40 +0800 )edit
0

answered 2017-09-07 02:04:06 +0800

cor3000 gravatar image cor3000
3382 1 7
ZK Team

updated 2017-09-07 02:17:51 +0800

how about using the labels variable. Since it represents the labels as nested maps you can access properties dynamically using the square brackets labels.app[propertyExpression] and an expression resulting in a string (indirect reference):

<label value="@load(labels.app.user.messages.type[vmApp.selectedMessage.msgType])"/>

or if reused more often on a page you can use @ref to make it more readable and improve performance (PE/EE only):

<div msgLabels="@ref(labels.app.user.messages)" selMsg="@ref(vmApp.selectedMessage)">
    <label value="@load(msgLabels.type[selMsg.msgType])"/>
    <label value="@load(msgLabels.status[selMsg.msgStatus])"/>
    <label value="@load(msgLabels.somethingElse[selMsg.msgSomethingElse])"/>
</div>

Robert

link publish delete flag offensive edit
Your answer
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
2 followers

RSS

Stats

Asked: 2017-09-04 16:05:34 +0800

Seen: 15 times

Last updated: Sep 07

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