From e1023bb3313282b00d6dcdefd5d7e30d7aaa1bfc Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 30 十一月 2023 11:13:29 +0800 Subject: [PATCH] update 优化 代码中存在的警告 --- src/lang/index.ts | 44 +++++++++++++++++--------------------------- 1 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/lang/index.ts b/src/lang/index.ts index 1048211..dddb86b 100644 --- a/src/lang/index.ts +++ b/src/lang/index.ts @@ -2,44 +2,34 @@ import { createI18n } from 'vue-i18n'; // 鏈湴璇█鍖� -import enLocale from './en'; -import zhCnLocale from './zh-cn'; +import enUSLocale from './en_US'; +import zhCNLocale from './zh_CN'; const messages = { - 'zh-cn': { - ...zhCnLocale - }, - en: { - ...enLocale - } + zh_CN: { + ...zhCNLocale + }, + en_US: { + ...enUSLocale + } }; /** - * 鑾峰彇褰撳墠绯荤粺浣跨敤璇█瀛楃涓� - * + * 鑾峰彇褰撳墠璇█ * @returns zh-cn|en ... */ export const getLanguage = () => { - // 鏈湴缂撳瓨鑾峰彇 - let language = localStorage.getItem('language'); - if (language) { - return language; - } - // 娴忚鍣ㄤ娇鐢ㄨ瑷� - language = navigator.language.toLowerCase(); - const locales = Object.keys(messages); - for (const locale of locales) { - if (language.indexOf(locale) > -1) { - return locale; - } - } - return 'zh-cn'; + const language = useStorage('language', 'zh_CN'); + if (language.value) { + return language.value; + } + return 'zh_CN'; }; const i18n = createI18n({ - legacy: false, - locale: getLanguage(), - messages: messages + legacy: false, + locale: getLanguage(), + messages }); export default i18n; -- Gitblit v1.9.3