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 start all possible language dictionaries. I thus want to load the dictionary dynamically when the user chooses to change language. I have made a first implementation that works rather well.
See http://jsfiddle.net/cyclomarc/RYbNG/7/
When starting the app, it is rendered in english. You can now select one of the views (About or Info) and these are also rendered in english. When you click on 'Dutch', the dutch language dictionary is loaded and the application is redirected to the index route in the correct language.
It seems that the new language strings are only used when you transition to a dummy route and then back to the route you want (in my sample this is always 'index').
updateLanguage: function (lang) {
var _self = this;
//Load correct dictionary and transition to index route
$.getScript("http://libraries.azurewebsites.net/locales/dictionary_" + lang + ".js", function () {
CLDR.defaultLanguage = lang;
_self.transitionToRoute('I18redirect');
});
}
App.I18redirectRoute = Ember.Route.extend({
activate: function () {
this.transitionTo('index');
}
});
My questions:
Is this the best way to reload a view.template (transition to dummy route and then on activate transition to index) ?
Is there a way to transition back to the route where you requested the language change (would need to use something with get(path) or so ) ?
I would also like to translate the strings 'outside' the red div (the application outlet). I transition back to index, but in that case, the application template is not redrawn ... What could be the reason ?
Is it the expected behaviour that when you move away from a template and then re-enter the template, the template itself is rebuild with all the language strings, or is this only when in the meantime the language is changed ? How could such a rebuild of template with new strings be traced in console log ?
Any other ideas to make this a robust switching solution ?