Ember: dynamic switch to chosen language (using i18n library)

前端 未结 3 1275
孤独总比滥情好
孤独总比滥情好 2021-02-05 16:05

I am using the ember-i18n library for translation of static strings used throughout my application. As the language files are rather big, I do not want to load at application st

3条回答
  •  逝去的感伤
    2021-02-05 16:18

    You could utilize rerender() method of the view, this way you won't have to switch to a dummy url:

    updateLanguage: function(lang) {
    
        //Send xhr to get a dictionary for corresponding language
        this.getDictionary(lang).then(successCb, failureCb);
    
        //If dictionary was retrieved, set translations property and 
        function successCb(response) {
            Ember.I18n.translations = response;
            $.each(Ember.View.views, function(index, view) {
              view.rerender();
            });
        };
    
        function failureCb(response) {
            console.error('Dictionary for this language is not available');
        };
    }
    

提交回复
热议问题