2015-10-26 17:11:44 +01:00
|
|
|
// commonjs code goes here
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
import i18next from 'i18next';
|
|
|
|
import XHR from 'i18next-xhr-backend';
|
|
|
|
import LngDetector from 'i18next-browser-languagedetector';
|
|
|
|
import Cache from 'i18next-localstorage-cache';
|
2016-07-05 13:05:51 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
window.i18n = i18next;
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
var backendOptions = {
|
|
|
|
loadPath: '/static/locale/__lng__/translations.json',
|
|
|
|
};
|
|
|
|
var callbacks = [];
|
|
|
|
var initialized = false;
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
var detectionOptions = {
|
|
|
|
order: ['htmlTag'],
|
|
|
|
htmlTag: document.documentElement,
|
|
|
|
};
|
2016-07-05 13:05:51 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
var cacheOptions = {
|
|
|
|
enabled: true,
|
|
|
|
prefix: 'i18next:' + page_params.server_generation + ':',
|
|
|
|
expirationTime: 2*7*24*60*60*1000, // 2 weeks
|
|
|
|
};
|
2016-06-10 09:03:36 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
i18next.use(XHR)
|
|
|
|
.use(LngDetector)
|
|
|
|
.use(Cache)
|
|
|
|
.init({
|
|
|
|
nsSeparator: false,
|
|
|
|
keySeparator: false,
|
|
|
|
interpolation: {
|
|
|
|
prefix: "__",
|
|
|
|
suffix: "__",
|
|
|
|
},
|
|
|
|
backend: backendOptions,
|
|
|
|
detection: detectionOptions,
|
|
|
|
cache: cacheOptions,
|
|
|
|
fallbackLng: 'en',
|
|
|
|
}, function () {
|
|
|
|
var i;
|
|
|
|
initialized = true;
|
|
|
|
for (i=0; i<callbacks.length; i += 1) {
|
|
|
|
callbacks[i]();
|
2016-06-10 09:03:36 +02:00
|
|
|
}
|
2017-06-15 19:48:48 +02:00
|
|
|
});
|
2016-06-10 09:03:36 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
i18next.ensure_i18n = function (callback) {
|
|
|
|
if (initialized) {
|
|
|
|
callback();
|
|
|
|
} else {
|
|
|
|
callbacks.push(callback);
|
|
|
|
}
|
|
|
|
};
|