mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
Ensure translations are loaded.
Since i18next loads translations asynchronously we need to make sure that they are loaded before we call the JS code which depends on them. Fixes #982
This commit is contained in:
@@ -1,26 +1,45 @@
|
||||
// commonjs code goes here
|
||||
|
||||
var i18n = window.i18n = require('i18next');
|
||||
var XHR = require('i18next-xhr-backend');
|
||||
var lngDetector = require('i18next-browser-languagedetector');
|
||||
var backendOptions = {
|
||||
loadPath: '/static/locale/__lng__/translations.json'
|
||||
};
|
||||
(function () {
|
||||
var i18n = window.i18n = require('i18next');
|
||||
var XHR = require('i18next-xhr-backend');
|
||||
var lngDetector = require('i18next-browser-languagedetector');
|
||||
var backendOptions = {
|
||||
loadPath: '/static/locale/__lng__/translations.json'
|
||||
};
|
||||
var callbacks = [];
|
||||
var initialized = false;
|
||||
|
||||
var detectionOptions = {
|
||||
order: ['htmlTag'],
|
||||
htmlTag: document.documentElement
|
||||
};
|
||||
var detectionOptions = {
|
||||
order: ['htmlTag'],
|
||||
htmlTag: document.documentElement
|
||||
};
|
||||
|
||||
i18n.use(XHR)
|
||||
.use(lngDetector)
|
||||
.init({
|
||||
nsSeparator: false,
|
||||
keySeparator: false,
|
||||
interpolation: {
|
||||
prefix: "__",
|
||||
suffix: "__"
|
||||
},
|
||||
backend: backendOptions,
|
||||
detection: detectionOptions
|
||||
});
|
||||
i18n.use(XHR)
|
||||
.use(lngDetector)
|
||||
.init({
|
||||
nsSeparator: false,
|
||||
keySeparator: false,
|
||||
interpolation: {
|
||||
prefix: "__",
|
||||
suffix: "__"
|
||||
},
|
||||
backend: backendOptions,
|
||||
detection: detectionOptions
|
||||
}, function () {
|
||||
var i;
|
||||
initialized = true;
|
||||
for (i=0; i<callbacks.length; i++) {
|
||||
callbacks[i]();
|
||||
}
|
||||
});
|
||||
|
||||
i18n.ensure_i18n = function (callback) {
|
||||
if (initialized) {
|
||||
callback();
|
||||
} else {
|
||||
callbacks.push(callback);
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user