@astroscope/i18n 0.1.0 → 0.2.0

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 (161) hide show
  1. package/README.md +21 -1
  2. package/dist/index.d.ts +23 -0
  3. package/dist/index.js +4 -0
  4. package/package.json +8 -7
  5. package/dist/babel-plugin-FUTQRKLT.js +0 -121
  6. package/dist/chunk-22ZZFFC2.js +0 -159
  7. package/dist/chunk-2PSXD3JJ.js +0 -144
  8. package/dist/chunk-3VI62RLT.js +0 -176
  9. package/dist/chunk-4DAQPWXI.js +0 -36
  10. package/dist/chunk-4OGX6AF5.js +0 -10
  11. package/dist/chunk-4PHYKXO3.js +0 -227
  12. package/dist/chunk-4UBFISFY.js +0 -376
  13. package/dist/chunk-5DERF6DV.js +0 -266
  14. package/dist/chunk-5KGNHFTC.js +0 -344
  15. package/dist/chunk-5PP4D2VK.js +0 -23
  16. package/dist/chunk-6BW3PN23.js +0 -14
  17. package/dist/chunk-6ESQ4JQI.js +0 -263
  18. package/dist/chunk-A7MPXMOP.js +0 -202
  19. package/dist/chunk-AWZ2SQDW.js +0 -149
  20. package/dist/chunk-AYY2YIBQ.js +0 -52
  21. package/dist/chunk-BMNEJFTD.js +0 -56
  22. package/dist/chunk-BSXQGEUK.js +0 -16
  23. package/dist/chunk-BSYTJFGF.js +0 -21
  24. package/dist/chunk-BVPXEGTT.js +0 -12
  25. package/dist/chunk-C4DJYWF6.js +0 -193
  26. package/dist/chunk-C5EJYE2P.js +0 -245
  27. package/dist/chunk-CLNOQHMS.js +0 -254
  28. package/dist/chunk-E5MCIRSU.js +0 -144
  29. package/dist/chunk-E7ZJS7WX.js +0 -162
  30. package/dist/chunk-ESFGCYYH.js +0 -24
  31. package/dist/chunk-FHBVI3TL.js +0 -372
  32. package/dist/chunk-FI5KZ5IO.js +0 -17
  33. package/dist/chunk-H5R6YMOL.js +0 -233
  34. package/dist/chunk-H62K3FGA.js +0 -236
  35. package/dist/chunk-HDG2R6XT.js +0 -211
  36. package/dist/chunk-HGXU5QAK.js +0 -344
  37. package/dist/chunk-HHRMR3TM.js +0 -17
  38. package/dist/chunk-HS4HVBAD.js +0 -127
  39. package/dist/chunk-IPJWKKHJ.js +0 -324
  40. package/dist/chunk-ITTL4V7J.js +0 -24
  41. package/dist/chunk-IWUBCMOK.js +0 -128
  42. package/dist/chunk-JJBBY2GR.js +0 -14
  43. package/dist/chunk-JTUKXNIJ.js +0 -23
  44. package/dist/chunk-K7YULG4A.js +0 -14
  45. package/dist/chunk-KNONI6DP.js +0 -89
  46. package/dist/chunk-LMTEO22Y.js +0 -17
  47. package/dist/chunk-LRLZEX4D.js +0 -147
  48. package/dist/chunk-MFKPLUAN.js +0 -241
  49. package/dist/chunk-MIWXQOO3.js +0 -316
  50. package/dist/chunk-MJRTAWPR.js +0 -261
  51. package/dist/chunk-MZEPQCXX.js +0 -249
  52. package/dist/chunk-NHHTSFA7.js +0 -237
  53. package/dist/chunk-NTTXM7AG.js +0 -23
  54. package/dist/chunk-NZFAVJXR.js +0 -192
  55. package/dist/chunk-OFNFSDW3.js +0 -13
  56. package/dist/chunk-PG3XDNGF.js +0 -227
  57. package/dist/chunk-PVEVTPNK.js +0 -139
  58. package/dist/chunk-QAO4BXS4.js +0 -244
  59. package/dist/chunk-QCTULQQK.js +0 -34
  60. package/dist/chunk-QKND2KCA.js +0 -163
  61. package/dist/chunk-QZEGY6RJ.js +0 -151
  62. package/dist/chunk-RAE2L6FT.js +0 -193
  63. package/dist/chunk-S3ABJBU3.js +0 -255
  64. package/dist/chunk-SVDVCPCV.js +0 -236
  65. package/dist/chunk-T35ZUWTL.js +0 -153
  66. package/dist/chunk-T6WV5DW6.js +0 -156
  67. package/dist/chunk-TGUXVDA3.js +0 -82
  68. package/dist/chunk-TYMO7K3A.js +0 -173
  69. package/dist/chunk-V4RBFLQL.js +0 -23
  70. package/dist/chunk-V4XWJXXZ.js +0 -23
  71. package/dist/chunk-VQCY3OKK.js +0 -258
  72. package/dist/chunk-WLGOJPDJ.js +0 -15
  73. package/dist/chunk-WUEPDJIL.js +0 -259
  74. package/dist/chunk-X3L7WZLY.js +0 -254
  75. package/dist/chunk-XDD62ZM3.js +0 -255
  76. package/dist/chunk-XFXXEDRD.js +0 -36
  77. package/dist/chunk-XKYOR5UK.js +0 -8
  78. package/dist/chunk-Y26535SI.js +0 -239
  79. package/dist/chunk-Y3PQX5TX.js +0 -152
  80. package/dist/chunk-Y4BE2V6F.js +0 -347
  81. package/dist/chunk-Z4IZYDIA.js +0 -24
  82. package/dist/chunk-Z52G4CYY.js +0 -14
  83. package/dist/chunk-ZGLUYWVM.js +0 -128
  84. package/dist/client/import-with-i18n.d.ts +0 -16
  85. package/dist/client/import-with-i18n.js +0 -8
  86. package/dist/client-directives/idle.d.ts +0 -9
  87. package/dist/client-directives/idle.js +0 -15
  88. package/dist/client-directives/load.d.ts +0 -9
  89. package/dist/client-directives/load.js +0 -15
  90. package/dist/client-directives/media.d.ts +0 -9
  91. package/dist/client-directives/media.js +0 -15
  92. package/dist/client-directives/only.d.ts +0 -9
  93. package/dist/client-directives/only.js +0 -15
  94. package/dist/client-directives/utils.d.ts +0 -9
  95. package/dist/client-directives/utils.js +0 -7
  96. package/dist/client-directives/visible.d.ts +0 -9
  97. package/dist/client-directives/visible.js +0 -15
  98. package/dist/i18n-3cZHoHwP.d.ts +0 -86
  99. package/dist/i18n-BHU81LMA.d.ts +0 -55
  100. package/dist/i18n-BagoeH4_.d.ts +0 -62
  101. package/dist/i18n-BeL84090.d.ts +0 -77
  102. package/dist/i18n-BeRWDfHi.d.ts +0 -55
  103. package/dist/i18n-Bfs2PVcf.d.ts +0 -79
  104. package/dist/i18n-BrL7p3aN.d.ts +0 -99
  105. package/dist/i18n-CNQNCFU0.d.ts +0 -55
  106. package/dist/i18n-CX_uU8V2.d.ts +0 -80
  107. package/dist/i18n-Cr1QZCwe.d.ts +0 -64
  108. package/dist/i18n-CzTRxGeX.d.ts +0 -80
  109. package/dist/i18n-DUOFiC7g.d.ts +0 -77
  110. package/dist/i18n-DcF47BHS.d.ts +0 -77
  111. package/dist/i18n-DifWvtaO.d.ts +0 -60
  112. package/dist/i18n-DumSqX1t.d.ts +0 -55
  113. package/dist/i18n-fWTJw12h.d.ts +0 -80
  114. package/dist/import-with-i18n.d.ts +0 -23
  115. package/dist/import-with-i18n.js +0 -7
  116. package/dist/init.d.ts +0 -2
  117. package/dist/init.js +0 -8
  118. package/dist/middleware-entrypoint-C0Drh9E_.d.ts +0 -29
  119. package/dist/middleware-entrypoint-mEl66IUy.d.ts +0 -29
  120. package/dist/middleware-entrypoint.d.ts +0 -5
  121. package/dist/middleware-entrypoint.js +0 -30
  122. package/dist/server/middleware-entrypoint.d.ts +0 -2
  123. package/dist/server/middleware-entrypoint.js +0 -28
  124. package/dist/t-BY_C9lZ1.d.ts +0 -30
  125. package/dist/t-CG3yDiEa.d.ts +0 -30
  126. package/dist/t-CHsBfrPr.d.ts +0 -30
  127. package/dist/t-DQpXaDhP.d.ts +0 -30
  128. package/dist/t.client.d.ts +0 -11
  129. package/dist/t.client.js +0 -35
  130. package/dist/t.server.d.ts +0 -22
  131. package/dist/t.server.js +0 -12
  132. package/dist/types-BC6K-pID.d.ts +0 -110
  133. package/dist/types-BUV7BZML.d.ts +0 -55
  134. package/dist/types-BWGB322F.d.ts +0 -46
  135. package/dist/types-BaaSiz9n.d.ts +0 -7
  136. package/dist/types-Bgl2V5xo.d.ts +0 -102
  137. package/dist/types-BwhB6IT4.d.ts +0 -111
  138. package/dist/types-C6rOJFY2.d.ts +0 -24
  139. package/dist/types-C7lD-Woj.d.ts +0 -50
  140. package/dist/types-CLWZeQhD.d.ts +0 -54
  141. package/dist/types-COXt613w.d.ts +0 -19
  142. package/dist/types-CUlkbl9-.d.ts +0 -50
  143. package/dist/types-CVv7GGPj.d.ts +0 -46
  144. package/dist/types-CiIDN2sW.d.ts +0 -64
  145. package/dist/types-Cr86qjYl.d.ts +0 -58
  146. package/dist/types-CxnObiEO.d.ts +0 -7
  147. package/dist/types-D44mFUjA.d.ts +0 -97
  148. package/dist/types-D85m9UTC.d.ts +0 -137
  149. package/dist/types-DWhsmSPP.d.ts +0 -102
  150. package/dist/types-DdprXGJ1.d.ts +0 -46
  151. package/dist/types-DhVJ2ZIo.d.ts +0 -43
  152. package/dist/types-DnbOuM1L.d.ts +0 -7
  153. package/dist/types-DsNK_9sI.d.ts +0 -24
  154. package/dist/types-DvWBr9Xp.d.ts +0 -17
  155. package/dist/types-DwkIalh6.d.ts +0 -24
  156. package/dist/types-OYRgjtE_.d.ts +0 -110
  157. package/dist/types-SV8S05GX.d.ts +0 -7
  158. package/dist/types-TYn9WnxY.d.ts +0 -46
  159. package/dist/types-aXCBbdhq.d.ts +0 -55
  160. package/dist/types-gn4aNKGx.d.ts +0 -54
  161. package/dist/types-nippsMkm.d.ts +0 -54
