-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from visiky/intl
feat: 增加国际化
- Loading branch information
Showing
29 changed files
with
931 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.language-switcher { | ||
margin: 0 7px; | ||
display: inline-block; | ||
font-size: 12px; | ||
|
||
.divider { | ||
padding: 0 4px; | ||
} | ||
|
||
span.lang { | ||
&.unselected { | ||
color: rgba(255, 255, 255, 0.25); | ||
cursor: pointer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Popover } from 'antd'; | ||
import qs from 'query-string'; | ||
import { getLanguage, getLocale } from '@/locale'; | ||
import { getMode } from '@/hooks/useModeSwitcher'; | ||
import './index.less'; | ||
|
||
export const LangSwitcher = ({ className }: { className?: string }) => { | ||
const lang = getLanguage(); | ||
const mode = getMode(); | ||
const i18n = getLocale(); | ||
|
||
const changeLanguage = value => { | ||
if (value === lang) return; | ||
|
||
const { | ||
pathname, | ||
hash: currentHash, | ||
search: currentSearch, | ||
} = window.location; | ||
const hash = currentHash === '#/' ? '' : currentHash; | ||
const search = qs.stringify({ | ||
...qs.parse(currentSearch), | ||
lang: value, | ||
}); | ||
window.location.href = `${pathname}?${search}${hash}`; | ||
}; | ||
|
||
const RadioContent = ( | ||
<span> | ||
<span | ||
className={cx('lang', { unselected: lang !== 'zh_CN' })} | ||
onClick={() => changeLanguage('zh_CN')} | ||
> | ||
中 | ||
</span> | ||
<span className="divider">/</span> | ||
<span | ||
className={cx('lang', { unselected: lang !== 'en_US' })} | ||
onClick={() => changeLanguage('en_US')} | ||
> | ||
En | ||
</span> | ||
</span> | ||
); | ||
|
||
return ( | ||
<div className={cx('language-switcher', className)}> | ||
{mode === 'edit' ? ( | ||
<Popover | ||
content={i18n.get( | ||
'编辑模式下, 切换国际化会导致正在配置的内容丢失,请及时保存' | ||
)} | ||
placement="left" | ||
> | ||
{RadioContent} | ||
</Popover> | ||
) : ( | ||
{ RadioContent } | ||
)} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.