Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
},
"lng": {
"english": "Englisch",
"japanese": "Japanisch",
"portuguese": "Portugiesisch",
"spanish": "Spanisch",
"german": "Deutsch",
Expand Down
3 changes: 2 additions & 1 deletion i18n/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
},
"lng": {
"english": "English",
"japanese": "Japanese",
"portuguese": "Portuguese",
"spanish": "Spanish",
"german": "German",
Expand All @@ -146,4 +147,4 @@
},
"help-to-translate": "Help to translate",
"change-language": "Change language"
}
}
1 change: 1 addition & 0 deletions i18n/translations/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
},
"lng": {
"english": "Inglés",
"japanese": "Japonés",
"portuguese": "Portugués",
"spanish": "Español",
"german": "Alemán",
Expand Down
3 changes: 2 additions & 1 deletion i18n/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
},
"lng": {
"english": "Anglaise",
"japanese": "Japonaise",
"portuguese": "Portugaise",
"spanish": "Espagnol",
"german": "Allemande",
Expand All @@ -146,4 +147,4 @@
},
"help-to-translate": "Aide à traduire",
"change-language": "Changer la langue"
}
}
15 changes: 13 additions & 2 deletions i18n/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,16 @@
"app-context-not-correct-used": "AppContextが正しく使用されませんでした",
"theme-context-not-correct-used": "ThemeContextが正しく使用されませんでした",
"package-meta-is-required-at-detail-context": "DetailContextではpackageMetaが必要です"
}
}
},
"lng": {
"english": "英語",
"japanese": "日本語",
"portuguese": "ポルトガル語",
"spanish": "スペイン語",
"german": "ドイツ語",
"chinese": "中国語",
"french": "フランス語"
},
"help-to-translate": "翻訳を助ける",
"change-language": "言語を変更"
}
3 changes: 2 additions & 1 deletion i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
},
"lng": {
"english": "Inglês",
"japanese": "Japonês",
"portuguese": "Português",
"spanish": "Espanhol",
"german": "Alemão",
Expand All @@ -146,4 +147,4 @@
},
"help-to-translate": "Ajude a traduzir",
"change-language": "Mudar idioma"
}
}
3 changes: 2 additions & 1 deletion i18n/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
},
"lng": {
"english": "英語",
"japanese": "日語",
"portuguese": "葡萄牙語",
"spanish": "西班牙文",
"german": "德語",
Expand All @@ -145,4 +146,4 @@
},
"help-to-translate": "幫助翻譯",
"change-language": "改變語言"
}
}
3 changes: 3 additions & 0 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import austria from './img/austria.svg';
import spain from './img/spain.svg';
import usa from './img/usa.svg';
import france from './img/france.svg';
import japan from './img/japan.svg';
import earth from './img/earth.svg';
import verdaccio from './img/verdaccio.svg';
import filebinary from './img/filebinary.svg';
Expand All @@ -32,6 +33,7 @@ export interface IconsMap {
france: string;
germany: string;
india: string;
japan: string;
earth: string;
verdaccio: string;
license: string;
Expand Down Expand Up @@ -60,6 +62,7 @@ export const Icons: IconsMap = {
germany,
usa,
france,
japan,
};

export interface Props {
Expand Down
1 change: 1 addition & 0 deletions src/components/Icon/img/japan.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 45 additions & 32 deletions src/components/LanguageSwitch/LanguageSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Grow from '@material-ui/core/Grow';
import Popper from '@material-ui/core/Popper';
import MenuList from '@material-ui/core/MenuList';
import styled from '@emotion/styled';
import { css } from '@emotion/core';

import { Language } from '../../../i18n/config';
import ThemeContext from '../../design-tokens/ThemeContext';
Expand All @@ -25,34 +24,48 @@ import Icon from '../Icon';

const VERDACCIO_UI_GITHUB_REPOSITORY = 'https://github.com/verdaccio/ui';

const getTranslatedCurrentLanguage = (
t: TFunction
): { [key: string]: { translation: string; icon: React.ComponentProps<typeof Icon>['name'] } } => ({
'en-us': {
translation: t('lng.english'),
icon: 'usa',
},
'fr-fr': {
translation: t('lng.french'),
icon: 'france',
},
'pt-br': {
translation: t('lng.portuguese'),
icon: 'brazil',
},
'de-de': {
translation: t('lng.german'),
icon: 'germany',
},
'es-es': {
translation: t('lng.spanish'),
icon: 'spain',
},
'zh-cn': {
translation: t('lng.chinese'),
icon: 'china',
},
});
const getTranslatedCurrentLanguageDetails = (
t: TFunction,
currentLanguage: string
): { translation: string; icon: React.ComponentProps<typeof Icon>['name'] } => {
switch (currentLanguage) {
case 'fr-FR':
return {
translation: t('lng.french'),
icon: 'france',
};
case 'pt-BR':
return {
translation: t('lng.portuguese'),
icon: 'brazil',
};
case 'de-DE':
return {
translation: t('lng.german'),
icon: 'germany',
};
case 'es-ES':
return {
translation: t('lng.spanish'),
icon: 'spain',
};
case 'zh-CN':
return {
translation: t('lng.chinese'),
icon: 'china',
};
case 'ja-JP':
return {
translation: t('lng.japanese'),
icon: 'japan',
};
default:
return {
translation: t('lng.english'),
icon: 'usa',
};
}
};

const LanguageSwitch = () => {
const themeContext = useContext(ThemeContext);
Expand All @@ -65,9 +78,9 @@ const LanguageSwitch = () => {
}

const languages = (i18next.options.resources ? Object.keys(i18next.options.resources) : []) as Array<Language>;
const currentLanguage: Language = i18next.language || i18next.options?.fallbackLng?.[0];
const currentLanguage = themeContext.language;

const { translation: userLanguage } = getTranslatedCurrentLanguage(t)[currentLanguage.toLowerCase()];
const { translation: userLanguage } = getTranslatedCurrentLanguageDetails(t, currentLanguage);

const handleToggle = useCallback(() => {
setOpen(prevOpen => !prevOpen);
Expand Down Expand Up @@ -124,7 +137,7 @@ const LanguageSwitch = () => {
{languages
.filter(language => language !== currentLanguage)
.map(language => {
const { icon, translation } = getTranslatedCurrentLanguage(t)[language.toLowerCase()];
const { icon, translation } = getTranslatedCurrentLanguageDetails(t, language);
return (
<StyledMenuItem
key={language}
Expand Down
4 changes: 1 addition & 3 deletions src/design-tokens/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
import { ThemeProvider as EmotionThemeProvider } from 'emotion-theming';
import i18next from 'i18next';

import { Language } from '../../i18n/config';

import ThemeContext from './ThemeContext';
import { getTheme, ThemeMode } from './theme';
import useLocalStorage from './useLocalStorage';

const ThemeProvider: React.FC = ({ children }) => {
const isDarkModeDefault = window?.__VERDACCIO_BASENAME_UI_OPTIONS?.darkMode;
const currentLanguage: Language = i18next.language || i18next.options?.fallbackLng?.[0];
const currentLanguage = i18next.languages?.[0];

const [isDarkMode, setIsDarkMode] = useLocalStorage('darkMode', !!isDarkModeDefault);
const [language, setLanguage] = useLocalStorage('language', currentLanguage);
Expand Down