2015-10-26 17:11:44 +01:00
|
|
|
// commonjs code goes here
|
2017-06-15 19:48:48 +02:00
|
|
|
import i18next from 'i18next';
|
2018-05-30 19:43:49 +02:00
|
|
|
import localstorage from './localstorage';
|
2016-07-05 13:05:51 +02:00
|
|
|
|
2017-06-15 19:48:48 +02:00
|
|
|
window.i18n = i18next;
|
2016-05-13 12:44:03 +02:00
|
|
|
|
2018-05-30 18:14:20 +02:00
|
|
|
i18next.init({
|
|
|
|
lng: 'lang',
|
|
|
|
resources: {
|
|
|
|
lang: {
|
|
|
|
translation: page_params.translation_data,
|
2018-05-29 12:34:59 +02:00
|
|
|
},
|
2018-05-30 18:14:20 +02:00
|
|
|
},
|
|
|
|
nsSeparator: false,
|
|
|
|
keySeparator: false,
|
|
|
|
interpolation: {
|
|
|
|
prefix: "__",
|
|
|
|
suffix: "__",
|
|
|
|
},
|
|
|
|
returnEmptyString: false, // Empty string is not a valid translation.
|
|
|
|
});
|
2016-06-10 09:03:36 +02:00
|
|
|
|
2018-05-29 12:34:59 +02:00
|
|
|
// garbage collect all old-style i18n translation maps in localStorage.
|
2017-04-10 20:12:30 +02:00
|
|
|
$(function () {
|
2017-07-28 21:18:33 +02:00
|
|
|
if (!localstorage.supported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-10 20:12:30 +02:00
|
|
|
// this collects all localStorage keys that match the format of:
|
|
|
|
// i18next:dddddddddd:w+ => 1484902202:en
|
|
|
|
// these are all language translation strings.
|
|
|
|
var translations = Object.keys(localStorage).filter(function (key) {
|
|
|
|
return /^i18next:\d{10}:\w+$/.test(key);
|
|
|
|
});
|
|
|
|
|
2017-07-19 10:17:06 +02:00
|
|
|
// remove cached translations of older versions.
|
2017-04-10 20:12:30 +02:00
|
|
|
translations.forEach(function (translation_key) {
|
2018-05-29 12:34:59 +02:00
|
|
|
localStorage.removeItem(translation_key);
|
2017-04-10 20:12:30 +02:00
|
|
|
});
|
|
|
|
return this;
|
|
|
|
});
|