我正在使用I18n本地化包来处理应用程序语言切换的部分。它使用全局变量来设置所需的语言,并使用json文件存储翻译内容。
由于语言切换只是全局变量的更改,Ember无法检测到并自动呈现模板。我通过在应用程序控制器中添加一个操作来强制执行。
我对该解决方案有两个问题: 1)应用程序模板未通过我的重新呈现进行更新
由于语言切换只是全局变量的更改,Ember无法检测到并自动呈现模板。我通过在应用程序控制器中添加一个操作来强制执行。
Extranet.ApplicationController = Ember.ObjectController.extend(
{
actions:
{
localToFr: function()
{
this.localisation('fr'); // this changes the global variable
this.get('target.router').refresh(); // this is what refresh the template
},
localToEn: function()
{
this.localisation('en');
this.get('target.router').refresh();
}
},
localisation: function(lg)
{
I18n.locale = lg;
}
})
我对该解决方案有两个问题: 1)应用程序模板未通过我的重新呈现进行更新
this.get('target.router').refresh();
2) 我的另一个问题是,它不能在不请求服务器访问的模板上正常工作(例如:路由“authSession”的嵌套)。
Extranet.Router.map(function()
{
this.resource(
'parkings', {path:'/'}, function ()
{
this.route('parking', {path:'/parking/:parking_id'});
this.route('historique', {path:'/parking/:parking_id/historique'});
this.route('sessAct', {path:'/parking/:parking_id/sessAct'});
this.route('rapport', {path:'/parking/:parking_id/rapport'});
}
);
this.resource(
'authSession', function ()
{
this.route('login');
this.route('logout');
}
);
}
);