【问题标题】:AEM 6.x: How to access i18n translations via Javascript?AEM 6.x:如何通过 Javascript 访问 i18n 翻译?
【发布时间】:2017-03-13 16:32:05
【问题描述】:

我正在尝试使用 Javascript 从我在 AEM 的翻译器 (/libs/cq/i18n/translator.html) 中创建的字典中动态检索翻译的消息。

我们的字典值设置如下:

String          EN                  FR
========================================================
TEST-001        This is a Test1     FR:This is a Test1
TEST-002        This is a Test2     FR:This is a Test2
TEST-003        This is a Test3     FR:This is a Test3

我已经阅读了国际化 UI 字符串文章 (https://docs.adobe.com/docs/en/aem/6-2/develop/components/i18n/i18n-dev.html),但是当我尝试以下操作时:

Granite.I18n.setLocale("en");
Granite.I18n.get("TEST-001");

Granite.I18n.setLocale("fr");
Granite.I18n.get("TEST-001");

我只返回我传入的字符串(即“TEST-001”)。

有人可以帮我理解如何取回翻译后的值吗?

谢谢!

【问题讨论】:

    标签: javascript internationalization adobe aem translate


    【解决方案1】:

    取决于您的翻译存储在哪里,您可以尝试类似 -

    <script>
            Granite.I18n.init({
                locale: "<%= LocaleUtil.toRFC4646(request.getLocale()).toLowerCase() %>",
                urlPrefix: "<%= request.getContextPath() %>/libs/cq/i18n/dict."
            });
        </script>
    

    这是取自这里的样本 -

    /libs/cq/gui/components/projects/admin/page/head.jsp
    

    另一种方法是

    <html
        lang="<%= LocaleUtil.toRFC4646(request.getLocale()).toLowerCase() %>"
        data-i18n-dictionary-src="<%= request.getContextPath() %>/libs/cq/i18n/dict.{+locale}.json">
    

    取自 - /libs/fd/fm/gui/components/admin/creationwizard/page/page.jsp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2018-11-25
      • 2018-09-19
      • 1970-01-01
      相关资源
      最近更新 更多