@intlayer/core 9.9.3-canary.0 → 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,239 +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
- const parseI18Next = (text) => {
15
- let index = 0;
16
- const parseNodes = () => {
17
- const nodes = [];
18
- let currentText = "";
19
- while (index < text.length) {
20
- const char = text[index];
21
- if (char === "{" && text[index + 1] === "{") {
22
- if (currentText) {
23
- nodes.push(currentText);
24
- currentText = "";
25
- }
26
- index += 2;
27
- nodes.push(parseStandardArgument());
28
- } else if (char === "{") {
29
- if (currentText) {
30
- nodes.push(currentText);
31
- currentText = "";
32
- }
33
- index++;
34
- nodes.push(parseICUArgument());
35
- } else if (char === "}") break;
36
- else {
37
- currentText += char;
38
- index++;
39
- }
40
- }
41
- if (currentText) nodes.push(currentText);
42
- return nodes;
43
- };
44
- const parseStandardArgument = () => {
45
- let name = "";
46
- while (index < text.length) {
47
- if (text[index] === "}" && text[index + 1] === "}") {
48
- index += 2;
49
- return {
50
- type: "argument",
51
- name: name.trim().replace(/^-\s+/, "-")
52
- };
53
- }
54
- name += text[index];
55
- index++;
56
- }
57
- throw new Error("Unclosed i18next variable");
58
- };
59
- const parseICUArgument = () => {
60
- let name = "";
61
- while (index < text.length && /[^,}]/.test(text[index])) {
62
- name += text[index];
63
- index++;
64
- }
65
- name = name.trim();
66
- if (index >= text.length) throw new Error("Unclosed argument");
67
- if (text[index] === "}") {
68
- index++;
69
- return {
70
- type: "argument",
71
- name
72
- };
73
- }
74
- if (text[index] === ",") {
75
- index++;
76
- let type = "";
77
- while (index < text.length && /[^,}]/.test(text[index])) {
78
- type += text[index];
79
- index++;
80
- }
81
- type = type.trim();
82
- if (index >= text.length) throw new Error("Unclosed argument");
83
- if (text[index] === "}") {
84
- index++;
85
- return {
86
- type: "argument",
87
- name,
88
- format: { type }
89
- };
90
- }
91
- if (text[index] === ",") {
92
- index++;
93
- if (type === "plural" || type === "select") {
94
- const options = {};
95
- while (index < text.length && text[index] !== "}") {
96
- while (index < text.length && /\s/.test(text[index])) index++;
97
- let key = "";
98
- while (index < text.length && /[^{\s]/.test(text[index])) {
99
- key += text[index];
100
- index++;
101
- }
102
- while (index < text.length && /\s/.test(text[index])) index++;
103
- if (text[index] !== "{") throw new Error("Expected { after option key");
104
- index++;
105
- const value = parseNodes();
106
- if (text[index] !== "}") throw new Error("Expected } after option value");
107
- index++;
108
- options[key] = value;
109
- while (index < text.length && /\s/.test(text[index])) index++;
110
- }
111
- index++;
112
- if (type === "plural") return {
113
- type: "plural",
114
- name,
115
- options
116
- };
117
- else if (type === "select") return {
118
- type: "select",
119
- name,
120
- options
121
- };
122
- } else {
123
- let style = "";
124
- while (index < text.length && text[index] !== "}") {
125
- style += text[index];
126
- index++;
127
- }
128
- if (index >= text.length) throw new Error("Unclosed argument");
129
- style = style.trim();
130
- index++;
131
- return {
132
- type: "argument",
133
- name,
134
- format: {
135
- type,
136
- style
137
- }
138
- };
139
- }
140
- }
141
- }
142
- throw new Error("Malformed argument");
143
- };
144
- return parseNodes();
145
- };
146
- const i18nextNodesToIntlayer = (nodes) => {
147
- if (nodes.length === 0) return "";
148
- if (nodes.length === 1 && typeof nodes[0] === "string") {
149
- const node = nodes[0];
150
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) return require_transpiler_html_html.html(node);
151
- return node;
152
- }
153
- if (nodes.every((node) => typeof node === "string" || node.type === "argument")) {
154
- let str = "";
155
- for (const node of nodes) if (typeof node === "string") str += node;
156
- else if (typeof node !== "string" && node.type === "argument") {
157
- if (node.format) str += `{${node.name}, ${node.format.type}${node.format.style ? `, ${node.format.style}` : ""}}`;
158
- else str += `{{${node.name}}}`;
159
- }
160
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) return require_transpiler_html_html.html(str);
161
- return require_transpiler_insertion_insertion.insert(str);
162
- }
163
- if (nodes.length === 1) {
164
- const node = nodes[0];
165
- if (typeof node === "string") {
166
- if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) return require_transpiler_html_html.html(node);
167
- return node;
168
- }
169
- if (node?.type === "argument") {
170
- if (node.format) return require_transpiler_insertion_insertion.insert(`{${node.name}, ${node.format.type}${node.format.style ? `, ${node.format.style}` : ""}}`);
171
- return require_transpiler_insertion_insertion.insert(`{{${node.name}}}`);
172
- }
173
- if (node?.type === "plural") {
174
- const options = {};
175
- let hasExactMatch = false;
176
- for (const key of Object.keys(node.options)) if (key.startsWith("=")) {
177
- hasExactMatch = true;
178
- break;
179
- }
180
- if (hasExactMatch) {
181
- for (const [key, val] of Object.entries(node.options)) {
182
- let newKey = key;
183
- if (key.startsWith("=")) newKey = key.substring(1);
184
- else if (key === "one") newKey = "1";
185
- else if (key === "two") newKey = "2";
186
- else if (key === "few") newKey = "<=3";
187
- else if (key === "many") newKey = ">=4";
188
- else if (key === "other") newKey = "fallback";
189
- const replacedVal = val.map((v) => {
190
- if (typeof v === "string") return v.replace(/#/g, `{{${node.name}}}`);
191
- return v;
192
- });
193
- options[newKey] = i18nextNodesToIntlayer(replacedVal);
194
- }
195
- options.__intlayer_icu_var = node.name;
196
- return require_transpiler_enumeration_enumeration.enu(options);
197
- } else {
198
- for (const [key, val] of Object.entries(node.options)) {
199
- const replacedVal = val.map((v) => {
200
- if (typeof v === "string") return v.replace(/#/g, `{{${node.name}}}`);
201
- return v;
202
- });
203
- options[key] = i18nextNodesToIntlayer(replacedVal);
204
- }
205
- return require_transpiler_plural_plural.plural(options);
206
- }
207
- }
208
- if (node?.type === "select") {
209
- const options = {};
210
- for (const [key, val] of Object.entries(node.options)) options[key === "other" ? "fallback" : key] = i18nextNodesToIntlayer(val);
211
- const optionKeys = Object.keys(options);
212
- if ((options.male || options.female) && optionKeys.every((k) => [
213
- "male",
214
- "female",
215
- "other",
216
- "fallback"
217
- ].includes(k))) return require_transpiler_gender_gender.gender({
218
- fallback: options.fallback,
219
- male: options.male,
220
- female: options.female
221
- });
222
- return require_transpiler_select_select.select(options, node.name);
223
- }
224
- }
225
- return nodes.map((node) => i18nextNodesToIntlayer([node]));
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]*?\}\}/;
14
+ /**
15
+ * Converts one i18next message into intlayer content.
16
+ *
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.
21
+ */
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;
226
26
  };
