Skip to content

Commit

Permalink
refactor(ui): easier to add new language for i18n (#476)
Browse files Browse the repository at this point in the history
## What type of PR is this?

/kind refactor

## What this PR does / why we need it:

Easier to add new language for i18n of Web UI.

---------

Co-authored-by: hai-tian <[email protected]>
  • Loading branch information
elliotxx and hai-tian authored May 30, 2024
1 parent a11bd72 commit e95aa42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 2 additions & 6 deletions ui/src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { useTranslation } from 'react-i18next'
import showPng from '@/assets/show.png'
import logo from '@/assets/img/logo.svg'
import languageSvg from '@/assets/translate_language.svg'
import { Languages, LanguagesMap } from '@/utils/constants'

import styles from './style.module.less'
import { Languages } from '@/utils/constants'

type MenuItem = Required<MenuProps>['items'][number]

Expand Down Expand Up @@ -184,11 +184,7 @@ const LayoutPage = () => {
>
<img src={languageSvg} />
<span className={styles.help_text}>
{i18n.language === 'zh'
? '中文'
: i18n.language === 'de'
? 'Deutsch'
: 'English'}
{LanguagesMap?.[i18n.language || 'en']}
</span>
<CaretDownOutlined style={{ color: '#646566' }} />
</a>
Expand Down
8 changes: 7 additions & 1 deletion ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ function App() {
setLang(i18n.language)
}, [i18n.language])

const langMap = {
en: enUS,
zh: zhCN,
de: deDE,
}

return (
<Provider store={store}>
<ConfigProvider
locale={lang === 'en' ? enUS : lang === 'de' ? deDE : zhCN}
locale={langMap?.[lang || 'en']}
theme={{
token: {
colorPrimary: '#2F54EB',
Expand Down
6 changes: 6 additions & 0 deletions ui/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ export const Languages = [
value: 'de',
},
]

export const LanguagesMap = {
zh: '简体中文',
en: 'English',
de: 'Deutsch',
}

0 comments on commit e95aa42

Please sign in to comment.