Skip to content

Instantly share code, notes, and snippets.

@dohomi
Created February 23, 2015 09:17
Show Gist options
  • Save dohomi/f16699ca3afec82f4caa to your computer and use it in GitHub Desktop.
Save dohomi/f16699ca3afec82f4caa to your computer and use it in GitHub Desktop.
Router.configure({
layoutTemplate: 'layoutBackend',
notFoundTemplate: 'page404',
loadingTemplate: 'loading',
i18n: {
languages: TP.Const.AllowedLangKey,
setLanguage: function (lang) {
if (Meteor.isClient) {
TP.Core.Functions.setLanguageKey(lang);
}
},
missingLangCodeAction: function (url) {
if (Meteor.isClient) {
TP.initLangCodeMissing = true;
// pasted code from origin i18n
var lang = this.getLanguage();
var path = Iron.Url.normalize(url);
if (lang) {
this.go('/' + lang + path);
return true;
} else {
console.log("Can't retrieve current language on " + this.getEnv() + ".");
return false;
}
}
}
}
});
Template.body.rendered = function () {
this.autorun(function () {
var langCodeMissing = TP.initLangCodeMissing;
var userLang = Meteor.user() && Meteor.user().languageKey;
var currentRouterLanguage = Router.getLanguage();
if (langCodeMissing && !Meteor.loggingIn() && userLang) {
if (userLang !== currentRouterLanguage) {
Router.setLanguage(userLang);
}
} else {
if (currentRouterLanguage !== TP.Core.Functions.getLanguageKey()) {
TP.Core.Functions.setLanguageKey(currentRouterLanguage);
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment