diff --git a/static/js/translations.js b/static/js/translations.js index e8a8cdb9dc..c42b5470df 100644 --- a/static/js/translations.js +++ b/static/js/translations.js @@ -1,79 +1,30 @@ // commonjs code goes here - import i18next from 'i18next'; -import XHR from 'i18next-xhr-backend'; -import LngDetector from 'i18next-browser-languagedetector'; -import Cache from 'i18next-localstorage-cache'; -import localstorage from './localstorage'; window.i18n = i18next; -// Add those keys in this list which are received from the backend -// and are translated by calling i18n.t function on variables. For example, -// i18n.t(receivedFromBackend); -var toBeTranslated = [ // eslint-disable-line no-unused-vars - // The Emoji type name for the "text" emojiset choice - i18n.t('Plain text'), -]; - -function loadPath(languages) { - var language = languages[0]; - if (language.indexOf('-') >= 0) { - language = language.replace('-', '_'); // Change zh-Hans to zh_Hans. - } - - return '/static/locale/' + language + '/translations.json'; -} - -var backendOptions = { - loadPath: loadPath, -}; -var callbacks = []; -var initialized = false; - -var detectionOptions = { - order: ['htmlTag'], - htmlTag: document.documentElement, -}; - -var cacheOptions = { - enabled: !page_params.development, - prefix: 'i18next:' + page_params.server_generation + ':', - expirationTime: 2*24*60*60*1000, // 2 days -}; - -i18next.use(XHR) - .use(LngDetector) - .use(Cache) +i18next .init({ + lng: 'lang', + resources: { + lang: { + translation: page_params.translation_data, + }, + }, nsSeparator: false, keySeparator: false, interpolation: { prefix: "__", suffix: "__", }, - backend: backendOptions, - detection: detectionOptions, - cache: cacheOptions, - fallbackLng: 'en', returnEmptyString: false, // Empty string is not a valid translation. - }, function () { - var i; - initialized = true; - for (i=0; i