zulip/static/js/src/main.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-10-26 17:11:44 +01:00
// commonjs code goes here
(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');
var backendOptions = {
loadPath: '/static/locale/__lng__/translations.json',
};
var callbacks = [];
var initialized = false;
var detectionOptions = {
order: ['htmlTag'],
htmlTag: document.documentElement,
};
2016-07-05 13:05:51 +02:00
var cacheOptions = {
enabled: true,
prefix: 'i18next:' + page_params.server_generation + ':',
2016-07-05 13:05:51 +02:00
};
i18n.use(XHR)
.use(lngDetector)
2016-07-05 13:05:51 +02:00
.use(Cache)
.init({
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: "__",
suffix: "__",
},
backend: backendOptions,
2016-07-05 13:05:51 +02:00
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) {
if (initialized) {
callback();
} else {
callbacks.push(callback);
}
};
}());