mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 02:48:28 -07:00
Merge: - client: set i18n language only from available languages
Closes #1082 * commit '3269766ea7e2340a658cc13343f9d3cc6565b7dc': - client: use lowercase lang codes - client: set i18n language only from available languages
This commit is contained in:
commit
b870db249e
@ -30,10 +30,6 @@ export const REPOSITORY = {
|
|||||||
export const PRIVACY_POLICY_LINK = 'https://adguard.com/privacy/home.html';
|
export const PRIVACY_POLICY_LINK = 'https://adguard.com/privacy/home.html';
|
||||||
|
|
||||||
export const LANGUAGES = [
|
export const LANGUAGES = [
|
||||||
{
|
|
||||||
key: 'en',
|
|
||||||
name: 'English',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: 'da',
|
key: 'da',
|
||||||
name: 'Dansk',
|
name: 'Dansk',
|
||||||
@ -46,6 +42,10 @@ export const LANGUAGES = [
|
|||||||
key: 'nl',
|
key: 'nl',
|
||||||
name: 'Dutch',
|
name: 'Dutch',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'en',
|
||||||
|
name: 'English',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'es',
|
key: 'es',
|
||||||
name: 'Español',
|
name: 'Español',
|
||||||
|
@ -3,6 +3,8 @@ import { reactI18nextModule } from 'react-i18next';
|
|||||||
import { initReactI18n } from 'react-i18next/hooks';
|
import { initReactI18n } from 'react-i18next/hooks';
|
||||||
import langDetect from 'i18next-browser-languagedetector';
|
import langDetect from 'i18next-browser-languagedetector';
|
||||||
|
|
||||||
|
import { DEFAULT_LANGUAGE } from './helpers/constants';
|
||||||
|
|
||||||
import vi from './__locales/vi.json';
|
import vi from './__locales/vi.json';
|
||||||
import en from './__locales/en.json';
|
import en from './__locales/en.json';
|
||||||
import ru from './__locales/ru.json';
|
import ru from './__locales/ru.json';
|
||||||
@ -49,16 +51,16 @@ const resources = {
|
|||||||
sv: {
|
sv: {
|
||||||
translation: sv,
|
translation: sv,
|
||||||
},
|
},
|
||||||
'pt-BR': {
|
'pt-br': {
|
||||||
translation: ptBR,
|
translation: ptBR,
|
||||||
},
|
},
|
||||||
'zh-TW': {
|
'zh-tw': {
|
||||||
translation: zhTW,
|
translation: zhTW,
|
||||||
},
|
},
|
||||||
bg: {
|
bg: {
|
||||||
translation: bg,
|
translation: bg,
|
||||||
},
|
},
|
||||||
'zh-CN': {
|
'zh-cn': {
|
||||||
translation: zhCN,
|
translation: zhCN,
|
||||||
},
|
},
|
||||||
cs: {
|
cs: {
|
||||||
@ -85,7 +87,7 @@ const resources = {
|
|||||||
pl: {
|
pl: {
|
||||||
translation: pl,
|
translation: pl,
|
||||||
},
|
},
|
||||||
'pt-PT': {
|
'pt-pt': {
|
||||||
translation: ptPT,
|
translation: ptPT,
|
||||||
},
|
},
|
||||||
sk: {
|
sk: {
|
||||||
@ -99,22 +101,29 @@ const resources = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const availableLanguages = Object.keys(resources);
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(langDetect)
|
.use(langDetect)
|
||||||
.use(initReactI18n)
|
.use(initReactI18n)
|
||||||
.use(reactI18nextModule) // passes i18n down to react-i18next
|
.use(reactI18nextModule)
|
||||||
.init({
|
.init({
|
||||||
resources,
|
resources,
|
||||||
fallbackLng: 'en',
|
lowerCaseLng: true,
|
||||||
keySeparator: false, // we use content as keys
|
fallbackLng: DEFAULT_LANGUAGE,
|
||||||
nsSeparator: false, // Fix character in content
|
keySeparator: false,
|
||||||
returnEmptyString: false, // count empty value as invalid
|
nsSeparator: false,
|
||||||
|
returnEmptyString: false,
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false, // not needed for react!!
|
escapeValue: false,
|
||||||
},
|
},
|
||||||
react: {
|
react: {
|
||||||
wait: true,
|
wait: true,
|
||||||
},
|
},
|
||||||
|
}, () => {
|
||||||
|
if (!availableLanguages.includes(i18n.language)) {
|
||||||
|
i18n.changeLanguage(DEFAULT_LANGUAGE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default i18n;
|
export default i18n;
|
||||||
|
Loading…
Reference in New Issue
Block a user