@intlayer/core 9.9.3-canary.1 → 9.9.3

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.
@@ -14,7 +14,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
14
14
  *
15
15
  */
16
16
  const getInsertion = (content, values) => content.replace(/\{\{\s*(.*?)\s*\}\}/g, (_, key) => {
17
- return (values[key.trim()] ?? "").toString();
17
+ const trimmedKey = key.trim();
18
+ return (values[trimmedKey] ?? values[trimmedKey.replace(/^-\s+/, "-")] ?? "").toString();
18
19
  });
19
20
 
20
21
  exports.getInsertion = getInsertion;
@@ -1 +1 @@
1
- {"version":3,"file":"getInsertion.cjs","names":[],"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string | number }\n) =>\n content.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (values[trimmedKey] ?? '').toString();\n });\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,gBACX,SACA,WAEA,QAAQ,QAAQ,yBAAyB,GAAG,QAAQ;CAElD,QAAQ,OADW,IAAI,KACC,MAAM,GAAE,CAAE,SAAS;AAC7C,CAAC"}
1
+ {"version":3,"file":"getInsertion.cjs","names":[],"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string | number }\n) =>\n content.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n\n // i18next's unescaped `{{- name}}` is read as `-name`\n const value =\n values[trimmedKey] ?? values[trimmedKey.replace(/^-\\s+/, '-')];\n\n return (value ?? '').toString();\n });\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,gBACX,SACA,WAEA,QAAQ,QAAQ,yBAAyB,GAAG,QAAQ;CAClD,MAAM,aAAa,IAAI,KAAK;CAM5B,QAFE,OAAO,eAAe,OAAO,WAAW,QAAQ,SAAS,GAAG,MAE7C,GAAE,CAAE,SAAS;AAChC,CAAC"}
@@ -1,256 +1,69 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
3
  const require_interpreter_getContent_deepTransform = require("../interpreter/getContent/deepTransform.cjs");
4
- const require_transpiler_enumeration_enumeration = require("../transpiler/enumeration/enumeration.cjs");
5
- const require_transpiler_gender_gender = require("../transpiler/gender/gender.cjs");
6
4
  const require_transpiler_html_html = require("../transpiler/html/html.cjs");
7
5
  const require_transpiler_insertion_insertion = require("../transpiler/insertion/insertion.cjs");
8
- const require_transpiler_plural_plural = require("../transpiler/plural/plural.cjs");
9
- const require_transpiler_select_select = require("../transpiler/select/select.cjs");
10
6
  let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
11
7
  _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
12
8
 
13
9
  // src/messageFormat/i18next.ts
14
- /** `{name, plural|select|number|date|time …`: an ICU argument with a format. */
15
- const FORMATTED_ARGUMENT_PATTERN = /^\{\s*[\p{L}\p{N}_$][\p{L}\p{N}_$.-]*\s*,\s*(?:plural|select|number|date|time)\s*[,}]/u;
16
- /** `{name}`: a bare ICU argument. */
17
- const SIMPLE_ARGUMENT_PATTERN = /^\{\s*[\p{L}\p{N}_$][\p{L}\p{N}_$.-]*\s*\}/u;
10
+ /** An HTML-like tag (`<strong>`, `<1>`), rendered through an `html` node. */
11
+ const HTML_TAG_PATTERN = /<[a-zA-Z0-9-]+[^>]*>/;
12
+ /** A closed `{{…}}` interpolation. */
13
+ const INTERPOLATION_PATTERN = /\{\{[\s\S]*?\}\}/;
18
14
  /**
19
- * Parses an i18next message into nodes.
15
+ * Converts one i18next message into intlayer content.
20
16
  *
21
- * i18next treats single braces as literal text, so a lone `{…}` or `}` at the
22
- * top level stays text (`Press {Ctrl+K}`, `$t(key, {"count": 1})`). Only ICU
23
- * blocks with a known format (`{count, plural, …}`) are parsed there; bare
24
- * `{name}` arguments are read inside plural/select options, where the reverse
25
- * formatter writes them.
17
+ * As in i18next, only `{{…}}` is syntax: single braces stay text
18
+ * (`Press {Ctrl+K}`, `$t(key, {"count": 1})`, ICU blocks), and each
19
+ * interpolation keeps its spelling so write-back leaves the source unchanged.
20
+ * Plurals and contexts are key suffixes (`key_one`, `key_male`), kept as keys.
26
21
  */
