We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a4f5dd4 commit 505e112Copy full SHA for 505e112
1 file changed
src/locales/locales.ts
@@ -76,6 +76,25 @@ export async function matchLanguage() {
76
return lng;
77
}
78
79
+ // 根据前缀去匹配
80
+ const prefixMap = i18n.languages.reduce(
81
+ (acc, lng) => {
82
+ const prefix = lng.split("-")[0];
83
+ if (!acc[prefix]) {
84
+ acc[prefix] = [];
85
+ }
86
+ acc[prefix].push(lng);
87
+ return acc;
88
+ },
89
+ {} as Record<string, string[]>
90
+ );
91
+ for (let i = 0; i < acceptLanguages.length; i += 1) {
92
+ const lng = acceptLanguages[i];
93
94
+ if (prefixMap[prefix] && prefixMap[prefix].length > 0) {
95
+ return prefixMap[prefix][0]; // 返回第一个匹配的语言
96
97
98
return "";
99
100
0 commit comments