简体   繁体   English

如何使用百里香叶将翻译成javascript

[英]How to put translation into javascript using thymeleaf

Using thymeleaf i generate a page which content some javascript. 使用百里香我生成了一个页面,其中包含一些JavaScript。 The js is generated with thymeleaf in order to get some part of the java model into my page. js是用百里香产生的,以便将Java模型的某些部分放入我的页面。

I know how to get some translation into my html using thymeleaf. 我知道如何使用百里香叶将一些翻译成我的html。

But now i want to get some of the thymeleaf translation into my generated js in order to centralize my translation effort. 但是现在我想将一些百里香叶翻译到生成的js中,以便集中翻译工作。

Ideally i'd like to have a window.messages variable which would contains all my translated messages. 理想情况下,我想拥有一个window.messages变量,该变量将包含我所有已翻译的消息。 This var would be initialized in the genrated js script. 该变量将在生成的js脚本中初始化。

Any reference on this? 有什么参考吗?

You can use 您可以使用

var window.messages = /*[[#{MESSAGE_FILE_TEXT}]]*/ 

or 要么

var window.messages = /*[[${TEXT_FROM_CONTROLER}]]*/

Reference to documentation on script inlining 参考有关脚本内联的文档

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

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