227
27
  const i18nextToIntlayerPlugin = {
228
- canHandle: (node) => typeof node === "string" && (node.includes("{") || node.includes("}") || /<[a-zA-Z0-9-]+[^>]*>/.test(node)),
229
- transform: (node) => {
230
- try {
231
- const ast = parseI18Next(node);
232
- return i18nextNodesToIntlayer(ast);
233
- } catch {
234
- return node;
235
- }
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]);
236
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)]));
237
67
  };
238
68
  const intlayerToI18nextPlugin = {
239
69
  canHandle: (node) => {
@@ -265,17 +95,12 @@ const intlayerToI18nextPlugin = {
265
95
  const childVal = next(val, props);
266
96
  transformedOptions[key] = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
267
97
  }
268
- let varName = "count";
269
- const fallbackVal = transformedOptions.other || Object.values(transformedOptions)[0];
270
- if (fallbackVal) {
271
- const match = fallbackVal.match(/\{\{([a-zA-Z0-9_]+)\}\}/) || fallbackVal.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);
272
- if (match?.[1]) varName = match[1];
273
- }
98
+ const varName = node.variable ?? I18NEXT_PLURAL_VARIABLE;
274
99
  const parts = [];
275
100
  for (const [key, val] of Object.entries(transformedOptions)) {
276
101
  const icuKey = key;
277
102
  let strVal = val;
278
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
103
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
279
104
  strVal = strVal.replace(new RegExp(`\\{${varName}\\}`, "g"), "#");
280
105
  parts.push(`${icuKey} {${strVal}}`);
281
106
  }
@@ -292,7 +117,7 @@ const intlayerToI18nextPlugin = {
292
117
  let varName = options.__intlayer_icu_var || "count";
293
118
  if (!options.__intlayer_icu_var) {
294
119
  const fallbackVal = transformedOptions.fallback || transformedOptions.other || Object.values(transformedOptions)[0];
295
- 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_]+)\}(?!,)/);
296
121
  if (match?.[1]) varName = match[1];
