@zachhandley/ez-i18n 0.4.0 → 0.4.1
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 +19 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -937,27 +937,43 @@ function __deepMerge(target, ...sources) {
|
|
|
937
937
|
function getPublicLoaderCode() {
|
|
938
938
|
return `
|
|
939
939
|
async function __loadPublicJson(url, absolutePath) {
|
|
940
|
+
async function __parseJsonResponse(response) {
|
|
941
|
+
const text = await response.text();
|
|
942
|
+
if (!text) return {};
|
|
943
|
+
return JSON.parse(text);
|
|
944
|
+
}
|
|
945
|
+
|
|
940
946
|
// Browser - fetch with relative URL
|
|
941
947
|
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
942
|
-
|
|
948
|
+
const response = await fetch(url);
|
|
949
|
+
if (!response.ok) {
|
|
950
|
+
throw new Error(\`Failed to fetch translations from \${url}: \${response.status}\`);
|
|
951
|
+
}
|
|
952
|
+
return __parseJsonResponse(response);
|
|
943
953
|
}
|
|
944
954
|
|
|
945
955
|
// Cloudflare Workers - use ASSETS binding (set by middleware)
|
|
946
956
|
const assets = globalThis.__EZ_I18N_ASSETS__;
|
|
947
957
|
if (assets && typeof assets.fetch === 'function') {
|
|
948
958
|
const response = await assets.fetch(new URL(url, 'https://assets.local'));
|
|
949
|
-
|
|
959
|
+
if (!response.ok) {
|
|
960
|
+
throw new Error(\`Failed to fetch translations from \${url}: \${response.status}\`);
|
|
961
|
+
}
|
|
962
|
+
return __parseJsonResponse(response);
|
|
950
963
|
}
|
|
951
964
|
|
|
952
965
|
// Deno - use Deno.readTextFile
|
|
953
966
|
if (typeof Deno !== 'undefined') {
|
|
954
967
|
const content = await Deno.readTextFile(absolutePath);
|
|
968
|
+
if (!content) return {};
|
|
955
969
|
return JSON.parse(content);
|
|
956
970
|
}
|
|
957
971
|
|
|
958
972
|
// Node.js / Bun - use absolute path with node:fs
|
|
959
973
|
const { readFileSync } = await import('node:fs');
|
|
960
|
-
|
|
974
|
+
const content = readFileSync(absolutePath, 'utf-8');
|
|
975
|
+
if (!content) return {};
|
|
976
|
+
return JSON.parse(content);
|
|
961
977
|
}`;
|
|
962
978
|
}
|
|
963
979
|
function resolveConfig(config) {
|