2013-02-10 109 views
1

我想要做一些基本的国际化在我的应用程序木偶+国际化

我装了i18n的插件(从require.js)到我的应用程序和创建的目录nls其中我有几个文件,例如project.js

main.js文件中设置的默认位置像

config : { 
    i18n : { 
     locale : 'de-de' 
    } 
} 

我现在想用在我看来/模板文件。有人可以向我解释这是如何完成的吗?这些模板安装在一个文件template.js

笔者认为:

define(['marionette', 'templates', 'i18n!nls/project'], function (marionette, templates, msg) { 

    return marionette.CompositeView.extend({ 
     template : templates.project 
    }); 

}); 

我的模板:

<div class="container"> 
    <div class="well"> 
     <h2>Projects</h2> 
    </div> 
</div> 

有人能向我解释如何使用文件在我看来/模板?提前致谢!

编辑:

我想通了一些解决方案尝试&错误。正如我通过require.js tpl加载模板!插件我不需要编译它们,如果我打电话给他们require('tpl!templates/dashboard.tmpl')。我可以简单地通过我加载的i18n文件'i18n!nls/dashboard'。在木偶认为是默认渲染,所以我这样做:

define(['marionette', 'templates', 'i18n!nls/dashboard'], function (Marionette, templates, msg) { 

    return Marionette.CompositeView.extend({ 

     template : function() { 
      return templates.dashboard(msg); 
     }, 

     initialize : function() { 

     } 
    }); 

}); 

的国际化插件的文件以及这里解释: http://requirejs.org/docs/api.html#i18n

我不得不做这一步一步来,首先我错过根,然后我想知道为什么我的德语区域设置没有加载,但我只是忘了在根文件中设置de-de : true。现在一切都像魅力

回答

5

首先你通过require.js加载i18文件到你的视图。 我在这个例子中使用了把手模板。

define([ 
    'marionette', 
    'handlebars', 
    'text!modules/tableModule/templates/myTmpl.html', 
    'i18n!nls/dashboard', 
], 
function(Marionette, Handlebars, tmpl, locals) { ... 

然后你编译并加载你的模板与i18对象。

var template = Handlebars.compile(tmpl); 
this.template = template(locals.myVar); 

,你可以去和做复杂的组合以及

var template = Handlebars.compile(tmpl); 
    var data =_.extend(options, {lang:locals}); 
    this.template = template(data); 

您的NLS文件看起来像这样

define({ 

    "root": { 
     "myVar" : "some text in", 
     "canBeAnObjectTo": { 
         "title" : "my title ", 
         "contact" : "Contact", 
      } 

,你的看法会是这样的:

<div class="cssClass"> 
<div class="table-caption pull-left">{{this.myVar}}</div> 
    </div> 

希望能帮到

+0

非常感谢你,我不得不做的事情有点不同,它帮助了我很多,我会在原始帖子中发布我的结果 – pfried 2013-02-11 08:51:20