@@ -1,347 +0,0 @@
1
- import {
2
- chunkIdToName
3
- } from "./chunk-4A5BKHFN.js";
4
-
5
- // src/extraction/manifest.ts
6
- import path from "path";
7
- var I18N_GLOBAL_KEY = "__astroscope_i18n_manifest__";
8
- function getGlobalState() {
9
- const g = globalThis;
10
- if (!g[I18N_GLOBAL_KEY]) {
11
- g[I18N_GLOBAL_KEY] = {
12
- extractedKeys: [],
13
- chunkManifest: {},
14
- projectRoot: ""
15
- };
16
- }
17
- return g[I18N_GLOBAL_KEY];
18
- }
19
- function getManifest() {
20
- const state = getGlobalState();
21
- const keysWithRelativePaths = state.extractedKeys.map((key) => ({
22
- ...key,
23
- file: state.projectRoot ? path.relative(state.projectRoot, key.file) : key.file
24
- }));
25
- return {
26
- keys: keysWithRelativePaths,
27
- chunks: state.chunkManifest
28
- };
29
- }
30
-
31
- // src/extraction/vite-plugin.ts
32
- import fs from "fs";
33
- import path2 from "path";
34
- import { transformAsync } from "@babel/core";
35
-
36
- // src/extraction/babel-plugin.ts
37
- function getStringValue(t, node) {
38
- if (t.isStringLiteral(node)) {
39
- return node.value;
40
- }
41
- if (t.isTemplateLiteral(node) && node.quasis.length === 1 && node.expressions.length === 0) {
42
- return node.quasis[0]?.value.cooked ?? null;
43
- }
44
- return null;
45
- }
46
- function extractMeta(t, node) {
47
- const stringValue = getStringValue(t, node);
48
- if (stringValue !== null) {
49
- return { fallback: stringValue };
50
- }
51
- if (t.isObjectExpression(node)) {
52
- return extractMetaFromObject(t, node);
53
- }
54
- return { fallback: "" };
55
- }
56
- function extractMetaFromObject(t, obj) {
57
- const meta = { fallback: "" };
58
- for (const prop of obj.properties) {
59
- if (!t.isObjectProperty(prop)) continue;
60
- if (!t.isIdentifier(prop.key)) continue;
61
- const name = prop.key.name;
62
- if (name === "fallback") {
63
- const value = getStringValue(t, prop.value);
64
- if (value !== null) {
65
- meta.fallback = value;
66
- }
67
- } else if (name === "description") {
68
- const value = getStringValue(t, prop.value);
69
- if (value !== null) {
70
- meta.description = value;
71
- }
72
- } else if (name === "variables" && t.isObjectExpression(prop.value)) {
73
- meta.variables = extractVariables(t, prop.value);
74
- }
75
- }
76
- return meta;
77
- }
78
- function extractVariables(t, obj) {
79
- const result = {};
80
- for (const prop of obj.properties) {
81
- if (!t.isObjectProperty(prop)) continue;
82
- if (!t.isIdentifier(prop.key)) continue;
83
- const varName = prop.key.name;
84
- if (t.isObjectExpression(prop.value)) {
85
- const varDef = {};
86
- for (const varProp of prop.value.properties) {
87
- if (!t.isObjectProperty(varProp)) continue;
88
- if (!t.isIdentifier(varProp.key)) continue;
89
- const varPropName = varProp.key.name;
90
- const value = getStringValue(t, varProp.value);
91
- if (value !== null) {
92
- if (varPropName === "fallback") {
93
- varDef.fallback = value;
94
- } else if (varPropName === "description") {
95
- varDef.description = value;
96
- }
97
- }
98
- }
99
- result[varName] = varDef;
100
- }
101
- }
102
- return Object.keys(result).length > 0 ? result : void 0;
103
- }
104
- function isMetaArgument(t, node) {
105
- if (t.isStringLiteral(node) || t.isTemplateLiteral(node)) {
106
- return true;
107
- }
108
- if (t.isObjectExpression(node)) {
109
- for (const prop of node.properties) {
110
- if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "fallback") {
111
- return true;
112
- }
113
- }
114
- }
115
- return false;
116
- }
117
- function i18nExtractPlugin({ types: t }) {
118
- return {
119
- name: "@astroscope/i18n/extract",
120
- visitor: {
121
- CallExpression(path3, state) {
122
- if (!path3.get("callee").isIdentifier({ name: "t" })) return;
123
- const args = path3.node.arguments;
124
- if (args.length < 1) return;
125
- const keyArg = args[0];
126
- if (!t.isExpression(keyArg)) return;
127
- const key = getStringValue(t, keyArg);
128
- if (key === null) return;
129
- let meta = { fallback: "" };
130
- if (args.length >= 2 && t.isExpression(args[1]) && isMetaArgument(t, args[1])) {
131
- meta = extractMeta(t, args[1]);
132
- }
133
- state.opts.onKeyExtracted({
134
- key,
135
- meta,
136
- file: state.filename ?? "",
137
- line: path3.node.loc?.start.line ?? 0
138
- });
139
- if (state.opts.stripFallbacks && args.length >= 2) {
140
- const secondArg = args[1];
141
- if (!t.isExpression(secondArg)) return;
142
- if (isMetaArgument(t, secondArg)) {
143
- if (args.length === 2) {
144
- path3.node.arguments = [args[0]];
145
- } else if (args.length >= 3) {
146
- path3.node.arguments = [args[0], args[2]];
147
- }
148
- }
149
- }
150
- }
151
- }
152
- };
153
- }
154
-
155
- // src/extraction/vite-plugin.ts
156
- var VIRTUAL_MODULE_ID = "virtual:@astroscope/i18n/manifest";
157
- var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
158
- var MANIFEST_FILE_NAME = "i18n-manifest.json";
159
- function hasI18nImport(code) {
160
- return /@astroscope\/i18n\/t/.test(code);
161
- }
162
- function getParserPlugins(filename) {
163
- const plugins = [];
164
- if (/\.tsx?$/.test(filename)) {
165
- plugins.push("typescript");
166
- }
167
- if (/\.(jsx|tsx)$/.test(filename)) {
168
- plugins.push("jsx");
169
- }
170
- return plugins;
171
- }
172
- function i18nVitePlugin(options) {
173
- const { include = [".ts", ".tsx", ".js", ".jsx", ".astro"], logger } = options;
174
- const extractedKeys = [];
175
- const fileToKeys = /* @__PURE__ */ new Map();
176
- const filesWithI18n = /* @__PURE__ */ new Set();
177
- let chunkManifest = {};
178
- let projectRoot = "";
179
- let isBuild = false;
180
- let isSSR = false;
181
- return {
182
- name: "@astroscope/i18n/extract",
183
- enforce: "pre",
184
- configResolved(config) {
185
- projectRoot = config.root;
186
- getGlobalState().projectRoot = config.root;
187
- isBuild = config.command === "build";
188
- isSSR = !!config.build.ssr;
189
- },
190
- resolveId(id) {
191
- if (id === VIRTUAL_MODULE_ID) {
192
- return RESOLVED_VIRTUAL_MODULE_ID;
193
- }
194
- if (id.startsWith(`${VIRTUAL_MODULE_ID}?`)) {
195
- return `\0${id}`;
196
- }
197
- },
198
- load(id) {
199
- if (id === RESOLVED_VIRTUAL_MODULE_ID || id.startsWith(`\0${VIRTUAL_MODULE_ID}?`)) {
200
- if (isBuild) {
201
- return `
202
- import { readFileSync, existsSync } from 'node:fs';
203
- import { fileURLToPath } from 'node:url';
204
- import { dirname, join } from 'node:path';
205
-
206
- const __dirname = dirname(fileURLToPath(import.meta.url));
207
- const manifestName = '${MANIFEST_FILE_NAME}';
208
-
209
- // manifest is emitted to server directory (not publicly accessible)
210
- const searchPaths = [
211
- join(__dirname, manifestName), // same dir (server/)
212
- join(__dirname, '..', manifestName), // parent dir (from chunks/)
213
- ];
214
-
215
- let manifestPath = searchPaths.find(p => existsSync(p));
216
- if (!manifestPath) {
217
- console.warn('[i18n] manifest not found, using empty manifest');
218
- manifestPath = null;
219
- }
220
-
221
- const manifestJson = manifestPath
222
- ? JSON.parse(readFileSync(manifestPath, 'utf-8'))
223
- : { keys: [], chunks: {} };
224
-
225
- export const manifest = manifestJson;
226
- export function getManifest() { return manifestJson; }
227
- `;
228
- }
229
- return `
230
- import { getManifest as _getManifest } from '@astroscope/i18n/extraction';
231
- export const manifest = { keys: [], chunks: {} }; // placeholder, use getManifest()
232
- export function getManifest() { return _getManifest(); }
233
- `;
234
- }
235
- },
236
- async transform(code, id) {
237
- if (!include.some((ext) => id.endsWith(ext))) {
238
- return null;
239
- }
240
- if (id.includes("node_modules")) {
241
- return null;
242
- }
243
- if (!hasI18nImport(code)) {
244
- return null;
245
- }
246
- filesWithI18n.add(id);
247
- const fileKeys = [];
248
- const result = await transformAsync(code, {
249
- filename: id,
250
- sourceMaps: true,
251
- babelrc: false,
252
- configFile: false,
253
- parserOpts: {
254
- plugins: getParserPlugins(id)
255
- },
256
- plugins: [
257
- [
258
- i18nExtractPlugin,
259
- {
260
- onKeyExtracted: (key) => fileKeys.push(key),
261
- stripFallbacks: isBuild
262
- // only strip in production
263
- }
264
- ]
265
- ]
266
- });
267
- if (fileKeys.length > 0) {
268
- extractedKeys.push(...fileKeys);
269
- getGlobalState().extractedKeys = extractedKeys;
270
- fileToKeys.set(
271
- id,
272
- fileKeys.map((k) => k.key)
273
- );
274
- }
275
- if (isBuild && result?.code) {
276
- return {
277
- code: result.code,
278
- map: result.map
279
- };
280
- }
281
- return null;
282
- },
283
- generateBundle(_, bundle) {
284
- chunkManifest = {};
285
- for (const [fileName, chunk] of Object.entries(bundle)) {
286
- if (chunk.type === "chunk" && chunk.moduleIds) {
287
- const keys = /* @__PURE__ */ new Set();
288
- let hasI18nModule = false;
289
- for (const moduleId of chunk.moduleIds) {
290
- const moduleKeys = fileToKeys.get(moduleId);
291
- if (moduleKeys) {
292
- moduleKeys.forEach((k) => keys.add(k));
293
- }
294
- if (filesWithI18n.has(moduleId)) {
295
- hasI18nModule = true;
296
- }
297
- }
298
- if (keys.size > 0) {
299
- const chunkName = chunkIdToName(fileName.replace(/\.js$/, ""));
300
- chunkManifest[chunkName] = Array.from(keys);
301
- }
302
- if (hasI18nModule && chunk.type === "chunk") {
303
- const chunkName = chunkIdToName(fileName.replace(/\.js$/, ""));
304
- const loaderCode = `
305
- /* @astroscope/i18n loader */
306
- if (typeof window !== 'undefined' && window.__i18n__) {
307
- const __i18n__ = window.__i18n__;
308
- const __i18n_hash__ = __i18n__.hashes[${JSON.stringify(chunkName)}];
309
- if (__i18n_hash__) {
310
- await import(\`/_i18n/\${__i18n__.locale}/${chunkName}.\${__i18n_hash__}.js\`);
311
- }
312
- }
313
- /* end @astroscope/i18n loader */
314
- `;
315
- chunk.code = loaderCode + chunk.code;
316
- }
317
- }
318
- }
319
- getGlobalState().chunkManifest = chunkManifest;
320
- const chunkCount = Object.keys(chunkManifest).length;
321
- const keyCount = extractedKeys.length;
322
- logger?.info(`manifest: ${chunkCount} chunks, ${keyCount} keys`);
323
- },
324
- writeBundle(outputOptions) {
325
- if (!isSSR && outputOptions.dir) {
326
- const keysWithRelativePaths = extractedKeys.map((key) => ({
327
- ...key,
328
- file: projectRoot ? path2.relative(projectRoot, key.file) : key.file
329
- }));
330
- const manifest = {
331
- keys: keysWithRelativePaths,
332
- chunks: chunkManifest
333
- };
334
- const serverDir = path2.resolve(outputOptions.dir, "..", "server");
335
- const manifestPath = path2.join(serverDir, MANIFEST_FILE_NAME);
336
- if (fs.existsSync(serverDir)) {
337
- fs.writeFileSync(manifestPath, JSON.stringify(manifest));
338
- }
339
- }
340
- }
341
- };
342
- }
343
-
344
- export {
345
- getManifest,
346
- i18nVitePlugin
347
- };
@@ -1,24 +0,0 @@
1
- import {
2
- buildI18nChunkUrl,
3
- componentUrlToChunkName
4
- } from "./chunk-HHRMR3TM.js";
5
-
6
- // src/client/directives/utils.ts
7
- async function loadI18nForChunk(el) {
8
- const componentUrl = el.getAttribute("component-url");
9
- if (!componentUrl) return;
10
- const chunkName = componentUrlToChunkName(componentUrl);
11
- const i18n = window.__i18n__;
12
- const hash = i18n.hashes[chunkName];
13
- if (hash) {
14
- const url = buildI18nChunkUrl(i18n.locale, chunkName, hash);
15
- await import(
16
- /* @vite-ignore */
17
- url
18
- );
19
- }
20
- }
21
-
22
- export {
23
- loadI18nForChunk
24
- };
@@ -1,14 +0,0 @@
1
- // src/import-with-i18n.ts
2
- async function importWithI18n(importFn, chunkId) {
3
- const hash = chunkId ? window.__i18n_hashes__?.[chunkId] : void 0;
4
- const locale = window.__i18n_locale__ || "en";
5
- const [module] = await Promise.all([
6
- importFn(),
7
- hash ? import(`/_i18n/${locale}/${chunkId?.replace(/^_astro\//, "")}.${hash}.js`) : Promise.resolve()
8
- ]);
9
- return module;
10
- }
11
-
12
- export {
13
- importWithI18n
14
- };
@@ -1,128 +0,0 @@
1
- import {
2
- compileTranslations
3
- } from "./chunk-KNDYKTHE.js";
4
-
5
- // src/server/i18n.ts
6
- import fs from "fs";
7
-
8
- // src/extraction/hash.ts
9
- import { createHash } from "crypto";
10
- function hashString(str) {
11
- return createHash("sha256").update(str).digest("hex").substring(0, 8);
12
- }
13
- function computeChunkHash(translations, keys) {
14
- const relevantTranslations = {};
15
- for (const key of keys.sort()) {
16
- if (translations[key]) {
17
- relevantTranslations[key] = translations[key];
18
- }
19
- }
20
- return hashString(JSON.stringify(relevantTranslations));
21
- }
22
- function computeAllChunkHashes(translations, manifest) {
23
- const hashes = {};
24
- for (const [chunkId, keys] of Object.entries(manifest)) {
25
- hashes[chunkId] = computeChunkHash(translations, keys);
26
- }
27
- return hashes;
28
- }
29
-
30
- // src/server/i18n.ts
31
- function loadExtractionManifest() {
32
- const candidates = [
33
- "./i18n-manifest.json",
34
- // same directory
35
- "../i18n-manifest.json"
36
- // parent (when code is in chunks/)
37
- ];
38
- for (const candidate of candidates) {
39
- try {
40
- const manifestPath = new URL(candidate, import.meta.url);
41
- const content = fs.readFileSync(manifestPath, "utf-8");
42
- return JSON.parse(content);
43
- } catch {
44
- }
45
- }
46
- return void 0;
47
- }
48
- var I18nSingleton = class {
49
- config = null;
50
- rawCache = /* @__PURE__ */ new Map();
51
- compiledCache = /* @__PURE__ */ new Map();
52
- extractionManifest = void 0;
53
- // undefined = not loaded yet
54
- hashCache = /* @__PURE__ */ new Map();
55
- configure(config) {
56
- this.config = config;
57
- }
58
- getConfig() {
59
- return this.config;
60
- }
61
- getDefaultLocale() {
62
- return this.config?.defaultLocale ?? this.config?.locales[0];
63
- }
64
- getFallbackBehavior() {
65
- return this.config?.fallback ?? "fallback";
66
- }
67
- setTranslations(locale, raw) {
68
- this.rawCache.set(locale, raw);
69
- this.compiledCache.set(locale, compileTranslations(locale, raw));
70
- this.hashCache.delete(locale);
71
- const chunks = this.getChunkManifest();
72
- if (chunks) {
73
- this.hashCache.set(locale, computeAllChunkHashes(raw, chunks));
74
- }
75
- }
76
- getTranslations(locale) {
77
- return this.rawCache.get(locale);
78
- }
79
- getCompiledTranslations(locale) {
80
- return this.compiledCache.get(locale);
81
- }
82
- getChunkManifest() {
83
- return this.getExtractionManifest()?.chunks ?? null;
84
- }
85
- /**
86
- * Get extracted translation keys with metadata.
87
- * Use this to populate your CMS with keys extracted from the codebase.
88
- */
89
- getExtractedKeys() {
90
- return this.getExtractionManifest()?.keys ?? null;
91
- }
92
- /**
93
- * Get the full extraction manifest (keys + chunks).
94
- * Returns null in dev mode (manifest doesn't exist).
95
- */
96
- getExtractionManifest() {
97
- if (this.extractionManifest === void 0) {
98
- this.extractionManifest = loadExtractionManifest() ?? null;
99
- }
100
- return this.extractionManifest;
101
- }
102
- getHashes(locale) {
103
- return this.hashCache.get(locale);
104
- }
105
- /**
106
- * Clear translations for specified locale(s).
107
- * @param locales - Locale(s) to clear, or all if not specified
108
- */
109
- clear(locales) {
110
- const targets = this.resolveLocales(locales);
111
- for (const locale of targets) {
112
- this.rawCache.delete(locale);
113
- this.compiledCache.delete(locale);
114
- this.hashCache.delete(locale);
115
- }
116
- }
117
- resolveLocales(locales) {
118
- if (!locales) return this.config?.locales ?? [];
119
- if (typeof locales === "string") return [locales];
120
- return locales;
121
- }
122
- };
123
- var i18n = new I18nSingleton();
124
-
125
- export {
126
- computeChunkHash,
127
- i18n
128
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * @deprecated Not needed - translations load automatically via chunk loader.
3
- * Use regular dynamic import() instead.
4
- */
5
- declare function importx<T>(importFn: () => Promise<T>): Promise<T>;
6
- /**
7
- * @deprecated Not needed - translations load automatically via chunk loader.
8
- * Use regular React.lazy() instead.
9
- */
10
- declare function lazyx<T>(importFn: () => Promise<{
11
- default: T;
12
- }>): () => Promise<{
13
- default: T;
14
- }>;
15
-
16
- export { importx, lazyx };
@@ -1,8 +0,0 @@
1
- import {
2
- importx,
3
- lazyx
4
- } from "../chunk-BVPXEGTT.js";
5
- export {
6
- importx,
7
- lazyx
8
- };
@@ -1,9 +0,0 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:idle directive
5
- * Loads translations in parallel before delegating to Astro's original idle directive
6
- */
7
- declare const idleDirective: ClientDirective;
8
-
9
- export { idleDirective as default };
@@ -1,15 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
-
6
- // src/client-directives/idle.ts
7
- import originalIdle from "astro/client/idle.js";
8
- var idleDirective = async (load, options, el) => {
9
- await loadI18nForChunk(el);
10
- return originalIdle(load, options, el);
11
- };
12
- var idle_default = idleDirective;
13
- export {
14
- idle_default as default
15
- };
@@ -1,9 +0,0 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:load directive
5
- * Loads translations in parallel before delegating to Astro's original load directive
6
- */
7
- declare const loadDirective: ClientDirective;
8
-
9
- export { loadDirective as default };
@@ -1,15 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
-
6
- // src/client-directives/load.ts
7
- import originalLoad from "astro/client/load.js";
8
- var loadDirective = async (load, options, el) => {
9
- await loadI18nForChunk(el);
10
- return originalLoad(load, options, el);
11
- };
12
- var load_default = loadDirective;
13
- export {
14
- load_default as default
15
- };
@@ -1,9 +0,0 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:media directive
5
- * Loads translations in parallel before delegating to Astro's original media directive
6
- */
7
- declare const mediaDirective: ClientDirective;
8
-
9
- export { mediaDirective as default };
@@ -1,15 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
-
6
- // src/client-directives/media.ts
7
- import originalMedia from "astro/client/media.js";
8
- var mediaDirective = async (load, options, el) => {
9
- await loadI18nForChunk(el);
10
- return originalMedia(load, options, el);
11
- };
12
- var media_default = mediaDirective;
13
- export {
14
- media_default as default
15
- };
@@ -1,9 +0,0 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:only directive
5
- * Loads translations in parallel before delegating to Astro's original only directive
6
- */
7
- declare const onlyDirective: ClientDirective;
8
-
9
- export { onlyDirective as default };
@@ -1,15 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
-
6
- // src/client-directives/only.ts
7
- import originalOnly from "astro/client/only.js";
8
- var onlyDirective = async (load, options, el) => {
9
- await loadI18nForChunk(el);
10
- return originalOnly(load, options, el);
11
- };
12
- var only_default = onlyDirective;
13
- export {
14
- only_default as default
15
- };
@@ -1,9 +0,0 @@
1
- import '../types-DWhsmSPP.js';
2
-
3
- /**
4
- * Load translations for a chunk before hydration
5
- * Extracts chunk name from astro-island's component-url attribute
6
- */
7
- declare function loadI18nForChunk(el: HTMLElement): Promise<void>;
8
-
9
- export { loadI18nForChunk };
@@ -1,7 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
- export {
6
- loadI18nForChunk
7
- };
@@ -1,9 +0,0 @@
1
- import { ClientDirective } from 'astro';
2
-
3
- /**
4
- * i18n-aware client:visible directive
5
- * Loads translations in parallel before delegating to Astro's original visible directive
6
- */
7
- declare const visibleDirective: ClientDirective;
8
-
9
- export { visibleDirective as default };
@@ -1,15 +0,0 @@
1
- import {
2
- loadI18nForChunk
3
- } from "../chunk-ESFGCYYH.js";
4
- import "../chunk-FI5KZ5IO.js";
5
-
6
- // src/client-directives/visible.ts
7
- import originalVisible from "astro/client/visible.js";
8
- var visibleDirective = async (load, options, el) => {
9
- await loadI18nForChunk(el);
10
- return originalVisible(load, options, el);
11
- };
12
- var visible_default = visibleDirective;
13
- export {
14
- visible_default as default
15
- };