You can not 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
778 B
33 lines
778 B
import { useStore, Language } from '@/store'
|
|
import { chineseLanguageLoader } from '@/i18n/util'
|
|
|
|
export const useSetLanguage = () => {
|
|
return {
|
|
setLanguage(language: Language) {
|
|
const store = useStore()
|
|
store.setLanguage(language)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const useSwitchLanguage = () => {
|
|
return {
|
|
switchLanguage(map: Record<string, any>, key: string) {
|
|
const store = useStore()
|
|
const language = store.language
|
|
if (language === 'zh') {
|
|
return map[key]
|
|
}
|
|
|
|
if (language === 'en' && map[key + 'En']) {
|
|
return map[key + 'En']
|
|
} else if (language === 'en' && !map[key + 'En']) {
|
|
return map[key]
|
|
}
|
|
|
|
if (language === 'tw') {
|
|
return chineseLanguageLoader(map[key])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|