mnfst 0.5.35 → 0.5.36
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.
|
@@ -89,6 +89,20 @@ function initializeLocalizationPlugin() {
|
|
|
89
89
|
return rtlLanguages.has(lang);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
function isPrerenderedStaticBuild() {
|
|
93
|
+
return document.head?.querySelector('meta[name="manifest:prerendered"][content="1"]') !== null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildLocaleNavigationUrl(newLang, availableLocales) {
|
|
97
|
+
const currentUrl = new URL(window.location.href);
|
|
98
|
+
const pathParts = currentUrl.pathname.split('/').filter(Boolean);
|
|
99
|
+
const hasLanguageInUrl = pathParts[0] && availableLocales.includes(pathParts[0]);
|
|
100
|
+
if (hasLanguageInUrl) pathParts[0] = newLang;
|
|
101
|
+
else pathParts.unshift(newLang);
|
|
102
|
+
currentUrl.pathname = '/' + pathParts.join('/');
|
|
103
|
+
return currentUrl.toString();
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
// Input validation for language codes
|
|
93
107
|
function isValidLanguageCode(lang) {
|
|
94
108
|
if (typeof lang !== 'string' || lang.length === 0) return false;
|
|
@@ -313,6 +327,16 @@ function initializeLocalizationPlugin() {
|
|
|
313
327
|
|
|
314
328
|
|
|
315
329
|
try {
|
|
330
|
+
// In prerendered static output, locale switching must navigate to a locale URL.
|
|
331
|
+
// Mutating Alpine store alone won't re-render baked static content.
|
|
332
|
+
if (isPrerenderedStaticBuild()) {
|
|
333
|
+
const targetUrl = buildLocaleNavigationUrl(newLang, store.available || []);
|
|
334
|
+
if (targetUrl !== window.location.href) {
|
|
335
|
+
window.location.assign(targetUrl);
|
|
336
|
+
}
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
|
|
316
340
|
// Update store
|
|
317
341
|
store.current = newLang;
|
|
318
342
|
store.direction = isRTL(newLang) ? 'rtl' : 'ltr';
|