Templates为每种语言生成多个JavaScript文件

Templates为每种语言生成多个JavaScript文件

本文介绍了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

我所期望的是它只生成一个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.

还有,但它有点无用对于你的问题,imo。

There's also i18n possibility, but it's kinda useless for your problem, imo.

这篇关于Google Closure Templates为每种语言生成多个JavaScript文件,而不是使用单独的资源文件生成单个JavaScript代码库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:29