From b098c284e1e03a07d954a567b7cf3cb2763b71e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Thu, 24 Mar 2022 23:56:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(lang/index.ts):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=9B=BD=E9=99=85=E5=8C=96=E7=A7=BB=E9=99=A4Element?= =?UTF-8?q?=20Plus=E8=AF=AD=E8=A8=80=E5=8C=85=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lang/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lang/index.ts b/src/lang/index.ts index 834384ab..b56f979d 100644 --- a/src/lang/index.ts +++ b/src/lang/index.ts @@ -1,32 +1,34 @@ + +// 自定义国际化配置 import {createI18n} from 'vue-i18n' import {localStorage} from '@/utils/storage' -// Element Plus 国际化配置 -import elementPlusLocaleZhCn from 'element-plus/es/locale/lang/zh-cn' -import elementPlusLocaleEn from 'element-plus/es/locale/lang/en' - -// 自定义国际化配置 +// 本地语言包 import enLocale from './en' import zhCnLocale from './zh-cn' -import {Locale, Path} from "@intlify/core-base"; const messages = { 'zh-cn': { - ...zhCnLocale, - ...elementPlusLocaleZhCn + ...zhCnLocale }, en: { - ...enLocale, - ...elementPlusLocaleEn + ...enLocale } } +/** + * 获取当前系统使用语言字符串 + * + * @returns zh-cn|en ... + */ export const getLanguage = () => { + // 本地缓存获取 let language = localStorage.get('language') if (language) { return language } - language = navigator.language.toLowerCase() // 浏览器使用的语言 + // 浏览器使用语言 + language = navigator.language.toLowerCase() const locales = Object.keys(messages) for (const locale of locales) { if (language.indexOf(locale) > -1) {