@zachhandley/ez-i18n 0.3.9 → 0.3.11

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -894,15 +894,27 @@ function __deepMerge(target, ...sources) {
894
894
  function getPublicLoaderCode() {
895
895
  return `
896
896
  async function __loadPublicJson(url, absolutePath) {
897
+ // Browser environment - use fetch
897
898
  if (typeof window !== 'undefined') {
898
- // Browser - use fetch with relative URL
899
899
  return fetch(url).then(r => r.json());
900
- } else {
901
- // SSR/Node - read from filesystem
902
- const fs = await import('node:fs');
903
- const content = fs.readFileSync(absolutePath, 'utf-8');
904
- return JSON.parse(content);
905
900
  }
901
+
902
+ // Edge runtime detection (Cloudflare Workers, Vercel Edge, Deno, etc.)
903
+ // These environments have fetch but no filesystem access
904
+ const isEdgeRuntime = typeof globalThis.caches !== 'undefined' || // CF Workers / Service Workers
905
+ typeof globalThis.EdgeRuntime !== 'undefined' || // Vercel Edge
906
+ typeof Deno !== 'undefined' || // Deno
907
+ !globalThis.process?.versions?.node; // No Node.js process
908
+
909
+ if (isEdgeRuntime) {
910
+ // Edge runtime - use fetch (relative URLs work in request context)
911
+ return fetch(url).then(r => r.json());
912
+ }
913
+
914
+ // Traditional Node.js SSR - read from filesystem
915
+ const fs = await import('node:fs');
916
+ const content = fs.readFileSync(absolutePath, 'utf-8');
917
+ return JSON.parse(content);
906
918
  }`;
907
919
  }
908
920
  function resolveConfig(config) {
@@ -951,6 +963,18 @@ function ezI18n(config) {
951
963
  })();
952
964
  `;
953
965
  injectScript("head-inline", hydrationScript);
966
+ const viewTransitionsScript = `
967
+ import { initLocale, setTranslations } from '@zachhandley/ez-i18n/runtime';
968
+
969
+ document.addEventListener('astro:after-swap', () => {
970
+ const initData = globalThis.__EZ_I18N_INIT__;
971
+ if (initData) {
972
+ initLocale(initData.locale, initData.translations);
973
+ setTranslations(initData.translations);
974
+ }
975
+ });
976
+ `;
977
+ injectScript("page", viewTransitionsScript);
954
978
  },
955
979
  "astro:config:done": ({
956
980
  injectTypes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },