Google Closure Templates为每种语言生成多个JavaScript文件,而不是使用单独的资源文件生成单个JavaScript代码库
我正在使用Google Closure Template来使用JavaScript编写应用程序的UI。 查看此问题,了解我使用Google Closure Template的详细原因。我希望它是多语言的。我看到有一个 - locales
开关,还查看了项目中提供的示例这里和这里。在README_FOR_EXAMPLES文件中,写入
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
SoyToJsSrcCompiler在simple.soy和features.soy上执行
时生成的JS文件(locales为'en'和'x-zz',带有翻译的XLIFF文件从共享示例目录'examples'和上面的编译时全局变量
文件)。我们需要simple.soy和features.soy,因为features.soy中的一些模板在simple.soy中调用模板。
注意:对于
生成这些文件的Ant目标(和命令行参数),请在顶级'build.xml'中查看目标'js-features-example'。
+ 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'.
我所期望的是它只生成一个JavaScript代码库,它将根据运行时提供的选项使用相应语言环境文件中的所需字符串在调用模板函数之前。是否可以使用闭包模板?
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?
据我所见,您可以使用字典对象作为参数你的模板。
As far as I can see, you can use a dictionary-object as a parametr for your template.
/**
* @param dict
*/
{template .example}
<h1>{$dict.title}</h1>
<div>{$dict.content}</div>
{/template}
此对象可以在服务器端从您的语言环境生成文件并通过脚本标签转移到javascript。
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.
还有 i18n可能性,但它有点无用对于你的问题,imo。
There's also i18n possibility, but it's kinda useless for your problem, imo.