@schukai/monster 4.38.10 → 4.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/source/i18n/util.mjs
CHANGED
@@ -96,7 +96,7 @@ export function detectUserLanguagePreference() {
|
|
96
96
|
}
|
97
97
|
|
98
98
|
const availableLanguages = [...linkTags].map((link) => {
|
99
|
-
const fullLang = link.hreflang;
|
99
|
+
const fullLang = link.getAttribute("hreflang");
|
100
100
|
const baseLang = fullLang.split("-")[0];
|
101
101
|
let label = link.getAttribute("data-monster-label");
|
102
102
|
if (!label) {
|
@@ -113,7 +113,7 @@ export function detectUserLanguagePreference() {
|
|
113
113
|
fullLang,
|
114
114
|
baseLang,
|
115
115
|
label,
|
116
|
-
href: link.href,
|
116
|
+
href: link.getAttribute("href"),
|
117
117
|
};
|
118
118
|
});
|
119
119
|
|
@@ -124,6 +124,10 @@ export function detectUserLanguagePreference() {
|
|
124
124
|
preferredLanguages.includes(lang.baseLang),
|
125
125
|
);
|
126
126
|
|
127
|
+
const allOfferableLanguages = availableLanguages.filter(
|
128
|
+
(lang) => lang.baseLang !== currentLang && lang.fullLang !== currentLang,
|
129
|
+
);
|
130
|
+
|
127
131
|
if (offerableLanguages.length === 0) {
|
128
132
|
return {
|
129
133
|
current: currentLang || null,
|
@@ -132,6 +136,7 @@ export function detectUserLanguagePreference() {
|
|
132
136
|
...lang,
|
133
137
|
weight: 1,
|
134
138
|
})),
|
139
|
+
allOfferable: allOfferableLanguages,
|
135
140
|
};
|
136
141
|
}
|
137
142
|
|
@@ -154,7 +159,7 @@ export function detectUserLanguagePreference() {
|
|
154
159
|
|
155
160
|
const currentLabel = languages?.[currentLang] || currentLang;
|
156
161
|
|
157
|
-
// If we found a language that matches user preferences (weight >
|
162
|
+
// If we found a language that matches user preferences (weight > 0)
|
158
163
|
if (bestMatchWeight > 0) {
|
159
164
|
return {
|
160
165
|
current: currentLang || null,
|
@@ -173,6 +178,7 @@ export function detectUserLanguagePreference() {
|
|
173
178
|
...lang,
|
174
179
|
weight: getWeight(lang),
|
175
180
|
})),
|
181
|
+
allOfferable: allOfferableLanguages,
|
176
182
|
};
|
177
183
|
}
|
178
184
|
|
@@ -184,5 +190,6 @@ export function detectUserLanguagePreference() {
|
|
184
190
|
...lang,
|
185
191
|
weight: getWeight(lang),
|
186
192
|
})),
|
193
|
+
allOfferable: allOfferableLanguages,
|
187
194
|
};
|
188
195
|
}
|