我有以下html:
<div >${'foo' @ i18n}</div>
Run Code Online (Sandbox Code Playgroud)
在我的i18n文件中,我有以下内容:
<foo
jcr:mixinTypes="[sling:Message]"
jcr:primaryType="sling:MessageEntry"
sling:key="foo"
sling:message="This is dummy text"/>
Run Code Online (Sandbox Code Playgroud)
This is dummy text显示在页面中.到目前为止.问题是这foo是一个来自其他模板的变量,我读如下:
${fooValue} //this returns foo
Run Code Online (Sandbox Code Playgroud)
现在从i18n读取消息我尝试了以下内容:
<div>${'${fooValue}' @ i18n} </div>
但是这会显示${fooValue}在页面中.i18n如果有的话,如何阅读消息variable key?
小智 5
您可以使用本地模板向其传递标识i18n字典键的变量:
<template data-sly-template.locale="${@ key}">
${key @ i18n, locale='de'}
</template>
<div data-sly-call="${locale @ key='world'}"></div>
Run Code Online (Sandbox Code Playgroud)
假设你的i18n字典有翻译,输出将是:
<div>
Welt
</div>
Run Code Online (Sandbox Code Playgroud)
您还可以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>
Run Code Online (Sandbox Code Playgroud)
输出与上面相同.
| 归档时间: |
|
| 查看次数: |
5402 次 |
| 最近记录: |