File tree 1 file changed +5
-10
lines changed
1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -21,16 +21,11 @@ export const languageColumns: PickerColumn = [
21
21
/** 获取当前语言对应的语言包名称 */
22
22
function getI18nLocale ( ) {
23
23
const storedLocale = localStorage . getItem ( 'language' ) || navigator . language
24
- let locale = FALLBACK_LOCALE // 默认语言包
25
- for ( const l of languageColumns ) {
26
- const value = l . value as string
27
- if ( value === storedLocale // 存在当前语言的语言包
28
- || value . indexOf ( storedLocale ) === 0 // 存在当前语言的任意地区的语言包
29
- ) {
30
- locale = value
31
- break
32
- }
33
- }
24
+
25
+ const langs = languageColumns . map ( v => v . value as string )
26
+ const foundLocale = langs . find ( v => v === storedLocale || v . indexOf ( storedLocale ) === 0 ) // 存在当前语言的语言包 或 存在当前语言的任意地区的语言包
27
+ const locale = foundLocale || FALLBACK_LOCALE // 若未找到,则使用 默认语言包
28
+
34
29
document . querySelector ( 'html' ) . setAttribute ( 'lang' , locale )
35
30
return locale
36
31
}
You can’t perform that action at this time.
0 commit comments