I have a simple translate class (module) which handles the localization for my app. Inside the translate class I am loading the required language modules with a require function.
define(['require', 'config', 'store'],
function(require, Config, Store) {
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
'use strict';
var translation = {
locale: null,
name: null,
keys: null,
timezones: null
};
var languageCode = Store.getInstance().get('LanguageCode') || Config.defaultLanguageCode;
require(['translation/' + languageCode], function(trans) {
translation = trans;
});
var get = function(key) {
return (!!translation.keys && translation.keys[key]) ? translation.keys[key] : key;
};
var timezone = function(key) {
return (translation.timezones[key]) ? translation.timezones[key] : key;
};
return {
_: get,
timezone: timezone,
timezones: function() {
return translation.timezones;
}
};
});
The problem is that the return statement is executed before the needed language has loaded. I put the translate class in the require shim to load it before other modules but that didn't work either.