I want to apply internationalisation for my Meteor app, so I use i18n package.
Firstly, when go to my app, user is not logged in so the language is defined by browser language.
After logging in, how can I set the app language based on the property stored at user.profile.displayLanguage in database?
Thanks.
getUserLanguage = function() {
//use English by default, otherwise use user settings
var user = Meteor.user();
if(user && user.profile && user.profile.displayLanguage) {
return user.profile.displayLanguage;
}
return "en";
};
if (Meteor.isClient) {
Meteor.startup(function() {
Session.set("showLoadingIndicator", true);
TAPi18n.setLanguage(getUserLanguage())
.done(function() {
Session.set("showLoadingIndicator", false);
})
.fail(function(error_message) {
// Handle the situation
console.log(error_message);
});
});
}