fix(i18n): reload after change language
This commit is contained in:
parent
b4eb35d86a
commit
a97d6f024b
@ -1,6 +1,6 @@
|
|||||||
import { FC } from 'react'
|
import { FC } from 'react'
|
||||||
import { SettingContainer, SettingDivider, SettingRow, SettingRowTitle, SettingTitle } from './components'
|
import { SettingContainer, SettingDivider, SettingRow, SettingRowTitle, SettingTitle } from './components'
|
||||||
import { Avatar, message, Select, Upload } from 'antd'
|
import { Avatar, Select, Upload } from 'antd'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import LocalStorage from '@renderer/services/storage'
|
import LocalStorage from '@renderer/services/storage'
|
||||||
import { compressImage } from '@renderer/utils'
|
import { compressImage } from '@renderer/utils'
|
||||||
@ -14,7 +14,6 @@ import i18next from 'i18next'
|
|||||||
|
|
||||||
const GeneralSettings: FC = () => {
|
const GeneralSettings: FC = () => {
|
||||||
const avatar = useAvatar()
|
const avatar = useAvatar()
|
||||||
const [messageApi, contextHolder] = message.useMessage()
|
|
||||||
const { language } = useSettings()
|
const { language } = useSettings()
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -22,14 +21,26 @@ const GeneralSettings: FC = () => {
|
|||||||
const onSelectLanguage = (value: string) => {
|
const onSelectLanguage = (value: string) => {
|
||||||
dispatch(setLanguage(value))
|
dispatch(setLanguage(value))
|
||||||
i18next.changeLanguage(value)
|
i18next.changeLanguage(value)
|
||||||
// window.location.reload()
|
setTimeout(() => window.location.reload(), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingContainer>
|
<SettingContainer>
|
||||||
{contextHolder}
|
|
||||||
<SettingTitle>{t('settings.general.title')}</SettingTitle>
|
<SettingTitle>{t('settings.general.title')}</SettingTitle>
|
||||||
<SettingDivider />
|
<SettingDivider />
|
||||||
|
<SettingRow>
|
||||||
|
<SettingRowTitle>{t('common.language')}</SettingRowTitle>
|
||||||
|
<Select
|
||||||
|
defaultValue={language || 'en-US'}
|
||||||
|
style={{ width: 120 }}
|
||||||
|
onChange={onSelectLanguage}
|
||||||
|
options={[
|
||||||
|
{ value: 'zh-CN', label: '中文' },
|
||||||
|
{ value: 'en-US', label: 'English' }
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
<SettingDivider />
|
||||||
<SettingRow>
|
<SettingRow>
|
||||||
<SettingRowTitle>{t('common.avatar')}</SettingRowTitle>
|
<SettingRowTitle>{t('common.avatar')}</SettingRowTitle>
|
||||||
<Upload
|
<Upload
|
||||||
@ -44,29 +55,13 @@ const GeneralSettings: FC = () => {
|
|||||||
await LocalStorage.storeImage('avatar', compressedFile)
|
await LocalStorage.storeImage('avatar', compressedFile)
|
||||||
dispatch(setAvatar(await LocalStorage.getImage('avatar')))
|
dispatch(setAvatar(await LocalStorage.getImage('avatar')))
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
messageApi.open({
|
window.message.error(error.message)
|
||||||
type: 'error',
|
|
||||||
content: error.message
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<UserAvatar src={avatar} size="large" />
|
<UserAvatar src={avatar} size="large" />
|
||||||
</Upload>
|
</Upload>
|
||||||
</SettingRow>
|
</SettingRow>
|
||||||
<SettingDivider />
|
<SettingDivider />
|
||||||
<SettingRow>
|
|
||||||
<SettingRowTitle>{t('common.language')}</SettingRowTitle>
|
|
||||||
<Select
|
|
||||||
defaultValue={language || 'en-US'}
|
|
||||||
style={{ width: 120 }}
|
|
||||||
onChange={onSelectLanguage}
|
|
||||||
options={[
|
|
||||||
{ value: 'zh-CN', label: '中文' },
|
|
||||||
{ value: 'en-US', label: 'English' }
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</SettingRow>
|
|
||||||
<SettingDivider />
|
|
||||||
</SettingContainer>
|
</SettingContainer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user