Files
vanillajs-seed/app/index.js
2020-05-26 10:37:57 +02:00

56 lines
1.2 KiB
JavaScript

(function() {
// globals
MyApp.Utils = {};
// utility functions
// app functions
// events
// app startup
// set language
i18next
.use(i18nextBrowserLanguageDetector)
.use(i18nextXHRBackend)
.init({
detection: {
order: ['querystring', 'cookie', 'navigator'],
lookupQuerystring: 'lang',
lookupCookie: 'current-language',
caches: ['cookie'],
cookieMinutes: 5256000
},
whitelist: ['en', 'de', 'it'],
load: 'languageOnly',
fallbackLng: 'it',
backend: {
loadPath: '/i18n/{{lng}}.json'
}
})
.then(function() {
// language initialized
// if there is a lang query string parameter, remove it and reload: we save the language in a cookie so the url stays nice
var urlQueryString = new URLSearchParams(window.location.search);
if (urlQueryString.has('lang')) {
urlQueryString.delete('lang');
var newUrl = [location.protocol, '//', location.host, location.pathname].join('') +
(urlQueryString.toString() !== '' ? '?' + urlQueryString.toString() : '') +
window.location.hash;
window.location = newUrl;
return;
}
// render main shell
MyApp.Shell.renderShell()
.then(function() {
//setup routing
page({
hashbang: true
});
});
});
})();