Created
February 23, 2015 09:17
-
-
Save dohomi/f16699ca3afec82f4caa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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