@zachhandley/ez-i18n 0.3.11 → 0.3.13
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/dist/index.js +11 -4
- package/dist/middleware.js +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -397,10 +397,12 @@ function vitePlugin(config) {
|
|
|
397
397
|
};
|
|
398
398
|
useCache = true;
|
|
399
399
|
for (const [locale, files] of Object.entries(cache.discovered)) {
|
|
400
|
+
const filesInPublic = files.length > 0 && isInPublicDir(files[0], projectRoot);
|
|
400
401
|
translationInfo.set(locale, {
|
|
401
402
|
locale,
|
|
402
403
|
files,
|
|
403
|
-
localeBaseDir: localeBaseDirs[locale]
|
|
404
|
+
localeBaseDir: localeBaseDirs[locale],
|
|
405
|
+
isPublic: filesInPublic
|
|
404
406
|
});
|
|
405
407
|
}
|
|
406
408
|
}
|
|
@@ -894,7 +896,7 @@ function __deepMerge(target, ...sources) {
|
|
|
894
896
|
function getPublicLoaderCode() {
|
|
895
897
|
return `
|
|
896
898
|
async function __loadPublicJson(url, absolutePath) {
|
|
897
|
-
// Browser environment - use fetch
|
|
899
|
+
// Browser environment - use fetch with relative URL
|
|
898
900
|
if (typeof window !== 'undefined') {
|
|
899
901
|
return fetch(url).then(r => r.json());
|
|
900
902
|
}
|
|
@@ -907,8 +909,13 @@ async function __loadPublicJson(url, absolutePath) {
|
|
|
907
909
|
!globalThis.process?.versions?.node; // No Node.js process
|
|
908
910
|
|
|
909
911
|
if (isEdgeRuntime) {
|
|
910
|
-
// Edge runtime -
|
|
911
|
-
|
|
912
|
+
// Edge runtime - need absolute URL for fetch
|
|
913
|
+
// Priority: Astro site config > middleware-set origin > relative (hope for the best)
|
|
914
|
+
const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
|
|
915
|
+
globalThis.__EZ_I18N_ORIGIN__ ||
|
|
916
|
+
'';
|
|
917
|
+
const fetchUrl = origin ? origin + url : url;
|
|
918
|
+
return fetch(fetchUrl).then(r => r.json());
|
|
912
919
|
}
|
|
913
920
|
|
|
914
921
|
// Traditional Node.js SSR - read from filesystem
|
package/dist/middleware.js
CHANGED
|
@@ -40,6 +40,9 @@ var onRequest = defineMiddleware(async ({ cookies, request, locals, redirect },
|
|
|
40
40
|
}
|
|
41
41
|
locals.locale = locale;
|
|
42
42
|
try {
|
|
43
|
+
if (!import.meta.env.SITE && !globalThis.__EZ_I18N_ORIGIN__) {
|
|
44
|
+
globalThis.__EZ_I18N_ORIGIN__ = url.origin;
|
|
45
|
+
}
|
|
43
46
|
const { loadTranslations } = await import("ez-i18n:translations");
|
|
44
47
|
locals.translations = await loadTranslations(locale);
|
|
45
48
|
globalThis.__EZ_I18N_SSR__ = {
|