INNER CODE UNIT · TypeScript
switchLocale
troyzhxu/bean-searcher · bean-searcher-demos/frontend-vue/src/i18n/index.ts:33
export function switchLocale(locale?: Locale): string {
const current = i18n.global.locale.value as Locale
const next: Locale = locale || (current === 'zh-CN' ? 'en-US' : 'zh-CN')
i18n.global.locale.value = next
localStorage.setItem(STORAGE_KEY, next)
document.documentElement.lang = next
return next
}
/** 获取当前 locale */
export function getCurrentLocale(): string {
return i18n.global.locale.value
}
export default i18n