@zachhandley/ez-i18n 0.3.13 → 0.3.14
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 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -896,31 +896,24 @@ function __deepMerge(target, ...sources) {
|
|
|
896
896
|
function getPublicLoaderCode() {
|
|
897
897
|
return `
|
|
898
898
|
async function __loadPublicJson(url, absolutePath) {
|
|
899
|
-
// Browser
|
|
899
|
+
// Browser - use fetch with relative URL
|
|
900
900
|
if (typeof window !== 'undefined') {
|
|
901
901
|
return fetch(url).then(r => r.json());
|
|
902
902
|
}
|
|
903
903
|
|
|
904
|
-
//
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
typeof Deno !== 'undefined' || // Deno
|
|
909
|
-
!globalThis.process?.versions?.node; // No Node.js process
|
|
904
|
+
// Get origin from Astro site config or middleware-set value
|
|
905
|
+
const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
|
|
906
|
+
globalThis.__EZ_I18N_ORIGIN__ ||
|
|
907
|
+
'';
|
|
910
908
|
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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());
|
|
909
|
+
// If we have an origin, use fetch (works in CF Workers, Vercel Edge, etc.)
|
|
910
|
+
if (origin) {
|
|
911
|
+
return fetch(origin + url).then(r => r.json());
|
|
919
912
|
}
|
|
920
913
|
|
|
921
|
-
//
|
|
922
|
-
const
|
|
923
|
-
const content =
|
|
914
|
+
// No origin - try filesystem (traditional Node.js SSR)
|
|
915
|
+
const { readFileSync } = await import('node:fs');
|
|
916
|
+
const content = readFileSync(absolutePath, 'utf-8');
|
|
924
917
|
return JSON.parse(content);
|
|
925
918
|
}`;
|
|
926
919
|
}
|