Dynamic message key for i18n | Community
Skip to main content
October 16, 2015
Solved

Dynamic message key for i18n

Hello,

I'm working with AEM6 and Sightly and have an issue with our message keys.

Until now we had some text output like

<fmt:message key="message.key.${variable}" />

 

Now I would like to use this format: ${'message.key' @ i18n}

I thought, I found the solution by using 

${'message.key.part.{0}.another.part.{1}' @ i18n, format=[variable1, variable2]}

but the format-option only injects the values of variable1 and variable2 into the translation of the provided message key at the corresponding placeholders.

Other combinations like ${'message.key.'variable @ i18n} or ${'message.key.${variable}' @ i18n} failed.

 

I hope someone can provide a solution :-)

Best regards

Matthias

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
October 16, 2015

You can first concat it into one string and assign it to sightly variable using data-sly-test. See the snippet below

<div data-sly-test.prefix="next">
<div data-sly-test.suffix="text">
<div data-sly-test.i18key="${prefix}.${suffix}">
Value - ${i18key @ i18n}

You can also use @format to form a single string and assign it to sightly variable using data-sly-test.<variablename>

<div data-sly-test.key="${ '{0}.{1}' @ format=['next','text']}">
Value - ${key @ i18n}

I guess above should help.

Cheers

- Runal

2 replies

Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
October 16, 2015

You can first concat it into one string and assign it to sightly variable using data-sly-test. See the snippet below

<div data-sly-test.prefix="next">
<div data-sly-test.suffix="text">
<div data-sly-test.i18key="${prefix}.${suffix}">
Value - ${i18key @ i18n}

You can also use @format to form a single string and assign it to sightly variable using data-sly-test.<variablename>

<div data-sly-test.key="${ '{0}.{1}' @ format=['next','text']}">
Value - ${key @ i18n}

I guess above should help.

Cheers

- Runal

Translate
October 16, 2015

Hello Runal,

thx for your reply.

I used the format-version and it works!

Very nice idea.

 

Kind regards

Matthias

Translate