解决方法
我遇到了同样的问题,我只是通过使用Jquery Extend函数解决了这个问题.
假设您定义语言资源如下:
1)使用默认本地化创建资源文件,可能是用英语定义的.我们称之为resources.default.js
- var MyApp = MyApp || {};
- MyApp.resources = {
- One: "One",Two: "Two",Three:"Three"
- }
2)在独立文件中定义本地化资源,比方说西班牙语.称之为resources.es.js
- var localizedResources = {
- One: "Uno",Two: "Dos",Three:"Tres"
- }
3)在您的服务器逻辑上,确定您只需要包含英语的默认翻译,或者如果您需要任何其他语言,请执行包含.
- <script src="resources.es.js"> </script>
4)创建您的网页,并根据步骤3添加脚本以处理您包含的资源.
- <html>
- <head>
- </head>
- <body>
- <h1>Welcome to my App</h1>
- <p>Welcome to this test app</p>
- <button>Click me</button>
- <script src="resources.default.js"> </script>
- // The server decided we needed Spanish translations.
- <script src="resources.es.js"> </script>
- <script type="text/javascript">
- //Extend the translations into the resources object.
- $.extend(MyApp.resources,localizedResources);
- $(window).ready(function(){
- $('button').click(function(){
- alert(MyApp.resources.One);
- });
- });
- </script>
- </body>
这应该适合你.
编辑:
在这里看到它:http://jsfiddle.net/agarcian/rrDv3/1/