297
122
  }
298
123
  const keys = Object.keys(transformedOptions);
@@ -319,7 +144,7 @@ const intlayerToI18nextPlugin = {
319
144
  else if (key === ">=4") icuKey = "many";
320
145
  else if (/^\d+$/.test(key)) icuKey = `=${key}`;
321
146
  let strVal = val;
322
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
147
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
323
148
  strVal = strVal.replace(new RegExp(`\\{${varName}\\}`, "g"), "#");
324
149
  parts.push(`${icuKey} {${strVal}}`);
325
150
  }
@@ -334,7 +159,7 @@ const intlayerToI18nextPlugin = {
334
159
  let icuKey = key;
335
160
  if (key === "fallback") icuKey = "other";
336
161
  let strVal = val;
337
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
162
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
338
163
  parts.push(`${icuKey} {${strVal}}`);
339
164
  }
340
165
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -354,7 +179,7 @@ const intlayerToI18nextPlugin = {
354
179
  if (key === "fallback") icuKey = "other";
355
180
  const childVal = next(val, props);
356
181
  let strVal = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
357
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
182
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
358
183
  parts.push(`${icuKey} {${strVal}}`);
359
184
  }
360
185
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -372,7 +197,7 @@ const intlayerToI18nextPlugin = {
372
197
  const icuKey = key === "fallback" ? "other" : key;
373
198
  const childVal = next(val, props);
374
199
  let strVal = typeof childVal === "string" ? childVal : JSON.stringify(childVal);
375
- strVal = strVal.replace(/\{\{([^}]+)\}\}/g, "{$1}");
200
+ strVal = strVal.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "{$1}");
376
201
  parts.push(`${icuKey} {${strVal}}`);
377
202
  }
378
203
  return `{${varName}, select, ${parts.join(" ")}}`;
@@ -382,7 +207,7 @@ const intlayerToI18nextPlugin = {
382
207
  }
383
208
  };
