如何本地化 wicket 中的 javascript 文件
你好,一个 Wicket i18n 问题: 我有一个 javaScript 文件,其中包含我想要本地化的字符串。 理想情况下,我想本地化整个文件。像
- my.js
- my_de.js
- my_fr.js
- ...
这样的 wicket 会自动选择正确的 js 文件,就像处理属性文件一样。
有人知道该怎么做吗?
Hallo, a Wicket i18n question:
I have a javaScript file, that holds strings I want to localize.
Ideally I want to localize the whole file. Something like
- my.js
- my_de.js
- my_fr.js
- ...
where wicket automatically chooses the right js file, as it does with property files.
Any one knows how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将区域设置传递给资源引用:
Pass the locale to the resource reference:
如果字符串已经在 Javascript 文件中,则实际的解决方案有效。但是,当您在数据库中已经本地化字符串并希望将它们传递给 Javascript 代码时,会发生什么情况呢?您可以创建一个名为
YourPageJS.xml
的XML
文件,并在其中存储由某些键标识的 Javascript 代码。您可以通过位于实用程序类中的以下方法来调用此代码,并传递您的参数:
调用如下所示:
其中参数可以是您的本地化字符串。在上面的情况下,第一个参数是标记 Id。您可以将其添加到您的 html 头部,如下所示:
response.render(JavaScriptHeaderItem.forScript(YourUtils.getJsByClass(YourPage.class, "showModal" ,"firstParameter","secondParameter"), "yourJSid"));
(Wicket 6)此外,在
XML
中,您必须转换两个字符:'
变为''
和{
由于解析原因,变为'{'
。The actual solution works if the Strings are already in the Javascript files.But what happens when you have localized Strings in your database and want to pass them to your Javascript code? You could create a
XML
file namedYourPageJS.xml
and store Javascript code there identified by some keys.You call this code through the following method that is located in an utility class,passing your parameters:
The call looks like this :
where the parameters could be your localized strings.In the above case,the first parameter is the markup Id.You can add it to your html head like this:
response.render(JavaScriptHeaderItem.forScript(YourUtils.getJsByClass(YourPage.class, "showModal" ,"firstParameter","secondParameter"), "yourJSid"));
(Wicket 6)Also,in the
XML
you must transform two characters:'
becomes''
and{
becomes'{'
for parsing reasons.