Further work on localization

This commit is contained in:
Tomas Bures 2018-12-15 15:15:48 +01:00
parent fa451fc8da
commit cb1fc5b28d
35 changed files with 430 additions and 2796 deletions

View file

@ -12,25 +12,24 @@ import mailtrainConfig
import hoistStatics
from 'hoist-non-react-statics';
import {convertToFake, langCodes} from '../../../shared/langs';
import {convertToFake, getLang} from '../../../shared/langs';
import commonEn from "../../../locales/en/common";
import commonEs from "../../../locales/es/common";
import lang_en_US_common from "../../../locales/en-US/common";
const resourcesCommon = {
en: commonEn,
es: commonEs,
fake: convertToFake(commonEn)
'en-US': lang_en_US_common,
'fk-FK': convertToFake(lang_en_US_common)
};
const resources = {};
for (const lng of mailtrainConfig.enabledLanguages) {
const shortCode = langCodes[lng].shortCode;
resources[shortCode] = {
common: resourcesCommon[shortCode]
const langDesc = getLang(lng);
resources[langDesc.longCode] = {
common: resourcesCommon[langDesc.longCode]
};
}
console.log(resources);
i18n
.use(LanguageDetector)
@ -46,17 +45,20 @@ i18n
react: {
wait: true,
defaultTransParent: 'span' // This is because we use React < v16
defaultTransParent: 'span' // This is because we use React < v16 FIXME
},
detection: {
order: ['querystring', 'cookie', 'localStorage', 'navigator'],
lookupQuerystring: 'language',
lookupCookie: 'i18next',
lookupQuerystring: 'locale',
lookupCookie: 'i18nextLng',
lookupLocalStorage: 'i18nextLng',
caches: ['localStorage']
caches: ['localStorage', 'cookie']
},
whitelist: mailtrainConfig.enabledLanguages,
load: 'currentOnly',
debug: true
})

View file

@ -3,6 +3,7 @@
import {anonymousRestrictedAccessToken} from '../../../shared/urls';
import {AppType} from '../../../shared/app';
import mailtrainConfig from "mailtrainConfig";
import i18n from './i18n';
let restrictedAccessToken = anonymousRestrictedAccessToken;
@ -18,8 +19,14 @@ function getSandboxUrl(path) {
return mailtrainConfig.sandboxUrlBase + restrictedAccessToken + '/' + (path || '');
}
function getPublicUrl(path) {
return mailtrainConfig.publicUrlBase + (path || '');
function getPublicUrl(path, opts) {
const url = new URL(path || '', mailtrainConfig.publicUrlBase);
if (opts && opts.withLocale) {
url.searchParams.append('locale', i18n.language);
}
return url.toString();
}
function getUrl(path) {