Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 木偶+;模板中的i18n_Backbone.js_Internationalization_Marionette - Fatal编程技术网

Backbone.js 木偶+;模板中的i18n

Backbone.js 木偶+;模板中的i18n,backbone.js,internationalization,marionette,Backbone.js,Internationalization,Marionette,我想在我的应用程序中做一些基本的i18n 我将i18n插件(从require.js)加载到我的应用程序中,并创建了一个目录nls,其中有几个文件,例如project.js 我在main.js文件中设置了默认位置 config : { i18n : { locale : 'de-de' } } 现在我想使用视图/模板中的文件。有人能给我解释一下这是怎么做的吗?模板设置在一个template.js文件中 我的看法是: define(['marionette', 't

我想在我的应用程序中做一些基本的i18n

我将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>
i18n插件的文件在这里有很好的解释:


我必须一步一步地这样做,首先我没有找到根,然后我想知道为什么我的德语语言环境没有加载,但我只是忘记在根文件中设置
de de:true
。现在一切都很顺利

首先通过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>

{{this.myVar}}

希望这对您有所帮助。首先,您可以通过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>

{{this.myVar}}

希望对你有所帮助

非常感谢,我不得不做一些不同的事情,这对我帮助很大,我将在原始帖子中发布我的结果非常感谢,我不得不做一些不同的事情,这对我帮助很大,我将在原始帖子中发布我的结果