我正在使用 Google Closure Template 来使用 JavaScript 编写应用程序的 UI。 查看此问题了解我使用 Google Closure Template 的详细原因。我希望它是多语言的。我看到有一个 --locales
开关,还查看了项目 此处 和此处。在 README_FOR_EXAMPLES 文件中写道
+ simple_ generated_en.js, features_ generated_en.js,
simple_ generated_x-zz.js、features_ generated_x-zz.js
SoyToJsSrcCompiler执行时生成的JS文件
在 simple.soy 和 features.soy 上(区域设置为“en”和“x-zz”,以及来自共享示例目录“examples”的已翻译 XLIFF 文件以及上述编译时全局变量
文件)。我们需要 simple.soy 和 features.soy,因为 features.soy 中的某些模板调用 simple.soy 中的模板。
注意:对于示例 Ant 目标(和命令行参数),
生成这些文件,请参阅顶级“build.xml”中的目标“js-features-example”。
我所期望的是,它只会生成一个 JavaScript 代码库,该代码库将根据调用模板函数之前在运行时提供的选项,使用适当语言环境文件中所需的字符串。这可以通过闭包模板实现吗?
I'm using Google Closure Template in order to write my application's UI using JavaScript. Look at this question for the detailed reason of why I'm using Google Closure Template. I want it to be multilingual. I see that there is a --locales
switch and also looked at the samples provided in the project here and here. In the README_FOR_EXAMPLES files it is written that
+ simple_generated_en.js, features_generated_en.js,
simple_generated_x-zz.js, features_generated_x-zz.js
The JS files generated by SoyToJsSrcCompiler when it is executed
on simple.soy and features.soy (locales are 'en' and 'x-zz' with the translated XLIFF files from shared examples directory 'examples' and with the above compile-time globals
file). We need both simple.soy and features.soy because some of the templates in features.soy call the templates in simple.soy.
Note: For an example Ant target (and command line args) that
generates these files, please see target 'js-features-example' within the top-level 'build.xml'.
What I expected was that it would generate just one JavaScript code base which will use desired strings from the appropriate locale file based on an option provided at runtime before the template function is called. Is that possible with closure templates?
发布评论
评论(1)
据我所知,您可以使用字典对象作为模板的参数。
该对象可以在服务器端从您的区域设置文件生成,并通过 script 标记传输到 javascript。
否则,您可以根据区域设置将不同的编译模板文件加载到客户端。
还有国际化的可能性,但在我看来,它对你的问题有点无用。
As far as I can see, you can use a dictionary-object as a parametr for your template.
This object can be generated on the server-side from your locale file and transfered to javascript via script tag.
Otherwise you can load different compiled template file to the client side according to the locale.
There's also i18n possibility, but it's kinda useless for your problem, imo.