384
209
  const intlayerToI18nextFormatter = (message) => {
385
- return require_interpreter_getContent_deepTransform.deepTransformNode(message, {
210
+ return require_interpreter_getContent_deepTransform.deepTransformNode(expandSuffixedKeys(message), {
386
211
  dictionaryKey: "i18next",
387
212
  keyPath: [],
388
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\nconst parseI18Next = (text: string): I18NextNode[] => {\n let index = 0;\n\n const parseNodes = (): 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} or {var, plural, ...}\n else if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseICUArgument());\n } else if (char === '}') {\n // End of current block (likely ICU block end)\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();\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();\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":";;;;;;;;;;;;;AAiBA,MAAM,gBAAgB,SAAgC;CACpD,IAAI,QAAQ;CAEZ,MAAM,mBAAkC;EACtC,MAAM,QAAuB,CAAC;EAC9B,IAAI,cAAc;EAElB,OAAO,QAAQ,KAAK,QAAQ;GAC1B,MAAM,OAAO,KAAK;GAGlB,IAAI,SAAS,OAAO,KAAK,QAAQ,OAAO,KAAK;IAC3C,IAAI,aAAa;KACf,MAAM,KAAK,WAAW;KACtB,cAAc;IAChB;IACA,SAAS;IACT,MAAM,KAAK,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F,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,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AS,QAAQ,aAAa,UAAU;IAE9C,MAAM,WAAW,KAAK,KAAK,KAAK;IAChC,IAAI,SACF,OAAO,aAAa,WAAW,WAAW,KAAK,UAAU,QAAQ;IAEnE,SAAS,OAAO,QAAQ,2BAA2B,MAAM;IACzD,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,mBAAmB,OAAO,GAAG;EACpD,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"}
@@ -77,19 +77,25 @@ const formatArgument = (value, type, style, locale, formatters) => {
77
77
  * optionally formatted the i18next way (`{{price, number}}`)
78
78
  * 2. ICU formatted arguments `{value, number}` / `{ts, date, long}`
79
79
  * 3. Bare single-brace arguments `{name}` (ICU / vue-i18n simple args)
80
+ *
81
+ * With `'double-brace'` interpolation, only step 1 runs.
80
82
  */
81
- const interpolateMessage = (template, values = {}, locale = "en", formatters) => template.replace(/\{\{\s*([^{},]+?)\s*(?:,\s*(\w+)\s*(?:,\s*([^{}]+?)\s*)?)?\}\}/g, (match, path, type, style) => {
82
- const value = resolveValuePath(values, path);
83
- if (value === void 0) return match;
84
- return type ? formatArgument(value, type, style, locale, formatters) : String(value);
85
- }).replace(/\{\s*([\w.]+)\s*,\s*(\w+)\s*(?:,\s*([^}]+?)\s*)?\}/g, (match, path, type, style) => {
86
- const value = resolveValuePath(values, path);
87
- if (value === void 0) return match;
88
- return formatArgument(value, type, style, locale, formatters);
89
- }).replace(/\{\s*([\w.]+)\s*\}/g, (match, path) => {
90
- const value = resolveValuePath(values, path);
91
- return value === void 0 ? match : String(value);
92
- });
83
+ const interpolateMessage = (template, values = {}, locale = "en", formatters, interpolation = "default") => {
84
+ const interpolated = template.replace(/\{\{\s*([^{},]+?)\s*(?:,\s*(\w+)\s*(?:,\s*([^{}]+?)\s*)?)?\}\}/g, (match, path, type, style) => {
85
+ const value = resolveValuePath(values, path) ?? resolveValuePath(values, path.replace(/^-\s+/, "-"));
86
+ if (value === void 0) return match;
87
+ return type ? formatArgument(value, type, style, locale, formatters) : String(value);
88
+ });
89
+ if (interpolation === "double-brace") return interpolated;
90
+ return interpolated.replace(/\{\s*([\w.]+)\s*,\s*(\w+)\s*(?:,\s*([^}]+?)\s*)?\}/g, (match, path, type, style) => {
91
+ const value = resolveValuePath(values, path);
92
+ if (value === void 0) return match;
93
+ return formatArgument(value, type, style, locale, formatters);
94
+ }).replace(/\{\s*([\w.]+)\s*\}/g, (match, path) => {
95
+ const value = resolveValuePath(values, path);
96
+ return value === void 0 ? match : String(value);
97
+ });
98
+ };
93
99
  /** Reads the selector value of an enumeration/plural node from the values. */
94
100
  const getSelectorValue = (values, variableName) => values[variableName] ?? values.count ?? values.n;
95
101
  /**
@@ -100,25 +106,25 @@ const getSelectorValue = (values, variableName) => values[variableName] ?? value
100
106
  * Function nodes (produced by the interpreter plugins for `insertion`,
101
107
  * `enumeration` and `plural` content) are invoked with the values.
102
108
  */
103
- const resolveMessageNode = (node, values = {}, locale = "en", formatters) => {
109
+ const resolveMessageNode = (node, values = {}, locale = "en", formatters, interpolation = "default") => {
104
110
  if (node === null || node === void 0) return node;
105
- if (typeof node === "string") return interpolateMessage(node, values, locale, formatters);
111
+ if (typeof node === "string") return interpolateMessage(node, values, locale, formatters, interpolation);
106
112
  if (typeof node === "number" || typeof node === "boolean") return String(node);
107
113
  if (typeof node === "function") try {
108
- return resolveMessageNode(node(values), values, locale, formatters);
114
+ return resolveMessageNode(node(values), values, locale, formatters, interpolation);
109
115
  } catch {
110
116
  return;
111
117
  }
112
- if (Array.isArray(node)) return node.map((item) => String(resolveMessageNode(item, values, locale, formatters) ?? "")).join("");
118
+ if (Array.isArray(node)) return node.map((item) => String(resolveMessageNode(item, values, locale, formatters, interpolation) ?? "")).join("");
113
119
  const typedNode = node;
114
- if (typedNode.nodeType === _intlayer_types_nodeType.INSERTION) return resolveMessageNode(typedNode[_intlayer_types_nodeType.INSERTION], values, locale, formatters);
115
- if (typedNode.nodeType === _intlayer_types_nodeType.HTML) return resolveMessageNode(typedNode[_intlayer_types_nodeType.HTML], values, locale, formatters);
120
+ if (typedNode.nodeType === _intlayer_types_nodeType.INSERTION) return resolveMessageNode(typedNode[_intlayer_types_nodeType.INSERTION], values, locale, formatters, interpolation);
121
+ if (typedNode.nodeType === _intlayer_types_nodeType.HTML) return resolveMessageNode(typedNode[_intlayer_types_nodeType.HTML], values, locale, formatters, interpolation);
116
122
  if (typedNode.nodeType === _intlayer_types_nodeType.PLURAL) {
117
123
  const pluralState = typedNode[_intlayer_types_nodeType.PLURAL];
118
124
  const variableName = typeof typedNode.variable === "string" ? typedNode.variable : require_transpiler_plural_plural.DEFAULT_PLURAL_VARIABLE;
119
125
  const count = Number(getSelectorValue(values, variableName) ?? 1);
120
126
  const selected = require_interpreter_getPlural.getPlural(pluralState, count, locale);
121
- return resolveMessageNode(selected, values, locale, formatters);
127
+ return resolveMessageNode(selected, values, locale, formatters, interpolation);
122
128
  }
123
129
  if (typedNode.nodeType === _intlayer_types_nodeType.ENUMERATION) {
124
130
  const enumerationState = typedNode[_intlayer_types_nodeType.ENUMERATION];
@@ -137,19 +143,19 @@ const resolveMessageNode = (node, values = {}, locale = "en", formatters) => {
137
143
  const matchedKey = require_interpreter_getEnumeration.findMatchingCondition(options, count);
138
144
  selected = matchedKey ? options[matchedKey] : options[require_utils_intl.getCachedIntl("PluralRules", locale).select(count)] ?? require_interpreter_getEnumeration.getEnumeration(options, count);
139
145
  } else selected = options[String(selector)] ?? options.fallback ?? options.other;
140
- return resolveMessageNode(selected, values, locale, formatters);
146
+ return resolveMessageNode(selected, values, locale, formatters, interpolation);
141
147
  }
142
148
  if (typedNode.nodeType === _intlayer_types_nodeType.SELECT) {
143
149
  const selectState = typedNode[_intlayer_types_nodeType.SELECT];
144
150
  const variableName = typeof typedNode.variable === "string" ? typedNode.variable : "value";
145
151
  const selector = getSelectorValue(values, variableName);
146
152
  const selected = require_interpreter_getSelect.getSelect(selectState, String(selector ?? ""));
147
- return resolveMessageNode(selected, values, locale, formatters);
153
+ return resolveMessageNode(selected, values, locale, formatters, interpolation);
148
154
  }
149
155
  if (typedNode.nodeType === _intlayer_types_nodeType.GENDER) {
150
156
  const genderState = typedNode[_intlayer_types_nodeType.GENDER];
151
157
  const selected = genderState[String(values.gender ?? "")] ?? genderState.fallback ?? genderState.other;
152
- return resolveMessageNode(selected, values, locale, formatters);
158
+ return resolveMessageNode(selected, values, locale, formatters, interpolation);
153
159
  }
154
160
  return node;
155
161
  };
@@ -160,10 +166,11 @@ const resolveMessageNode = (node, values = {}, locale = "en", formatters) => {
160
166
  * the bundle through a built dictionary: the build already converted every
161
167
  * dialect construct into intlayer nodes, and the interpreter turned those into
162
168
  * callables, so no message parser is involved. Plain strings still get
163
- * `{{name}}` / `{name}` / `{value, number}` interpolation.
169
+ * `{{name}}` / `{name}` / `{value, number}` interpolation (only `{{…}}` with
170
+ * `'double-brace'` interpolation).
164
171
  */
165
- const resolveMessageNodeToString = (node, values = {}, locale = "en", formatters) => {
166
- const resolved = resolveMessageNode(node, values, locale, formatters);
172
+ const resolveMessageNodeToString = (node, values = {}, locale = "en", formatters, interpolation = "default") => {
173
+ const resolved = resolveMessageNode(node, values, locale, formatters, interpolation);
167
174
  return typeof resolved === "string" ? resolved : String(resolved ?? "");
168
175
  };
169
176
  /**
@@ -179,12 +186,18 @@ const resolveMessageNodeToString = (node, values = {}, locale = "en", formatters
179
186
  * resolveIcuMessage('Hello {name}', { name: 'John' }, 'en'); // 'Hello John'
180
187
  * ```
181
188
  */
182
- const createMessageResolver = (formatter) => (message, values = {}, locale = "en", formatters) => resolveMessageNodeToString(typeof message === "string" ? formatter(message) : message, values, locale, formatters);
189
+ const createMessageResolver = (formatter, interpolation = "default") => (message, values = {}, locale = "en", formatters) => resolveMessageNodeToString(typeof message === "string" ? formatter(message) : message, values, locale, formatters, interpolation);
183
190
  const DIALECT_FORMATTERS = {
184
191
  icu: require_messageFormat_ICU.icuToIntlayerFormatter,
185
192
  i18next: require_messageFormat_i18next.i18nextToIntlayerFormatter,
186
193
  "vue-i18n": require_messageFormat_vue_i18n.vueI18nToIntlayerFormatter
187
194
  };
195
+ /** i18next reads only `{{…}}`; the other dialects use single braces too. */
196
+ const DIALECT_INTERPOLATION = {
197
+ icu: "default",
198
+ i18next: "double-brace",
199
+ "vue-i18n": "default"
200
+ };
188
201
  /**
189
202
  * Resolves a raw message — string in a library dialect, or an intlayer node
190
203
  * tree — into a final string using interpolation values and locale.
@@ -206,7 +219,7 @@ const DIALECT_FORMATTERS = {
206
219
  * // '3 items'
207
220
  * ```
208
221
  */
209
- const resolveMessage = (message, values = {}, locale = "en", dialect = "icu") => createMessageResolver(DIALECT_FORMATTERS[dialect])(message, values, locale);
222
+ const resolveMessage = (message, values = {}, locale = "en", dialect = "icu") => createMessageResolver(DIALECT_FORMATTERS[dialect], DIALECT_INTERPOLATION[dialect])(message, values, locale);
210
223
  /**
211
224
  * Tokenizes a message containing XML-like tags (`'Visit <link>the docs</link>'`,
212
225
  * `'hello <1>{{name}}</1>'`, `'line<br/>break'`) into a token tree.