webpack: Migrate translations.js to use ES2015 syntax.

This commit is contained in:
digi0ps 2017-06-15 23:18:48 +05:30 committed by showell
parent 61744a7a2a
commit f228700ef2
1 changed files with 46 additions and 47 deletions

View File

@ -1,56 +1,55 @@
// commonjs code goes here // commonjs code goes here
(function () { import i18next from 'i18next';
var i18n = window.i18n = require('i18next'); import XHR from 'i18next-xhr-backend';
var XHR = require('i18next-xhr-backend'); import LngDetector from 'i18next-browser-languagedetector';
var lngDetector = require('i18next-browser-languagedetector'); import Cache from 'i18next-localstorage-cache';
var Cache = require('i18next-localstorage-cache');
var backendOptions = { window.i18n = i18next;
loadPath: '/static/locale/__lng__/translations.json',
};
var callbacks = [];
var initialized = false;
var detectionOptions = { var backendOptions = {
order: ['htmlTag'], loadPath: '/static/locale/__lng__/translations.json',
htmlTag: document.documentElement, };
}; var callbacks = [];
var initialized = false;
var cacheOptions = { var detectionOptions = {
enabled: true, order: ['htmlTag'],
prefix: 'i18next:' + page_params.server_generation + ':', htmlTag: document.documentElement,
expirationTime: 2*7*24*60*60*1000, // 2 weeks };
};
i18n.use(XHR) var cacheOptions = {
.use(lngDetector) enabled: true,
.use(Cache) prefix: 'i18next:' + page_params.server_generation + ':',
.init({ expirationTime: 2*7*24*60*60*1000, // 2 weeks
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]();
}
});
i18n.ensure_i18n = function (callback) { i18next.use(XHR)
if (initialized) { .use(LngDetector)
callback(); .use(Cache)
} else { .init({
callbacks.push(callback); 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]();
} }
}; });
}()); i18next.ensure_i18n = function (callback) {
if (initialized) {
callback();
} else {
callbacks.push(callback);
}
};