- client: set i18n language only from available languages

This commit is contained in:
Ildar Kamalov 2019-10-21 13:09:52 +03:00
parent 67a3d44b8c
commit bd1ee48a4f
2 changed files with 18 additions and 10 deletions

View File

@ -30,10 +30,6 @@ export const REPOSITORY = {
export const PRIVACY_POLICY_LINK = 'https://adguard.com/privacy/home.html';
export const LANGUAGES = [
{
key: 'en',
name: 'English',
},
{
key: 'da',
name: 'Dansk',
@ -46,6 +42,10 @@ export const LANGUAGES = [
key: 'nl',
name: 'Dutch',
},
{
key: 'en',
name: 'English',
},
{
key: 'es',
name: 'Español',

View File

@ -3,6 +3,8 @@ import { reactI18nextModule } from 'react-i18next';
import { initReactI18n } from 'react-i18next/hooks';
import langDetect from 'i18next-browser-languagedetector';
import { DEFAULT_LANGUAGE } from './helpers/constants';
import vi from './__locales/vi.json';
import en from './__locales/en.json';
import ru from './__locales/ru.json';
@ -99,22 +101,28 @@ const resources = {
},
};
const availableLanguages = Object.keys(resources);
i18n
.use(langDetect)
.use(initReactI18n)
.use(reactI18nextModule) // passes i18n down to react-i18next
.use(reactI18nextModule)
.init({
resources,
fallbackLng: 'en',
keySeparator: false, // we use content as keys
nsSeparator: false, // Fix character in content
returnEmptyString: false, // count empty value as invalid
fallbackLng: DEFAULT_LANGUAGE,
keySeparator: false,
nsSeparator: false,
returnEmptyString: false,
interpolation: {
escapeValue: false, // not needed for react!!
escapeValue: false,
},
react: {
wait: true,
},
});
if (!i18n.language.includes(availableLanguages)) {
i18n.changeLanguage(DEFAULT_LANGUAGE);
}
export default i18n;