This commit is contained in:
tangly1024
2021-09-27 09:33:21 +08:00
parent 22ca7f6d63
commit dfc0f645d4
76 changed files with 3650 additions and 2 deletions

34
lib/locale.js Normal file
View File

@@ -0,0 +1,34 @@
import BLOG from '@/blog.config'
import lang from './lang'
import { useContext, createContext } from 'react'
let locale = {}
if (BLOG.lang.slice(0, 2).toLowerCase() === 'zh') {
switch (BLOG.lang.toLowerCase()) {
case 'zh-cn':
case 'zh-sg':
locale = lang['zh-CN']
break
case 'zh-hk':
locale = lang['zh-HK']
break
case 'zh-tw':
locale = lang['zh-TW']
break
default:
locale = lang['zh-TW']
break
}
} else {
locale = lang.en
}
const LocaleContext = createContext()
export function LocaleProvider({ children }) {
return (
<LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>
)
}
export const useLocale = () => useContext(LocaleContext)