EmberJS中的I18n(路由和一般) [英] I18n in EmberJS (routing and in general)

查看:185
本文介绍了EmberJS中的I18n(路由和一般)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EmberJS是否支持国际化应用的翻译路由?或者至少可以轻松扩展它来支持i18n路由?任何有经验的人?



例如。路由字符串可以通过语言环境文件动态设置吗?还有,当使用Ember时,使用Rails路由将不会被指定两次?是这样吗?



我是新来的Ember(目前正在评估js框架),但我假设一般来说,Rails一个简单的指定从Rails里的非常基本的路由,其余的在Ember?所以不会有太多的重复?想知道Rails的区域设置文件是否可用于查找路由转换。



作为一个更一般的问题:Ember是否已经对I18n有任何支持?

解决方案

您可以通过重新打开 Ember.Route 并在初始化时设置本地化路由来实现国际化路由,请参见此处的示例 http://jsfiddle.net/pangratz666/wQXvb/



你有以确保您的路由器初始化之前, c c 字符串查找本身可以由 loc 方法完成,如 sly7_7 所述。



< pre class =lang-js prettyprint-override> Ember.STRINGS = {
'/ all':'/ alle',
'/ home /:id' / zuhause /:id'
};

Ember.Route.reopen({
init:function(){
this._super();
var route = this.get('route') ;
if(route)this.set('route',route.loc());
}
});


Does EmberJS support translated routes for internationalized apps? Or does it at least make it easy to extend it to support i18n routes? Anybody with experience with this?

E.g. can the route string be somehow set dynamically from locale files? Also it would be cool when using Ember with Rails routing would not have to be specified twice... is that so?

I'm new to Ember (currently evaluating js frameworks) but I assume in general with Rails one would simply specify very basic routes from within Rails and the rest in Ember? So there wouldn't be much duplication? Wonder if locale files from Rails could be used to lookup route translations.

As a more general question: does Ember has any support for I18n already?

解决方案

You can achieve internationalized routes by reopening Ember.Route and setting the localized route when it is initialized, see an example here http://jsfiddle.net/pangratz666/wQXvb/.

You have to make sure that the Ember.STRINGS is defined before your router is initialized. The String lookup itself can be done by the loc method, as mentioned by sly7_7.

Ember.STRINGS = {
    '/all': '/alle',
    '/home/:id': '/zuhause/:id'
};

Ember.Route.reopen({
    init: function() {
        this._super();
        var route = this.get('route');
        if (route) this.set('route', route.loc());
    }
});

这篇关于EmberJS中的I18n(路由和一般)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