@zachhandley/ez-i18n 0.3.12 → 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 +14 -19
- 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,31 +896,24 @@ function __deepMerge(target, ...sources) {
|
|
|
894
896
|
function getPublicLoaderCode() {
|
|
895
897
|
return `
|
|
896
898
|
async function __loadPublicJson(url, absolutePath) {
|
|
897
|
-
// Browser
|
|
899
|
+
// Browser - use fetch with relative URL
|
|
898
900
|
if (typeof window !== 'undefined') {
|
|
899
901
|
return fetch(url).then(r => r.json());
|
|
900
902
|
}
|
|
901
903
|
|
|
902
|
-
//
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
typeof Deno !== 'undefined' || // Deno
|
|
907
|
-
!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
|
+
'';
|
|
908
908
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
|
|
913
|
-
globalThis.__EZ_I18N_ORIGIN__ ||
|
|
914
|
-
'';
|
|
915
|
-
const fetchUrl = origin ? origin + url : url;
|
|
916
|
-
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());
|
|
917
912
|
}
|
|
918
913
|
|
|
919
|
-
//
|
|
920
|
-
const
|
|
921
|
-
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');
|
|
922
917
|
return JSON.parse(content);
|
|
923
918
|
}`;
|
|
924
919
|
}
|