27
- const parseI18Next = (text) => {
28
- let index = 0;
29
- const isICUArgumentStart = (isInsideOption) => {
30
- const remainingText = text.slice(index);
31
- return FORMATTED_ARGUMENT_PATTERN.test(remainingText) || isInsideOption && SIMPLE_ARGUMENT_PATTERN.test(remainingText);
32
- };
33
- const parseNodes = (isInsideOption) => {
34
- const nodes = [];
35
- let currentText = "";
36
- while (index < text.length) {
37
- const char = text[index];
38
- if (char === "{" && text[index + 1] === "{") {
39
- if (currentText) {
40
- nodes.push(currentText);
41
- currentText = "";
42
- }
43
- index += 2;
44
- nodes.push(parseStandardArgument());
45
- } else if (char === "{" && isICUArgumentStart(isInsideOption)) {
46
- if (currentText) {
47
- nodes.push(currentText);
48
- currentText = "";
49
- }
50
- index++;
51
- nodes.push(parseICUArgument());
52
- } else if (char === "}" && isInsideOption) break;
53
- else {
54
- currentText += char;
55
- index++;
56
- }
57
- }
58
- if (currentText) nodes.push(currentText);
59
- return nodes;
60
- };
61
- const parseStandardArgument = () => {
62
- let name = "";
63
- while (index < text.length) {
64
- if (text[index] === "}" && text[index + 1] === "}") {
65
- index += 2;
66
- return {
67
- type: "argument",
68
- name: name.trim().replace(/^-\s+/, "-")
69
- };
70
- }
71
- name += text[index];
72
- index++;
73
- }
74
- throw new Error("Unclosed i18next variable");
75
- };
76
- const parseICUArgument = () => {
77
- let name = "";
78
- while (index < text.length && /[^,}]/.test(text[index])) {
79
- name += text[index];
80
- index++;
81
- }
82
- name = name.trim();
83
- if (index >= text.length) throw new Error("Unclosed argument");
84
- if (text[index] === "}") {
85
- index++;
86
- return {
87
- type: "argument",
88
- name
89
- };
90
- }
91
- if (text[index] === ",") {
92
- index++;
93
- let type = "";
94
- while (index < text.length && /[^,}]/.test(text[index])) {
95
- type += text[index];
96
- index++;
97
- }
98
- type = type.trim();
99
- if (index >= text.length) throw new Error("Unclosed argument");
100
- if (text[index] === "}") {
101
- index++;
102
- return {
103
- type: "argument",
104
- name,
105
- format: { type }
106
- };
107
- }
108
- if (text[index] === ",") {
109
- index++;
110
- if (type === "plural" || type === "select") {
111
- const options = {};
112
- while (index < text.length && text[index] !== "}") {
113
- while (index < text.length && /\s/.test(text[index])) index++;
114
- let key = "";
115
- while (index < text.length && /[^{\s]/.test(text[index])) {
116
- key += text[index];
117
- index++;
118
- }
119
- while (index < text.length && /\s/.test(text[index])) index++;
120
- if (text[index] !== "{") throw new Error("Expected { after option key");
121
- index++;
122
- const value = parseNodes(true);
123
- if (text[index] !== "}") throw new Error("Expected } after option value");
124
- index++;
125
- options[key] = value;
126
- while (index < text.length && /\s/.test(text[index])) index++;
127
- }
128
- index++;
129
- if (type === "plural") return {
130
- type: "plural",
131
- name,
132
- options
133
- };
134
- else if (type === "select") return {
135
- type: "select",
136
- name,
137
- options
138
- };
139
- } else {
140
- let style = "";
141
- while (index < text.length && text[index] !== "}") {
142
- style += text[index];
143
- index++;
144
- }
145
- if (index >= text.length) throw new Error("Unclosed argument");
146
- style = style.trim();
147
- index++;
148
- return {
149
- type: "argument",
150
- name,
151
- format: {
152
- type,
153
- style
154
- }
155
- };
156
- }
157
- }
158
- }
159
- throw new Error("Malformed argument");
160
- };
161
- return parseNodes(false);
162
- };
163
- const i18nextNodesToIntlayer = (nodes) => {
164
- if (nodes.length === 0) return "";
165
- if (nodes.length === 1 && typeof nodes[0] === "string") {
166
- const node = nodes[0];
167
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) return require_transpiler_html_html.html(node);
168
- return node;
169
- }
170
- if (nodes.every((node) => typeof node === "string" || node.type === "argument")) {
171
- let str = "";
172
- for (const node of nodes) if (typeof node === "string") str += node;
173
- else if (typeof node !== "string" && node.type === "argument") {
174
- if (node.format) str += `{${node.name}, ${node.format.type}${node.format.style ? `, ${node.format.style}` : ""}}`;
175
- else str += `{{${node.name}}}`;
176
- }
177
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) return require_transpiler_html_html.html(str);
178
- return require_transpiler_insertion_insertion.insert(str);
179
- }
180
- if (nodes.length === 1) {
181
- const node = nodes[0];
182
- if (typeof node === "string") {
183
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) return require_transpiler_html_html.html(node);
184
- return node;
185
- }
186
- if (node?.type === "argument") {
187
- if (node.format) return require_transpiler_insertion_insertion.insert(`{${node.name}, ${node.format.type}${node.format.style ? `, ${node.format.style}` : ""}}`);
188
- return require_transpiler_insertion_insertion.insert(`{{${node.name}}}`);
189
- }
190
- if (node?.type === "plural") {
191
- const options = {};
192
- let hasExactMatch = false;
193
- for (const key of Object.keys(node.options)) if (key.startsWith("=")) {
194
- hasExactMatch = true;
195
- break;
196
- }
197
- if (hasExactMatch) {
198
- for (const [key, val] of Object.entries(node.options)) {
199
- let newKey = key;
200
- if (key.startsWith("=")) newKey = key.substring(1);
201
- else if (key === "one") newKey = "1";
202
- else if (key === "two") newKey = "2";
203
- else if (key === "few") newKey = "<=3";
204
- else if (key === "many") newKey = ">=4";
205
- else if (key === "other") newKey = "fallback";
206
- const replacedVal = val.map((v) => {
207
- if (typeof v === "string") return v.replace(/#/g, `{{${node.name}}}`);
208
- return v;
209
- });
210
- options[newKey] = i18nextNodesToIntlayer(replacedVal);
211
- }
212
- options.__intlayer_icu_var = node.name;
213
- return require_transpiler_enumeration_enumeration.enu(options);
214
- } else {
215
- for (const [key, val] of Object.entries(node.options)) {
216
- const replacedVal = val.map((v) => {
217
- if (typeof v === "string") return v.replace(/#/g, `{{${node.name}}}`);
218
- return v;
219
- });
220
- options[key] = i18nextNodesToIntlayer(replacedVal);
221
- }
222
- return require_transpiler_plural_plural.plural(options);
223
- }
224
- }
225
- if (node?.type === "select") {
226
- const options = {};
227
- for (const [key, val] of Object.entries(node.options)) options[key === "other" ? "fallback" : key] = i18nextNodesToIntlayer(val);
228
- const optionKeys = Object.keys(options);
229
- if ((options.male || options.female) && optionKeys.every((k) => [
230
- "male",
231
- "female",
232
- "other",
233
- "fallback"
234
- ].includes(k))) return require_transpiler_gender_gender.gender({
235
- fallback: options.fallback,
236
- male: options.male,
237
- female: options.female
238
- });
239
- return require_transpiler_select_select.select(options, node.name);
240
- }
241
- }
242
- return nodes.map((node) => i18nextNodesToIntlayer([node]));
22
+ const i18nextMessageToIntlayer = (message) => {
23
+ if (HTML_TAG_PATTERN.test(message)) return require_transpiler_html_html.html(message);
24
+ if (INTERPOLATION_PATTERN.test(message)) return require_transpiler_insertion_insertion.insert(message);
25
+ return message;
243
26
  };
244
27
  const i18nextToIntlayerPlugin = {
245
- canHandle: (node) => typeof node === "string" && (node.includes("{") || node.includes("}") || /<[a-zA-Z0-9-]+[^>]*>/.test(node)),
246
- transform: (node) => {
247
- try {
248
- const ast = parseI18Next(node);
249
- return i18nextNodesToIntlayer(ast);
250
- } catch {
251
- return node;
252
- }
28
+ canHandle: (node) => typeof node === "string" && (node.includes("{{") || HTML_TAG_PATTERN.test(node)),
29
+ transform: (node) => i18nextMessageToIntlayer(node)
30
+ };
31
+ const isContentRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && !("nodeType" in value);
32
+ /** Plural variable i18next reads `key_<category>` suffixes on. */
33
+ const I18NEXT_PLURAL_VARIABLE = "count";
34
+ /**
35
+ * i18next entries for a plural, gender or select node stored under `key`:
36
+ * `key_one`/`key_other` for a plural on `count`; `key_male`… with `key` as the
37
+ * fallback for a context; `key_male_one` for a plural inside a context.
38
+ * `undefined` when the node has no suffix form (it is written as ICU).
39
+ */
40
+ const getSuffixedEntries = (key, value, isContextAllowed = true) => {
41
+ if (typeof value !== "object" || value === null) return void 0;
42
+ const node = value;
43
+ if (node.nodeType === _intlayer_types_nodeType.PLURAL) {
44
+ if (node.variable && node.variable !== I18NEXT_PLURAL_VARIABLE) return;
45
+ return Object.entries(node[_intlayer_types_nodeType.PLURAL]).filter(([, content]) => content !== void 0).map(([category, content]) => [`${key}_${category}`, content]);
253
46
  }
47
+ if (isContextAllowed && (node.nodeType === _intlayer_types_nodeType.GENDER || node.nodeType === _intlayer_types_nodeType.SELECT)) return Object.entries(node[node.nodeType]).filter(([, content]) => content !== void 0).flatMap(([context, content]) => {
48
+ const contextKey = context === "fallback" ? key : `${key}_${context}`;
49
+ return getSuffixedEntries(contextKey, content, false) ?? [[contextKey, content]];
50
+ });
51
+ };
52
+ /**
53
+ * Rewrites plural, gender and select nodes held by object keys as i18next
54
+ * suffixed keys, which plain i18next resolves (it prints ICU blocks as text).
55
+ * A node keeps its key, and is written as ICU, when a suffixed key would
56
+ * overwrite an existing sibling.
57
+ */
58
+ const expandSuffixedKeys = (content) => {
59
+ if (Array.isArray(content)) return content.map(expandSuffixedKeys);
60
+ if (!isContentRecord(content)) return content;
61
+ const expandedEntries = Object.entries(content).flatMap(([key, value]) => {
62
+ const suffixedEntries = getSuffixedEntries(key, value);
63
+ const isCollisionFree = suffixedEntries?.every(([suffixedKey]) => suffixedKey === key || !(suffixedKey in content));
64
+ return suffixedEntries && isCollisionFree ? suffixedEntries : [[key, value]];
65
+ });
66
+ return Object.fromEntries(expandedEntries.map(([key, value]) => [key, expandSuffixedKeys(value)]));
254
67
  };
255
68
  const intlayerToI18nextPlugin = {
256
69
  canHandle: (node) => {
@@ -282,17 +95,12 @@ const intlayerToI18nextPlugin = {
282
95
  const childVal = next(val, props);
283
96
  transformedOptions[key] = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
284
97
  }
285
- let varName = "count";
286
- const fallbackVal = transformedOptions.other || Object.values(transformedOptions)[0];
287
- if (fallbackVal) {
288
- const match = fallbackVal.match(/\{\{([a-zA-Z0-9_]+)\}\}/) || fallbackVal.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);
289
- if (match?.[1]) varName = match[1];
290
- }
98
+ const varName = node.variable ?? I18NEXT_PLURAL_VARIABLE;
291
99
  const parts = [];
292
100
  for (const [key, val] of Object.entries(transformedOptions)) {
293
101
  const icuKey = key;
294
102
  let strVal = val;
295
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
103
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
296
104
  strVal = strVal.replace(new RegExp(`\\{${varName}\\}`, "g"), "#");
297
105
  parts.push(`${icuKey} {${strVal}}`);
298
106
  }
@@ -309,7 +117,7 @@ const intlayerToI18nextPlugin = {
309
117
  let varName = options.__intlayer_icu_var || "count";
310
118
  if (!options.__intlayer_icu_var) {
311
119
  const fallbackVal = transformedOptions.fallback || transformedOptions.other || Object.values(transformedOptions)[0];
312
- const match = fallbackVal?.match(/\{\{([a-zA-Z0-9_]+)\}\}/) || fallbackVal?.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);
120
+ const match = fallbackVal?.match(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/) || fallbackVal?.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);
313
121
  if (match?.[1]) varName = match[1];
314
122
  }
315
123
  const keys = Object.keys(transformedOptions);
@@ -336,7 +144,7 @@ const intlayerToI18nextPlugin = {
336
144
  else if (key === ">=4") icuKey = "many";
337
145
  else if (/^\d+$/.test(key)) icuKey = `=${key}`;
338
146
  let strVal = val;
339
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
147
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
340
148
  strVal = strVal.replace(new RegExp(`\\{${varName}\\}`, "g"), "#");
341
149
  parts.push(`${icuKey} {${strVal}}`);
342
150
  }
@@ -351,7 +159,7 @@ const intlayerToI18nextPlugin = {
351
159
  let icuKey = key;
352
160
  if (key === "fallback") icuKey = "other";
353
161
  let strVal = val;
354
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
162
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
355
163
  parts.push(`${icuKey} {${strVal}}`);
356
164
  }
357
165
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -371,7 +179,7 @@ const intlayerToI18nextPlugin = {
371
179
  if (key === "fallback") icuKey = "other";
372
180
  const childVal = next(val, props);
373
181
  let strVal = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
374
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
182
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
375
183
  parts.push(`${icuKey} {${strVal}}`);
376
184
  }
377
185
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -389,7 +197,7 @@ const intlayerToI18nextPlugin = {
389
197
  const icuKey = key === "fallback" ? "other" : key;
390
198
  const childVal = next(val, props);
391
199
  let strVal = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
392
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
200
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
393
201
  parts.push(`${icuKey} {${strVal}}`);
394
202
  }
395
203
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -399,7 +207,7 @@ const intlayerToI18nextPlugin = {
399
207
  }
400
208
  };
401
209
  const intlayerToI18nextFormatter = (message) => {
402
- return require_interpreter_getContent_deepTransform.deepTransformNode(message, {
210
+ return require_interpreter_getContent_deepTransform.deepTransformNode(expandSuffixedKeys(message), {
403
211
  dictionaryKey: "i18next",
404
212
  keyPath: [],
405
213
  plugins: [{
@@ -1 +1 @@
1
- {"version":3,"file":"i18next.cjs","names":["html","insert","enu","plural","gender","select","NodeTypes","deepTransformNode"],"sources":["../../../src/messageFormat/i18next.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, gender, html, insert, plural, select } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype I18NextNode =\n | string\n | {\n type: 'argument';\n name: string;\n format?: { type: string; style?: string };\n }\n | { type: 'plural'; name: string; options: Record<string, I18NextNode[]> }\n | { type: 'select'; name: string; options: Record<string, I18NextNode[]> };\n\n/** `{name, plural|select|number|date|time …`: an ICU argument with a format. */\nconst FORMATTED_ARGUMENT_PATTERN =\n /^\\{\\s*[\\p{L}\\p{N}_$][\\p{L}\\p{N}_$.-]*\\s*,\\s*(?:plural|select|number|date|time)\\s*[,}]/u;\n\n/** `{name}`: a bare ICU argument. */\nconst SIMPLE_ARGUMENT_PATTERN = /^\\{\\s*[\\p{L}\\p{N}_$][\\p{L}\\p{N}_$.-]*\\s*\\}/u;\n\n/**\n * Parses an i18next message into nodes.\n *\n * i18next treats single braces as literal text, so a lone `{…}` or `}` at the\n * top level stays text (`Press {Ctrl+K}`, `$t(key, {\"count\": 1})`). Only ICU\n * blocks with a known format (`{count, plural, …}`) are parsed there; bare\n * `{name}` arguments are read inside plural/select options, where the reverse\n * formatter writes them.\n */\nconst parseI18Next = (text: string): I18NextNode[] => {\n let index = 0;\n\n const isICUArgumentStart = (isInsideOption: boolean): boolean => {\n const remainingText = text.slice(index);\n\n return (\n FORMATTED_ARGUMENT_PATTERN.test(remainingText) ||\n (isInsideOption && SIMPLE_ARGUMENT_PATTERN.test(remainingText))\n );\n };\n\n const parseNodes = (isInsideOption: boolean): I18NextNode[] => {\n const nodes: I18NextNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n // Standard i18next variable: {{var}}\n if (char === '{' && text[index + 1] === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index += 2; // skip {{\n nodes.push(parseStandardArgument());\n }\n // ICU syntax: {var, plural, ...}, or {var} inside an option\n else if (char === '{' && isICUArgumentStart(isInsideOption)) {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseICUArgument());\n } else if (char === '}' && isInsideOption) {\n // End of the current plural/select option\n break;\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n return nodes;\n };\n\n const parseStandardArgument = (): I18NextNode => {\n // We are past '{{'\n let name = '';\n while (index < text.length) {\n // Check for closing }}\n if (text[index] === '}' && text[index + 1] === '}') {\n index += 2; // skip }}\n // Unescaped `{{- name}}` → `{{-name}}`: the compat runtime exposes\n // every value, unescaped, under `-name`.\n return { type: 'argument', name: name.trim().replace(/^-\\s+/, '-') };\n }\n name += text[index];\n index++;\n }\n throw new Error('Unclosed i18next variable');\n };\n\n const parseICUArgument = (): I18NextNode => {\n // We are past '{'\n let name = '';\n while (index < text.length && /[^,}]/.test(text[index]!)) {\n name += text[index];\n index++;\n }\n name = name.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name };\n }\n\n // Must be comma\n if (text[index] === ',') {\n index++;\n // Parse type\n let type = '';\n while (index < text.length && /[^,}]/.test(text[index]!)) {\n type += text[index];\n index++;\n }\n type = type.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name, format: { type } };\n }\n\n if (text[index] === ',') {\n index++;\n\n // If plural or select, parse options\n if (type === 'plural' || type === 'select') {\n const options: Record<string, I18NextNode[]> = {};\n\n while (index < text.length && text[index] !== '}') {\n while (index < text.length && /\\s/.test(text[index]!)) index++;\n\n let key = '';\n while (index < text.length && /[^{\\s]/.test(text[index]!)) {\n key += text[index];\n index++;\n }\n\n while (index < text.length && /\\s/.test(text[index]!)) index++;\n\n if (text[index] !== '{')\n throw new Error('Expected { after option key');\n index++; // skip {\n\n const value = parseNodes(true);\n\n if (text[index] !== '}')\n throw new Error('Expected } after option value');\n index++; // skip }\n\n options[key] = value;\n\n while (index < text.length && /\\s/.test(text[index]!)) index++;\n }\n\n index++; // skip closing argument }\n\n if (type === 'plural') {\n return { type: 'plural', name, options };\n } else if (type === 'select') {\n return { type: 'select', name, options };\n }\n } else {\n // Parse style for number/date/time\n let style = '';\n while (index < text.length && text[index] !== '}') {\n style += text[index];\n index++;\n }\n if (index >= text.length) throw new Error('Unclosed argument');\n\n style = style.trim();\n index++; // skip }\n\n return { type: 'argument', name, format: { type, style } };\n }\n }\n }\n\n throw new Error('Malformed argument');\n };\n\n return parseNodes(false);\n};\n\nconst i18nextNodesToIntlayer = (nodes: I18NextNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') {\n const node = nodes[0];\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n const canFlatten = nodes.every(\n (node) => typeof node === 'string' || node.type === 'argument'\n );\n\n if (canFlatten) {\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else if (typeof node !== 'string' && node.type === 'argument') {\n if (node.format) {\n // For formatted arguments, use ICU syntax: {name, type, style}\n str += `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`;\n } else {\n // For simple arguments, use standard i18next: {{name}}\n str += `{{${node.name}}}`;\n }\n }\n }\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) {\n return html(str);\n }\n return insert(str);\n }\n\n if (nodes.length === 1) {\n const node = nodes[0];\n if (typeof node === 'string') {\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n if (node?.type === 'argument') {\n if (node.format) {\n return insert(\n `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`\n );\n }\n return insert(`{{${node.name}}}`);\n }\n\n if (node?.type === 'plural') {\n const options: Record<string, any> = {};\n let hasExactMatch = false;\n\n for (const key of Object.keys(node.options)) {\n if (key.startsWith('=')) {\n hasExactMatch = true;\n break;\n }\n }\n\n if (hasExactMatch) {\n for (const [key, val] of Object.entries(node.options)) {\n let newKey = key;\n if (key.startsWith('=')) {\n newKey = key.substring(1);\n } else if (key === 'one') {\n newKey = '1';\n } else if (key === 'two') {\n newKey = '2';\n } else if (key === 'few') {\n newKey = '<=3';\n } else if (key === 'many') {\n newKey = '>=4';\n } else if (key === 'other') {\n newKey = 'fallback';\n }\n // Handle # replacement\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n // In ICU plural, # is replaced by the number\n // In i18next, if using ICU plugin, it behaves same.\n // We map it to {{varName}} in Intlayer\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[newKey] = i18nextNodesToIntlayer(replacedVal);\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n } else {\n for (const [key, val] of Object.entries(node.options)) {\n // Handle # replacement\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[key] = i18nextNodesToIntlayer(replacedVal);\n }\n\n return plural(options as any);\n }\n }\n\n if (node?.type === 'select') {\n const options: Record<string, any> = {};\n for (const [key, val] of Object.entries(node.options)) {\n // ICU names its catch-all case `other`; intlayer names it `fallback`.\n options[key === 'other' ? 'fallback' : key] =\n i18nextNodesToIntlayer(val);\n }\n\n // Check for gender\n const optionKeys = Object.keys(options);\n const isGender =\n (options.male || options.female) &&\n optionKeys.every((k) =>\n ['male', 'female', 'other', 'fallback'].includes(k)\n );\n\n if (isGender) {\n return gender({\n fallback: options.fallback,\n male: options.male,\n female: options.female,\n });\n }\n\n // Any other discriminant maps to a `select` node, which resolves on\n // arbitrary string values at runtime.\n return select(options, node.name);\n }\n }\n\n return nodes.map((node) => i18nextNodesToIntlayer([node]));\n};\n\nconst i18nextToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' &&\n (node.includes('{') ||\n node.includes('}') ||\n /<[a-zA-Z0-9-]+[^>]*>/.test(node)),\n transform: (node: any) => {\n try {\n const ast = parseI18Next(node);\n return i18nextNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToI18nextPlugin = {\n canHandle: (node: any) => {\n if (typeof node === 'string') return true;\n\n if (\n node &&\n typeof node === 'object' &&\n (node.nodeType === NodeTypes.INSERTION ||\n node.nodeType === NodeTypes.HTML ||\n node.nodeType === NodeTypes.ENUMERATION ||\n node.nodeType === NodeTypes.PLURAL ||\n node.nodeType === NodeTypes.GENDER ||\n node.nodeType === NodeTypes.SELECT ||\n node.nodeType === 'composite')\n ) {\n return true;\n }\n\n if (Array.isArray(node)) {\n if (node.length === 0) return false;\n\n let hasNode = false;\n let hasPlainObjectOrArray = false;\n\n for (const item of node) {\n if (typeof item === 'string') {\n } else if (\n item &&\n typeof item === 'object' &&\n (item.nodeType === NodeTypes.INSERTION ||\n item.nodeType === NodeTypes.HTML ||\n item.nodeType === NodeTypes.ENUMERATION ||\n item.nodeType === NodeTypes.PLURAL ||\n item.nodeType === NodeTypes.GENDER ||\n item.nodeType === NodeTypes.SELECT ||\n item.nodeType === 'composite')\n ) {\n hasNode = true;\n } else {\n hasPlainObjectOrArray = true;\n }\n }\n\n // If it contains plain objects or nested arrays, it's a structural array\n if (hasPlainObjectOrArray) return false;\n // If it contains ONLY strings, it's a structural array, not a composite string\n if (!hasNode) return false;\n\n return true;\n }\n\n return false;\n },\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n return node;\n }\n\n if (node.nodeType === NodeTypes.INSERTION) {\n if (node[NodeTypes.INSERTION].match(/\\{[^}]*,[^}]*\\}/)) {\n return node[NodeTypes.INSERTION];\n }\n return node[NodeTypes.INSERTION];\n }\n\n if (node.nodeType === NodeTypes.HTML) {\n return node[NodeTypes.HTML];\n }\n\n if (node.nodeType === NodeTypes.PLURAL) {\n const options = node[NodeTypes.PLURAL];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n let varName = 'count';\n\n const fallbackVal =\n transformedOptions.other || Object.values(transformedOptions)[0];\n\n if (fallbackVal) {\n const match =\n fallbackVal.match(/\\{\\{([a-zA-Z0-9_]+)\\}\\}/) ||\n fallbackVal.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match?.[1]) {\n varName = match[1];\n }\n }\n\n const parts = [];\n\n for (const [key, val] of Object.entries(transformedOptions)) {\n const icuKey = key;\n let strVal = val;\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n }\n\n if (node.nodeType === NodeTypes.ENUMERATION) {\n const options = node[NodeTypes.ENUMERATION];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var' || key === '__intlayer_icu_ordinal')\n continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n let varName = options.__intlayer_icu_var || 'count';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n\n const match =\n fallbackVal?.match(/\\{\\{([a-zA-Z0-9_]+)\\}\\}/) ||\n fallbackVal?.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match?.[1]) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n\n let strVal = val;\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n let strVal = val;\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeTypes.GENDER) {\n const options = node[NodeTypes.GENDER];\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (node.nodeType === NodeTypes.SELECT) {\n const options = node[NodeTypes.SELECT];\n const varName = node.variable || 'value';\n const parts = [];\n\n // ICU requires the `other` case to come last.\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n const icuKey = key === 'fallback' ? 'other' : key;\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToI18nextFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...intlayerToI18nextPlugin }],\n });\n};\n\nexport const i18nextToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...i18nextToIntlayerPlugin }],\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAM,6BACJ;;AAGF,MAAM,0BAA0B;;;;;;;;;;AAWhC,MAAM,gBAAgB,SAAgC;CACpD,IAAI,QAAQ;CAEZ,MAAM,sBAAsB,mBAAqC;EAC/D,MAAM,gBAAgB,KAAK,MAAM,KAAK;EAEtC,OACE,2BAA2B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,KAAKA,yBAAU;GAC/B,MAAM,UAAU,KAAK,YAAY;GACjC,MAAM,QAAQ,CAAC;GAGf,MAAM,UAAU,OAAO,QAAQ,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU;IAC/D,IAAI,SAAS,YAAY,OAAO;IAChC,IAAI,SAAS,YAAY,OAAO;IAChC,OAAO;GACT,CAAC;GAED,KAAK,MAAM,CAAC,KAAK,QAAQ,SAAS;IAChC,MAAM,SAAS,QAAQ,aAAa,UAAU;IAE9C,MAAM,WAAW,KAAK,KAAK,KAAK;IAChC,IAAI,SACF,OAAO,aAAa,WAAW,WAAW,KAAK,UAAU,QAAQ;IAEnE,SAAS,OAAO,QAAQ,oBAAoB,MAAM;IAClD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE;GACpC;GACA,OAAO,IAAI,QAAQ,YAAY,MAAM,KAAK,GAAG,EAAE;EACjD;EAEA,IACE,MAAM,QAAQ,IAAI,KACjB,KAAK,aAAa,eAAe,MAAM,QAAQ,KAAK,SAAS,GAI9D,QAFY,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,UAC7B,CAAC,KAAK,SAAc,KAAK,MAAM,KAAK,CAC1C,CAAC,CAAC,KAAK,EAAE;EAGtB,OAAO,KAAK,MAAM,KAAK;CACzB;AACF;AAEA,MAAa,8BACX,YACc;CACd,OAAOC,+DAAkB,SAAS;EAChC,eAAe;EACf,SAAS,CAAC;EACV,SAAS,CAAC;GAAE,IAAI;GAAW,GAAG;EAAwB,CAAC;CACzD,CAAC;AACH;AAEA,MAAa,8BACX,YAC0B;CAC1B,OAAOA,+DAAkB,SAAS;EAChC,eAAe;EACf,SAAS,CAAC;EACV,SAAS,CAAC;GAAE,IAAI;GAAW,GAAG;EAAwB,CAAC;CACzD,CAAC;AACH"}
1
+ {"version":3,"file":"i18next.cjs","names":["html","insert","NodeTypes","deepTransformNode"],"sources":["../../../src/messageFormat/i18next.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { html, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n/** An HTML-like tag (`<strong>`, `<1>`), rendered through an `html` node. */\nconst HTML_TAG_PATTERN = /<[a-zA-Z0-9-]+[^>]*>/;\n\n/** A closed `{{…}}` interpolation. */\nconst INTERPOLATION_PATTERN = /\\{\\{[\\s\\S]*?\\}\\}/;\n\n/**\n * Converts one i18next message into intlayer content.\n *\n * As in i18next, only `{{…}}` is syntax: single braces stay text\n * (`Press {Ctrl+K}`, `$t(key, {\"count\": 1})`, ICU blocks), and each\n * interpolation keeps its spelling so write-back leaves the source unchanged.\n * Plurals and contexts are key suffixes (`key_one`, `key_male`), kept as keys.\n */\nconst i18nextMessageToIntlayer = (message: string) => {\n if (HTML_TAG_PATTERN.test(message)) return html(message);\n if (INTERPOLATION_PATTERN.test(message)) return insert(message);\n\n return message;\n};\n\nconst i18nextToIntlayerPlugin = {\n canHandle: (node: unknown): node is string =>\n typeof node === 'string' &&\n (node.includes('{{') || HTML_TAG_PATTERN.test(node)),\n transform: (node: string) => i18nextMessageToIntlayer(node),\n};\n\n/** Content keyed by name: a plain object, not an intlayer node. */\ntype ContentRecord = Record<string, unknown>;\n\nconst isContentRecord = (value: unknown): value is ContentRecord =>\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !('nodeType' in value);\n\n/** Plural variable i18next reads `key_<category>` suffixes on. */\nconst I18NEXT_PLURAL_VARIABLE = 'count';\n\n/**\n * i18next entries for a plural, gender or select node stored under `key`:\n * `key_one`/`key_other` for a plural on `count`; `key_male`… with `key` as the\n * fallback for a context; `key_male_one` for a plural inside a context.\n * `undefined` when the node has no suffix form (it is written as ICU).\n */\nconst getSuffixedEntries = (\n key: string,\n value: unknown,\n isContextAllowed = true\n): [string, unknown][] | undefined => {\n if (typeof value !== 'object' || value === null) return undefined;\n\n const node = value as ContentRecord & {\n nodeType?: string;\n variable?: string;\n };\n\n if (node.nodeType === NodeTypes.PLURAL) {\n if (node.variable && node.variable !== I18NEXT_PLURAL_VARIABLE) {\n return undefined;\n }\n\n return Object.entries(node[NodeTypes.PLURAL] as ContentRecord)\n .filter(([, content]) => content !== undefined)\n .map(([category, content]) => [`${key}_${category}`, content]);\n }\n\n if (\n isContextAllowed &&\n (node.nodeType === NodeTypes.GENDER || node.nodeType === NodeTypes.SELECT)\n ) {\n return Object.entries(node[node.nodeType] as ContentRecord)\n .filter(([, content]) => content !== undefined)\n .flatMap(([context, content]): [string, unknown][] => {\n const contextKey = context === 'fallback' ? key : `${key}_${context}`;\n\n return (\n getSuffixedEntries(contextKey, content, false) ?? [\n [contextKey, content],\n ]\n );\n });\n }\n\n return undefined;\n};\n\n/**\n * Rewrites plural, gender and select nodes held by object keys as i18next\n * suffixed keys, which plain i18next resolves (it prints ICU blocks as text).\n * A node keeps its key, and is written as ICU, when a suffixed key would\n * overwrite an existing sibling.\n */\nconst expandSuffixedKeys = (content: unknown): unknown => {\n if (Array.isArray(content)) return content.map(expandSuffixedKeys);\n if (!isContentRecord(content)) return content;\n\n const expandedEntries = Object.entries(content).flatMap(\n ([key, value]): [string, unknown][] => {\n const suffixedEntries = getSuffixedEntries(key, value);\n const isCollisionFree = suffixedEntries?.every(\n ([suffixedKey]) => suffixedKey === key || !(suffixedKey in content)\n );\n\n return suffixedEntries && isCollisionFree\n ? suffixedEntries\n : [[key, value]];\n }\n );\n\n return Object.fromEntries(\n expandedEntries.map(([key, value]) => [key, expandSuffixedKeys(value)])\n );\n};\n\nconst intlayerToI18nextPlugin = {\n canHandle: (node: any) => {\n if (typeof node === 'string') return true;\n\n if (\n node &&\n typeof node === 'object' &&\n (node.nodeType === NodeTypes.INSERTION ||\n node.nodeType === NodeTypes.HTML ||\n node.nodeType === NodeTypes.ENUMERATION ||\n node.nodeType === NodeTypes.PLURAL ||\n node.nodeType === NodeTypes.GENDER ||\n node.nodeType === NodeTypes.SELECT ||\n node.nodeType === 'composite')\n ) {\n return true;\n }\n\n if (Array.isArray(node)) {\n if (node.length === 0) return false;\n\n let hasNode = false;\n let hasPlainObjectOrArray = false;\n\n for (const item of node) {\n if (typeof item === 'string') {\n } else if (\n item &&\n typeof item === 'object' &&\n (item.nodeType === NodeTypes.INSERTION ||\n item.nodeType === NodeTypes.HTML ||\n item.nodeType === NodeTypes.ENUMERATION ||\n item.nodeType === NodeTypes.PLURAL ||\n item.nodeType === NodeTypes.GENDER ||\n item.nodeType === NodeTypes.SELECT ||\n item.nodeType === 'composite')\n ) {\n hasNode = true;\n } else {\n hasPlainObjectOrArray = true;\n }\n }\n\n // If it contains plain objects or nested arrays, it's a structural array\n if (hasPlainObjectOrArray) return false;\n // If it contains ONLY strings, it's a structural array, not a composite string\n if (!hasNode) return false;\n\n return true;\n }\n\n return false;\n },\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n return node;\n }\n\n if (node.nodeType === NodeTypes.INSERTION) {\n if (node[NodeTypes.INSERTION].match(/\\{[^}]*,[^}]*\\}/)) {\n return node[NodeTypes.INSERTION];\n }\n return node[NodeTypes.INSERTION];\n }\n\n if (node.nodeType === NodeTypes.HTML) {\n return node[NodeTypes.HTML];\n }\n\n if (node.nodeType === NodeTypes.PLURAL) {\n const options = node[NodeTypes.PLURAL];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // A plural selects on its `variable`, `count` by default\n const varName: string = node.variable ?? I18NEXT_PLURAL_VARIABLE;\n\n const parts = [];\n\n for (const [key, val] of Object.entries(transformedOptions)) {\n const icuKey = key;\n let strVal = val;\n\n strVal = strVal.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n }\n\n if (node.nodeType === NodeTypes.ENUMERATION) {\n const options = node[NodeTypes.ENUMERATION];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var' || key === '__intlayer_icu_ordinal')\n continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n let varName = options.__intlayer_icu_var || 'count';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n\n const match =\n fallbackVal?.match(/\\{\\{\\s*([a-zA-Z0-9_]+)\\s*\\}\\}/) ||\n fallbackVal?.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match?.[1]) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n\n let strVal = val;\n\n strVal = strVal.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n let strVal = val;\n strVal = strVal.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, '{$1}');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeTypes.GENDER) {\n const options = node[NodeTypes.GENDER];\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (node.nodeType === NodeTypes.SELECT) {\n const options = node[NodeTypes.SELECT];\n const varName = node.variable || 'value';\n const parts = [];\n\n // ICU requires the `other` case to come last.\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n const icuKey = key === 'fallback' ? 'other' : key;\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToI18nextFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(expandSuffixedKeys(message), {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...intlayerToI18nextPlugin }],\n });\n};\n\nexport const i18nextToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...i18nextToIntlayerPlugin }],\n });\n};\n"],"mappings":";;;;;;;;;;AAOA,MAAM,mBAAmB;;AAGzB,MAAM,wBAAwB;;;;;;;;;AAU9B,MAAM,4BAA4B,YAAoB;CACpD,IAAI,iBAAiB,KAAK,OAAO,GAAG,OAAOA,kCAAK,OAAO;CACvD,IAAI,sBAAsB,KAAK,OAAO,GAAG,OAAOC,8CAAO,OAAO;CAE9D,OAAO;AACT;AAEA,MAAM,0BAA0B;CAC9B,YAAY,SACV,OAAO,SAAS,aACf,KAAK,SAAS,IAAI,KAAK,iBAAiB,KAAK,IAAI;CACpD,YAAY,SAAiB,yBAAyB,IAAI;AAC5D;AAKA,MAAM,mBAAmB,UACvB,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,EAAE,cAAc;;AAGlB,MAAM,0BAA0B;;;;;;;AAQhC,MAAM,sBACJ,KACA,OACA,mBAAmB,SACiB;CACpC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CAExD,MAAM,OAAO;CAKb,IAAI,KAAK,aAAaC,yBAAU,QAAQ;EACtC,IAAI,KAAK,YAAY,KAAK,aAAa,yBACrC;EAGF,OAAO,OAAO,QAAQ,KAAKA,yBAAU,OAAwB,CAAC,CAC3D,QAAQ,GAAG,aAAa,YAAY,MAAS,CAAC,CAC9C,KAAK,CAAC,UAAU,aAAa,CAAC,GAAG,IAAI,GAAG,YAAY,OAAO,CAAC;CACjE;CAEA,IACE,qBACC,KAAK,aAAaA,yBAAU,UAAU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