From 5e784d118833c9c02a573775ff45457a8d7e768e Mon Sep 17 00:00:00 2001 From: Juan Picado Date: Fri, 17 Sep 2021 07:17:34 +0200 Subject: [PATCH] refactor: one single file for i18n conf ui (#2440) * refactor: one single file for i18n conf ui * add test for crowdin * cleanup * space --- crowdin.yaml | 4 + .../src/App/Header/LanguageSwitch.tsx | 73 ++------ .../AutoComplete/AutoCompleteV2.tsx | 2 +- packages/plugins/ui-theme/src/i18n/config.ts | 15 +- .../ui-theme/src/i18n/crowdin/en-US.json | 170 ++++++++++++++++++ .../ui-theme/src/i18n/enabledLanguages.ts | 46 +++-- 6 files changed, 229 insertions(+), 81 deletions(-) create mode 100644 packages/plugins/ui-theme/src/i18n/crowdin/en-US.json diff --git a/crowdin.yaml b/crowdin.yaml index c6a2cd3ba..0b9060c2f 100644 --- a/crowdin.yaml +++ b/crowdin.yaml @@ -5,6 +5,10 @@ preserve_hierarchy: true files: [ + { + source: 'packages/plugins/ui-theme/src/i18n/crowdin/**/*', + translation: '/ui/i18n/%locale%/**/%original_file_name%', + }, { source: '/website/i18n/en/**/*', translation: '/website/i18n/%locale%/**/%original_file_name%', diff --git a/packages/plugins/ui-theme/src/App/Header/LanguageSwitch.tsx b/packages/plugins/ui-theme/src/App/Header/LanguageSwitch.tsx index 6fae65aa4..805520cbb 100644 --- a/packages/plugins/ui-theme/src/App/Header/LanguageSwitch.tsx +++ b/packages/plugins/ui-theme/src/App/Header/LanguageSwitch.tsx @@ -2,71 +2,24 @@ import styled from '@emotion/styled'; import { withStyles } from '@material-ui/core/styles'; import LanguageIcon from '@material-ui/icons/Language'; -import Flags from 'country-flag-icons/react/3x2'; -import i18next, { TFunctionKeys } from 'i18next'; +import i18next from 'i18next'; import React, { useCallback, useContext, useState, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import { Language } from 'src/i18n/enabledLanguages'; import { AutoComplete } from 'verdaccio-ui/components/AutoComplete/AutoCompleteV2'; import MenuItem from 'verdaccio-ui/components/MenuItem'; import { Theme } from 'verdaccio-ui/design-tokens/theme'; import ThemeContext from 'verdaccio-ui/design-tokens/ThemeContext'; -const lngDetails: Record = { - 'fr-FR': { - translation: 'lng.french', - icon: , - }, - 'pt-BR': { - translation: 'lng.portuguese', - icon: , - }, - 'de-DE': { - translation: 'lng.german', - icon: , - }, - 'es-ES': { - translation: 'lng.spanish', - icon: , - }, - 'zh-CN': { - translation: 'lng.chinese', - icon: , - }, - 'ru-RU': { - translation: 'lng.russian', - icon: , - }, - 'tr-TR': { - translation: 'lng.turkish', - icon: , - }, - 'uk-UA': { - translation: 'lng.ukraine', - icon: , - }, - 'km-KH': { - translation: 'lng.khmer', - icon: , - }, - 'ja-JP': { - translation: 'lng.japanese', - icon: , - }, - 'en-US': { - translation: 'lng.english', - icon: , - }, - 'cs-CZ': { - translation: 'lng.czech', - icon: , - }, - 'zh-TW': { - translation: 'lng.chineseTraditional', - icon: , - }, -}; +import { Language, listLanguages } from '../../i18n/enabledLanguages'; + +const listConverted = listLanguages.reduce((prev, item) => { + prev[item.lng] = { + translation: item.menuKey, + icon: item.icon, + }; + return prev; +}, {}); const LanguageSwitch = () => { const themeContext = useContext(ThemeContext); @@ -90,10 +43,10 @@ const LanguageSwitch = () => { const getCurrentLngDetails = useCallback( (language: Language) => { - const { icon, translation } = lngDetails[language] || lngDetails['en-US']; + const lng = listConverted[language] || listConverted['en-US']; return { - icon, - translation: t(translation), + icon: , + translation: t(lng.translation), }; }, [t] diff --git a/packages/plugins/ui-theme/src/components/AutoComplete/AutoCompleteV2.tsx b/packages/plugins/ui-theme/src/components/AutoComplete/AutoCompleteV2.tsx index cddf016da..3a21832e8 100644 --- a/packages/plugins/ui-theme/src/components/AutoComplete/AutoCompleteV2.tsx +++ b/packages/plugins/ui-theme/src/components/AutoComplete/AutoCompleteV2.tsx @@ -37,7 +37,7 @@ interface Props