Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Dynamic message key for i18n

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 1

Hello Runal,

thx for your reply.

I used the format-version and it works!

Very nice idea.

 

Kind regards

Matthias