AEM 6 viewly: How to read a variable from a language file?

I have the following html:

<div >${'foo' @ i18n}</div>

In my i18n file, I have the following:

<foo
            jcr:mixinTypes="[sling:Message]"
            jcr:primaryType="sling:MessageEntry"
            sling:key="foo"
            sling:message="This is dummy text"/>

This is dummy textdisplayed on the page. Okay bye. The problem is that it foois a variable that comes from another template, and I read the following:

${fooValue} //this returns foo

Now, to read the message from i18n, I tried the following:

< div>${'${fooValue}' @ i18n} </div>

but is displayed on this page ${fooValue}. How to read a message from i18nif I have variable key?

+4
source share
2 answers

You can use the local template to which you pass a variable that identifies your key for the i18n dictionary:

<template data-sly-template.locale="${@ key}">
    ${key @ i18n, locale='de'}    
</template>

<div data-sly-call="${locale @ key='world'}"></div>

, i18n , :

<div>
    Welt    
</div>

locale :

<template data-sly-template.locale="${@ key}">
    ${key @ i18n, locale='de'}    
</template>

<template data-sly-template.translate="${@ string}">
    <div data-sly-call="${locale @ key=string}" data-sly-unwrap></div>
</template>

<div data-sly-call="${translate @ string='world'}"></div>

, .

+5

Radu . , , - .

<div>${fooValue @ i18n}</div>

. . <div>${fooValue @ i18n}</div> vs <div data-sly-call="${translate @ string=fooValue}"></div>.

+2

All Articles