Skip to content

Instantly share code, notes, and snippets.

@frozeman
Last active March 21, 2017 23:07
Show Gist options
  • Save frozeman/78c1849b05cf90467fe7 to your computer and use it in GitHub Desktop.
Save frozeman/78c1849b05cf90467fe7 to your computer and use it in GitHub Desktop.
TAPi18n set default language
// SET default language
if(Cookie.get('TAPi18next')) {
TAPi18n.setLanguage(Cookie.get('TAPi18next'));
} else {
var userLang = navigator.language || navigator.userLanguage,
availLang = TAPi18n.getLanguages();
// set default language
if (_.isObject(availLang) && availLang[userLang]) {
TAPi18n.setLanguage(userLang);
// lang = userLang;
} else if (_.isObject(availLang) && availLang[userLang.substr(0,2)]) {
TAPi18n.setLanguage(userLang.substr(0,2));
// lang = userLang.substr(0,2);
} else {
TAPi18n.setLanguage('en');
// lang = 'en';
}
}
// change moment and numeral language, when language changes
Tracker.autorun(function(){
if(_.isString(TAPi18n.getLanguage())) {
moment.locale(TAPi18n.getLanguage().substr(0,2));
numeral.language(TAPi18n.getLanguage().substr(0,2));
}
});
@luclu
Copy link

luclu commented Mar 21, 2017

Eventually the cookie functionality was disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment