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