+ client: remove locales from js bundle

This commit is contained in:
Ildar Kamalov
2020-01-31 15:57:20 +03:00
parent 2151563757
commit 4d55f51fee
9 changed files with 177 additions and 248 deletions

View File

@@ -1,7 +1,9 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { Trans, withNamespaces } from 'react-i18next';
import { REPOSITORY, LANGUAGES, PRIVACY_POLICY_LINK } from '../../helpers/constants';
import { REPOSITORY, PRIVACY_POLICY_LINK } from '../../helpers/constants';
import { LANGUAGES } from '../../helpers/twosky';
import i18n from '../../i18n';
import Version from './Version';
@@ -68,9 +70,9 @@ class Footer extends Component {
value={i18n.language}
onChange={this.changeLanguage}
>
{LANGUAGES.map(language => (
<option key={language.key} value={language.key}>
{language.name}
{Object.keys(LANGUAGES).map(lang => (
<option key={lang} value={lang}>
{LANGUAGES[lang]}
</option>
))}
</select>

View File

@@ -31,117 +31,6 @@ export const REPOSITORY = {
export const PRIVACY_POLICY_LINK = 'https://adguard.com/privacy/home.html';
export const LANGUAGES = [
{
key: 'da',
name: 'Dansk',
},
{
key: 'de',
name: 'Deutsch',
},
{
key: 'nl',
name: 'Dutch',
},
{
key: 'en',
name: 'English',
},
{
key: 'es',
name: 'Español',
},
{
key: 'fr',
name: 'Français',
},
{
key: 'id',
name: 'Indonesian',
},
{
key: 'it',
name: 'Italiano',
},
{
key: 'pl',
name: 'Polski',
},
{
key: 'pt-br',
name: 'Portuguese (BR)',
},
{
key: 'pt-pt',
name: 'Portuguese (PT)',
},
{
key: 'sk',
name: 'Slovenčina',
},
{
key: 'sl',
name: 'Slovenščina',
},
{
key: 'sv',
name: 'Svenska',
},
{
key: 'vi',
name: 'Tiếng Việt',
},
{
key: 'tr',
name: 'Türkçe',
},
{
key: 'cs',
name: 'Český',
},
{
key: 'bg',
name: 'Български',
},
{
key: 'ru',
name: 'Русский',
},
{
key: 'ja',
name: '日本語',
},
{
key: 'zh-tw',
name: '正體中文',
},
{
key: 'zh-cn',
name: '简体中文',
},
{
key: 'no',
name: 'Norsk',
},
{
key: 'sr-cs',
name: 'Srpski',
},
{
key: 'hr',
name: 'Hrvatski',
},
{
key: 'fa',
name: 'فارسی',
},
{
key: 'ko',
name: '한국어',
},
];
export const INSTALL_FIRST_STEP = 1;
export const INSTALL_TOTAL_STEPS = 5;

View File

@@ -0,0 +1,6 @@
import twosky from 'MainRoot/.twosky.json';
export const {
languages: LANGUAGES,
base_locale: BASE_LOCALE,
} = twosky[0];

View File

@@ -1,132 +1,21 @@
import i18n from 'i18next';
import XHR from 'i18next-xhr-backend';
import { reactI18nextModule } from 'react-i18next';
import { initReactI18n } from 'react-i18next/hooks';
import langDetect from 'i18next-browser-languagedetector';
import { DEFAULT_LANGUAGE } from './helpers/constants';
import { LANGUAGES, BASE_LOCALE } from './helpers/twosky';
import vi from './__locales/vi.json';
import en from './__locales/en.json';
import ru from './__locales/ru.json';
import es from './__locales/es.json';
import fr from './__locales/fr.json';
import ja from './__locales/ja.json';
import sv from './__locales/sv.json';
import ptBR from './__locales/pt-br.json';
import zhTW from './__locales/zh-tw.json';
import bg from './__locales/bg.json';
import zhCN from './__locales/zh-cn.json';
import cs from './__locales/cs.json';
import da from './__locales/da.json';
import de from './__locales/de.json';
import id from './__locales/id.json';
import it from './__locales/it.json';
import ko from './__locales/ko.json';
import no from './__locales/no.json';
import nl from './__locales/nl.json';
import pl from './__locales/pl.json';
import ptPT from './__locales/pt-pt.json';
import sk from './__locales/sk.json';
import sl from './__locales/sl.json';
import tr from './__locales/tr.json';
import srCS from './__locales/sr-cs.json';
import hr from './__locales/hr.json';
import fa from './__locales/fa.json';
const resources = {
en: {
translation: en,
},
vi: {
translation: vi,
},
ru: {
translation: ru,
},
es: {
translation: es,
},
fr: {
translation: fr,
},
ja: {
translation: ja,
},
sv: {
translation: sv,
},
'pt-br': {
translation: ptBR,
},
'zh-tw': {
translation: zhTW,
},
bg: {
translation: bg,
},
'zh-cn': {
translation: zhCN,
},
cs: {
translation: cs,
},
da: {
translation: da,
},
de: {
translation: de,
},
id: {
translation: id,
},
it: {
translation: it,
},
ko: {
translation: ko,
},
no: {
translation: no,
},
nl: {
translation: nl,
},
pl: {
translation: pl,
},
'pt-pt': {
translation: ptPT,
},
sk: {
translation: sk,
},
sl: {
translation: sl,
},
tr: {
translation: tr,
},
'sr-cs': {
translation: srCS,
},
hr: {
translation: hr,
},
fa: {
translation: fa,
},
};
const availableLanguages = Object.keys(resources);
const availableLanguages = Object.keys(LANGUAGES);
i18n
.use(langDetect)
.use(XHR)
.use(initReactI18n)
.use(reactI18nextModule)
.init({
resources,
lowerCaseLng: true,
fallbackLng: DEFAULT_LANGUAGE,
fallbackLng: BASE_LOCALE,
keySeparator: false,
nsSeparator: false,
returnEmptyString: false,
@@ -136,9 +25,13 @@ i18n
react: {
wait: true,
},
whitelist: availableLanguages,
backend: {
loadPath: '/__locales/{{lng}}.json',
},
}, () => {
if (!availableLanguages.includes(i18n.language)) {
i18n.changeLanguage(DEFAULT_LANGUAGE);
i18n.changeLanguage(BASE_LOCALE);
}
});