Added fake language option to the client to ease localization

This commit is contained in:
Tomas Bures 2018-11-18 07:05:27 +01:00
parent 4862d6cac4
commit e18d2b2f84

View file

@ -6,6 +6,43 @@ import {getUrl} from "./urls";
import commonEn from "../../../locales/common/en";
function convertToFake(dict) {
function convertValueToFakeLang(str) {
let from = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+\\|`~[{]};:'\",<.>/?";
let to = "ɐqɔpǝɟƃɥıɾʞʅɯuodbɹsʇnʌʍxʎz∀ԐↃᗡƎℲ⅁HIſӼ⅂WNOԀÒᴚS⊥∩ɅX⅄Z0123456789¡@#$%ᵥ⅋⁎()-_=+\\|,~[{]};:,„´<.>/¿";
return str.replace(/(\{\{[^\}]+\}\}|%s)/g, '\x00\x04$1\x00').split('\x00').map(c => {
if (c.charAt(0) === '\x04') {
return c;
}
let r = '';
for (let i = 0, len = c.length; i < len; i++) {
let pos = from.indexOf(c.charAt(i));
if (pos < 0) {
r += c.charAt(i);
} else {
r += to.charAt(pos);
}
}
return r;
}).join('\x00').replace(/[\x00\x04]/g, '');
}
function _convertToFake(dict) {
for (const key in dict) {
const val = dict[key];
if (typeof val === 'string') {
dict[key] = convertValueToFakeLang(val);
} else {
_convertToFake(val);
}
}
}
return _convertToFake(dict);
}
i18n
.use(LanguageDetector)
.init({
@ -13,6 +50,9 @@ i18n
resources: {
en: {
common: commonEn
},
en_fake: {
common: convertToFake(commonEn)
}
},
@ -27,6 +67,14 @@ i18n
wait: true
},
detection: {
order: ['querystring', 'cookie', 'localStorage', 'navigator'],
lookupQuerystring: 'language',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
caches: ['localStorage']
},
debug: true
})