From eca8907a11c28d816c3da5a0667f45a38a499012 Mon Sep 17 00:00:00 2001
From: 江麻妞 <50100681+jiangmaniu@users.noreply.github.com>
Date: Tue, 1 Jun 2021 21:37:59 +0800
Subject: [PATCH] fix: Fix the problem that the `lang` attribute of `HTML` will not be set when it is first loaded (#682)

---
 src/locales/setupI18n.ts | 5 +++--
 src/locales/useLocale.ts | 6 +++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/locales/setupI18n.ts b/src/locales/setupI18n.ts
index 2801a93..799736c 100644
--- a/src/locales/setupI18n.ts
+++ b/src/locales/setupI18n.ts
@@ -3,7 +3,7 @@ import type { I18n, I18nOptions } from 'vue-i18n';
 
 import { createI18n } from 'vue-i18n';
 
-import { setLoadLocalePool } from './useLocale';
+import { setLoadLocalePool, setHtmlPageLang } from './useLocale';
 import { localeSetting } from '/@/settings/localeSetting';
 import { useLocaleStoreWithOut } from '/@/store/modules/locale';
 
@@ -16,7 +16,8 @@ async function createI18nOptions(): Promise<I18nOptions> {
   const locale = localeStore.getLocale;
   const defaultLocal = await import(`./lang/${locale}.ts`);
   const message = defaultLocal.default?.message ?? {};
-
+  
+  setHtmlPageLang(locale)
   setLoadLocalePool((loadLocalePool) => {
     loadLocalePool.push(locale);
   });
diff --git a/src/locales/useLocale.ts b/src/locales/useLocale.ts
index f4f5b8f..07b0a81 100644
--- a/src/locales/useLocale.ts
+++ b/src/locales/useLocale.ts
@@ -17,6 +17,10 @@ interface LangModule {
 
 const loadLocalePool: LocaleType[] = [];
 
+export function setHtmlPageLang(locale: LocaleType) {
+  document.querySelector('html')?.setAttribute('lang', locale);
+}
+
 export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
   cb(loadLocalePool);
 }
@@ -30,7 +34,7 @@ function setI18nLanguage(locale: LocaleType) {
     (i18n.global.locale as any).value = locale;
   }
   localeStore.setLocaleInfo({ locale });
-  document.querySelector('html')?.setAttribute('lang', locale);
+  setHtmlPageLang(locale)
 }
 
 export function useLocale() {
--
libgit2 0.23.3