简体   繁体   English

如何加载特定于组件的资源包以进行翻译?

[英]How to load component-specific resource bundle for translation?

I followed the instructions on this page ( http://docs.adobe.com/docs/en/cq/current/developing/cq5-translator.html ) in order to try to give my component access to a translatable string bundle. 我按照本页上的说明进行操作( http://docs.adobe.com/docs/en/cq/current/developing/cq5-translator.html ),以尝试使我的组件可以访问可翻译的字符串包。 I followed these instructions ( http://www.wemblog.com/2011/12/how-to-use-multi-language-translation.html ) to setup the component's JSP file to use the translated strings. 我按照这些说明( http://www.wemblog.com/2011/12/how-to-use-multi-language-translation.html )设置了组件的JSP文件以使用翻译后的字符串。 However, it's not working; 但是,它不起作用。 the default value is always used. 始终使用默认值。 I'm not sure where it is attempting to pull the resource bundle from, but I would like it to pull from the i18n folder I've created directly under the component node. 我不确定从哪里尝试从中提取资源包,但是我希望它从我直接在组件节点下创建的i18n文件夹中提取。 Any ideas what I am doing wrong? 有什么想法我做错了吗?

Relevant JSP code: 相关的JSP代码:

<cq:setContentBundle language="se" source="static" /><%
Locale pageLocale = currentPage.getLanguage(false); 
ResourceBundle resourceBundle = slingRequest.getResourceBundle("hello-world-strings", pageLocale);
    I18n i18n = new I18n(resourceBundle);
%>

<div style="margin:1em;padding:.8em;box-shadow:inset 0px 0px .5em #ddd;border:solid 1px #aaa;">
    <h1>Translation Testing Output</h1>
    OUT: <%= i18n.get("name") %>
</div>

Adding a comment in CQ's translator changes the key. 在CQ的翻译器中添加评论会更改键。 For debugging, try spitting the keys out: 要进行调试,请尝试吐出密钥:

<%= slingRequest.getResourceBundle(slingRequest.getLocale()).keySet()%><br>

If you see keys in the list that have unexpected double parentheses, those are the translator comments. 如果您在列表中看到带有意外的双括号的键,则这些是翻译者的注释。 If this is the case, you may not be getting messages because the keys aren't what you think they should be. 在这种情况下,您可能不会收到消息,因为密钥不是您认为应该的。 Try deleting the comments. 尝试删除评论。 You can't do this in the translator, but you can use a tool like crxde to edit the sling:key property directly. 您不能在转换器中执行此操作,但是可以使用crxde之类的工具直接编辑sling:key属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM