I18n in EmberJS (routing and in general)

无人久伴 提交于 2019-12-05 13:22:50

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());
    }
});

There is an ember-i18n project: https://github.com/zendesk/ember-i18n

It'll help you with your strings, but there isn't a solution for dealing with translated URLs currently.

You can use any JS routing library with Ember. There's a pretty simple Ember.Location protocol for integrating your own routing library with Ember.Router.

A partial answer for the general question can be found here:

http://docs.emberjs.com/#doc=Ember.String&method=.loc&src=false

I think this is not a complete i18n support, and there is no one built in emberjs.

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