You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
793 B
TypeScript
33 lines
793 B
TypeScript
import zhLocal from './zh-CN'
|
|
import zhTWLocal from './zh-TW'
|
|
import enUSLocal from './en-US'
|
|
import itITLocal from './it-IT'
|
|
import koKRLocal from './ko-KR'
|
|
|
|
const locales = {
|
|
'zh-CN': zhLocal,
|
|
'zh-TW': zhTWLocal,
|
|
'en-US': enUSLocal,
|
|
'it-IT': itITLocal,
|
|
'ko-KR': koKRLocal
|
|
}
|
|
|
|
type GLocaleWindow = {
|
|
g_locale: keyof typeof locales
|
|
}
|
|
|
|
export type LocaleType = keyof typeof locales
|
|
|
|
export const getLanguage = (): string => {
|
|
// support ssr
|
|
// if (!isBrowser()) return 'zh-CN'
|
|
const lang = window.localStorage.getItem('umi_locale')
|
|
return lang || (window as unknown as GLocaleWindow).g_locale || navigator.language
|
|
}
|
|
|
|
export const gLocaleObject = (): Record<string, string> => {
|
|
const gLocale = getLanguage()
|
|
// @ts-ignore
|
|
return locales[gLocale] || locales['zh-CN']
|
|
}
|