@@ -14,7 +14,7 @@ export function useLocale() {
1414 const cidReqStore = useCidReqStore ( )
1515 const courseSettingsStore = useCourseSettings ( )
1616
17- const appLocale = ref ( document . querySelector ( "html" ) . lang )
17+ const appLocale = ref ( document . documentElement . dataset . lang )
1818
1919 const localeList = computed ( ( ) => {
2020 const list = { }
@@ -68,7 +68,7 @@ export function useLocale() {
6868 * @type {{originalName: string, isocode: string} }
6969 */
7070 const currentLanguageFromList =
71- languageList . find ( ( language ) => document . querySelector ( "html" ) . lang === language . isocode ) || defaultLanguage
71+ languageList . find ( ( language ) => document . documentElement . dataset . lang === language . isocode ) || defaultLanguage
7272
7373 /**
7474 * @param {string } isoCode
@@ -99,9 +99,9 @@ export function useLocale() {
9999 if ( ! iso ) return { db : "" , bcp47 : "" , parent : "" }
100100 const u = String ( iso ) . trim ( )
101101 return {
102- db : u . replace ( "-" , "_" ) , // pt-BR -> pt_BR (DB)
103- bcp47 : u . replace ( "_" , "-" ) , // pt_BR -> pt-BR (BCP-47)
104- parent : u . split ( / [ - _ ] / ) [ 0 ] , // pt_BR -> pt
102+ db : u . replace ( "-" , "_" ) , // pt-BR -> pt_BR (DB)
103+ bcp47 : u . replace ( "_" , "-" ) , // pt_BR -> pt-BR (BCP-47)
104+ parent : u . split ( / [ - _ ] / ) [ 0 ] , // pt_BR -> pt
105105 }
106106 }
107107
@@ -112,7 +112,7 @@ export function useLocale() {
112112 function getLanguageName ( iso , displayLocale = null ) {
113113 if ( ! iso ) return "-"
114114 const tag = String ( iso ) . replace ( "_" , "-" )
115- const ui = displayLocale || appLocale . value || document . documentElement . lang || "en"
115+ const ui = displayLocale || appLocale . value || document . documentElement . dataset . lang || "en"
116116 try {
117117 const dn = new Intl . DisplayNames ( [ ui ] , { type : "language" } )
118118 return dn . of ( tag ) || iso . toUpperCase ( )
@@ -144,12 +144,7 @@ export function useLocale() {
144144 if ( ! row && bcp47 !== db ) row = await hit ( bcp47 )
145145 if ( ! row && parent && parent !== db ) row = await hit ( parent )
146146
147- const name =
148- row ?. originalName ||
149- row ?. original_name ||
150- row ?. englishName ||
151- row ?. english_name ||
152- iso . toUpperCase ( )
147+ const name = row ?. originalName || row ?. original_name || row ?. englishName || row ?. english_name || iso . toUpperCase ( )
153148
154149 __apiLangCache . set ( iso , name )
155150 return name
0 commit comments