Marionette + i18n in templates

↘锁芯ラ 提交于 2019-12-04 20:16:06

first you load the i18 file via require.js to your view. I use the handlebars templates in this example.

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

then you compile and load your template with the i18 object.

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

you can go and do complex combinations as well

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

your nls file will look like this

define({

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

and your view will be something like this:

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

hope that helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!