@angular/localize 13.0.0-rc.1 → 13.1.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,904 @@
1
+
2
+ import {createRequire as __cjsCompatRequire} from 'module';
3
+ const require = __cjsCompatRequire(import.meta.url);
4
+
5
+ import {
6
+ Diagnostics,
7
+ buildCodeFrameError,
8
+ getLocation,
9
+ isBabelParseError,
10
+ isGlobalIdentifier,
11
+ isNamedIdentifier,
12
+ serializeLocationPosition,
13
+ transformSync,
14
+ unwrapExpressionsFromTemplateLiteral,
15
+ unwrapMessagePartsFromLocalizeCall,
16
+ unwrapMessagePartsFromTemplateLiteral,
17
+ unwrapSubstitutionsFromLocalizeCall
18
+ } from "./chunk-PHXSPSJE.js";
19
+ import {
20
+ __spreadValues
21
+ } from "./chunk-KZHPLSGS.js";
22
+
23
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/duplicates.mjs
24
+ function checkDuplicateMessages(fs, messages, duplicateMessageHandling, basePath) {
25
+ const diagnostics = new Diagnostics();
26
+ if (duplicateMessageHandling === "ignore")
27
+ return diagnostics;
28
+ const messageMap = new Map();
29
+ for (const message of messages) {
30
+ if (messageMap.has(message.id)) {
31
+ messageMap.get(message.id).push(message);
32
+ } else {
33
+ messageMap.set(message.id, [message]);
34
+ }
35
+ }
36
+ for (const duplicates of messageMap.values()) {
37
+ if (duplicates.length <= 1)
38
+ continue;
39
+ if (duplicates.every((message) => message.text === duplicates[0].text))
40
+ continue;
41
+ const diagnosticMessage = `Duplicate messages with id "${duplicates[0].id}":
42
+ ` + duplicates.map((message) => serializeMessage(fs, basePath, message)).join("\n");
43
+ diagnostics.add(duplicateMessageHandling, diagnosticMessage);
44
+ }
45
+ return diagnostics;
46
+ }
47
+ function serializeMessage(fs, basePath, message) {
48
+ if (message.location === void 0) {
49
+ return ` - "${message.text}"`;
50
+ } else {
51
+ const locationFile = fs.relative(basePath, message.location.file);
52
+ const locationPosition = serializeLocationPosition(message.location);
53
+ return ` - "${message.text}" : ${locationFile}:${locationPosition}`;
54
+ }
55
+ }
56
+
57
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
58
+ import { SourceFileLoader } from "@angular/compiler-cli/private/localize";
59
+
60
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es2015_extract_plugin.mjs
61
+ import { \u0275parseMessage } from "@angular/localize";
62
+ function makeEs2015ExtractPlugin(fs, messages, localizeName = "$localize") {
63
+ return {
64
+ visitor: {
65
+ TaggedTemplateExpression(path) {
66
+ const tag = path.get("tag");
67
+ if (isNamedIdentifier(tag, localizeName) && isGlobalIdentifier(tag)) {
68
+ const quasiPath = path.get("quasi");
69
+ const [messageParts, messagePartLocations] = unwrapMessagePartsFromTemplateLiteral(quasiPath.get("quasis"), fs);
70
+ const [expressions, expressionLocations] = unwrapExpressionsFromTemplateLiteral(quasiPath, fs);
71
+ const location = getLocation(fs, quasiPath);
72
+ const message = \u0275parseMessage(messageParts, expressions, location, messagePartLocations, expressionLocations);
73
+ messages.push(message);
74
+ }
75
+ }
76
+ }
77
+ };
78
+ }
79
+
80
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es5_extract_plugin.mjs
81
+ import { \u0275parseMessage as \u0275parseMessage2 } from "@angular/localize";
82
+ function makeEs5ExtractPlugin(fs, messages, localizeName = "$localize") {
83
+ return {
84
+ visitor: {
85
+ CallExpression(callPath) {
86
+ try {
87
+ const calleePath = callPath.get("callee");
88
+ if (isNamedIdentifier(calleePath, localizeName) && isGlobalIdentifier(calleePath)) {
89
+ const [messageParts, messagePartLocations] = unwrapMessagePartsFromLocalizeCall(callPath, fs);
90
+ const [expressions, expressionLocations] = unwrapSubstitutionsFromLocalizeCall(callPath, fs);
91
+ const [messagePartsArg, expressionsArg] = callPath.get("arguments");
92
+ const location = getLocation(fs, messagePartsArg, expressionsArg);
93
+ const message = \u0275parseMessage2(messageParts, expressions, location, messagePartLocations, expressionLocations);
94
+ messages.push(message);
95
+ }
96
+ } catch (e) {
97
+ if (isBabelParseError(e)) {
98
+ throw buildCodeFrameError(fs, callPath, e);
99
+ } else {
100
+ throw e;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ };
106
+ }
107
+
108
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
109
+ var MessageExtractor = class {
110
+ constructor(fs, logger, { basePath, useSourceMaps = true, localizeName = "$localize" }) {
111
+ this.fs = fs;
112
+ this.logger = logger;
113
+ this.basePath = basePath;
114
+ this.useSourceMaps = useSourceMaps;
115
+ this.localizeName = localizeName;
116
+ this.loader = new SourceFileLoader(this.fs, this.logger, { webpack: basePath });
117
+ }
118
+ extractMessages(filename) {
119
+ const messages = [];
120
+ const sourceCode = this.fs.readFile(this.fs.resolve(this.basePath, filename));
121
+ if (sourceCode.includes(this.localizeName)) {
122
+ transformSync(sourceCode, {
123
+ sourceRoot: this.basePath,
124
+ filename,
125
+ plugins: [
126
+ makeEs2015ExtractPlugin(this.fs, messages, this.localizeName),
127
+ makeEs5ExtractPlugin(this.fs, messages, this.localizeName)
128
+ ],
129
+ code: false,
130
+ ast: false
131
+ });
132
+ if (this.useSourceMaps && messages.length > 0) {
133
+ this.updateSourceLocations(filename, sourceCode, messages);
134
+ }
135
+ }
136
+ return messages;
137
+ }
138
+ updateSourceLocations(filename, contents, messages) {
139
+ const sourceFile = this.loader.loadSourceFile(this.fs.resolve(this.basePath, filename), contents);
140
+ if (sourceFile === null) {
141
+ return;
142
+ }
143
+ for (const message of messages) {
144
+ if (message.location !== void 0) {
145
+ message.location = this.getOriginalLocation(sourceFile, message.location);
146
+ if (message.messagePartLocations) {
147
+ message.messagePartLocations = message.messagePartLocations.map((location) => location && this.getOriginalLocation(sourceFile, location));
148
+ }
149
+ if (message.substitutionLocations) {
150
+ const placeholderNames = Object.keys(message.substitutionLocations);
151
+ for (const placeholderName of placeholderNames) {
152
+ const location = message.substitutionLocations[placeholderName];
153
+ message.substitutionLocations[placeholderName] = location && this.getOriginalLocation(sourceFile, location);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
159
+ getOriginalLocation(sourceFile, location) {
160
+ const originalStart = sourceFile.getOriginalLocation(location.start.line, location.start.column);
161
+ if (originalStart === null) {
162
+ return location;
163
+ }
164
+ const originalEnd = sourceFile.getOriginalLocation(location.end.line, location.end.column);
165
+ const start = { line: originalStart.line, column: originalStart.column };
166
+ const end = originalEnd !== null && originalEnd.file === originalStart.file ? { line: originalEnd.line, column: originalEnd.column } : start;
167
+ const originalSourceFile = sourceFile.sources.find((sf) => (sf == null ? void 0 : sf.sourcePath) === originalStart.file);
168
+ const startPos = originalSourceFile.startOfLinePositions[start.line] + start.column;
169
+ const endPos = originalSourceFile.startOfLinePositions[end.line] + end.column;
170
+ const text = originalSourceFile.contents.substring(startPos, endPos).trim();
171
+ return { file: originalStart.file, start, end, text };
172
+ }
173
+ };
174
+
175
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/utils.mjs
176
+ function consolidateMessages(messages, getMessageId2) {
177
+ const messageGroups = new Map();
178
+ for (const message of messages) {
179
+ const id = getMessageId2(message);
180
+ if (!messageGroups.has(id)) {
181
+ messageGroups.set(id, [message]);
182
+ } else {
183
+ messageGroups.get(id).push(message);
184
+ }
185
+ }
186
+ for (const messages2 of messageGroups.values()) {
187
+ messages2.sort(compareLocations);
188
+ }
189
+ return Array.from(messageGroups.values()).sort((a1, a2) => compareLocations(a1[0], a2[0]));
190
+ }
191
+ function hasLocation(message) {
192
+ return message.location !== void 0;
193
+ }
194
+ function compareLocations({ location: location1 }, { location: location2 }) {
195
+ if (location1 === location2) {
196
+ return 0;
197
+ }
198
+ if (location1 === void 0) {
199
+ return -1;
200
+ }
201
+ if (location2 === void 0) {
202
+ return 1;
203
+ }
204
+ if (location1.file !== location2.file) {
205
+ return location1.file < location2.file ? -1 : 1;
206
+ }
207
+ if (location1.start.line !== location2.start.line) {
208
+ return location1.start.line < location2.start.line ? -1 : 1;
209
+ }
210
+ if (location1.start.column !== location2.start.column) {
211
+ return location1.start.column < location2.start.column ? -1 : 1;
212
+ }
213
+ return 0;
214
+ }
215
+
216
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/arb_translation_serializer.mjs
217
+ var ArbTranslationSerializer = class {
218
+ constructor(sourceLocale, basePath, fs) {
219
+ this.sourceLocale = sourceLocale;
220
+ this.basePath = basePath;
221
+ this.fs = fs;
222
+ }
223
+ serialize(messages) {
224
+ const messageGroups = consolidateMessages(messages, (message) => getMessageId(message));
225
+ let output = `{
226
+ "@@locale": ${JSON.stringify(this.sourceLocale)}`;
227
+ for (const duplicateMessages of messageGroups) {
228
+ const message = duplicateMessages[0];
229
+ const id = getMessageId(message);
230
+ output += this.serializeMessage(id, message);
231
+ output += this.serializeMeta(id, message.description, message.meaning, duplicateMessages.filter(hasLocation).map((m) => m.location));
232
+ }
233
+ output += "\n}";
234
+ return output;
235
+ }
236
+ serializeMessage(id, message) {
237
+ return `,
238
+ ${JSON.stringify(id)}: ${JSON.stringify(message.text)}`;
239
+ }
240
+ serializeMeta(id, description, meaning, locations) {
241
+ const meta = [];
242
+ if (description) {
243
+ meta.push(`
244
+ "description": ${JSON.stringify(description)}`);
245
+ }
246
+ if (meaning) {
247
+ meta.push(`
248
+ "x-meaning": ${JSON.stringify(meaning)}`);
249
+ }
250
+ if (locations.length > 0) {
251
+ let locationStr = `
252
+ "x-locations": [`;
253
+ for (let i = 0; i < locations.length; i++) {
254
+ locationStr += (i > 0 ? ",\n" : "\n") + this.serializeLocation(locations[i]);
255
+ }
256
+ locationStr += "\n ]";
257
+ meta.push(locationStr);
258
+ }
259
+ return meta.length > 0 ? `,
260
+ ${JSON.stringify("@" + id)}: {${meta.join(",")}
261
+ }` : "";
262
+ }
263
+ serializeLocation({ file, start, end }) {
264
+ return [
265
+ ` {`,
266
+ ` "file": ${JSON.stringify(this.fs.relative(this.basePath, file))},`,
267
+ ` "start": { "line": "${start.line}", "column": "${start.column}" },`,
268
+ ` "end": { "line": "${end.line}", "column": "${end.column}" }`,
269
+ ` }`
270
+ ].join("\n");
271
+ }
272
+ };
273
+ function getMessageId(message) {
274
+ return message.customId || message.id;
275
+ }
276
+
277
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/json_translation_serializer.mjs
278
+ var SimpleJsonTranslationSerializer = class {
279
+ constructor(sourceLocale) {
280
+ this.sourceLocale = sourceLocale;
281
+ }
282
+ serialize(messages) {
283
+ const fileObj = { locale: this.sourceLocale, translations: {} };
284
+ for (const [message] of consolidateMessages(messages, (message2) => message2.id)) {
285
+ fileObj.translations[message.id] = message.text;
286
+ }
287
+ return JSON.stringify(fileObj, null, 2);
288
+ }
289
+ };
290
+
291
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/legacy_message_id_migration_serializer.mjs
292
+ var LegacyMessageIdMigrationSerializer = class {
293
+ constructor(_diagnostics) {
294
+ this._diagnostics = _diagnostics;
295
+ }
296
+ serialize(messages) {
297
+ let hasMessages = false;
298
+ const mapping = messages.reduce((output, message) => {
299
+ if (shouldMigrate(message)) {
300
+ for (const legacyId of message.legacyIds) {
301
+ if (output.hasOwnProperty(legacyId)) {
302
+ this._diagnostics.warn(`Detected duplicate legacy ID ${legacyId}.`);
303
+ }
304
+ output[legacyId] = message.id;
305
+ hasMessages = true;
306
+ }
307
+ }
308
+ return output;
309
+ }, {});
310
+ if (!hasMessages) {
311
+ this._diagnostics.warn("Could not find any legacy message IDs in source files while generating the legacy message migration file.");
312
+ }
313
+ return JSON.stringify(mapping, null, 2);
314
+ }
315
+ };
316
+ function shouldMigrate(message) {
317
+ return !message.customId && !!message.legacyIds && message.legacyIds.length > 0;
318
+ }
319
+
320
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/format_options.mjs
321
+ function validateOptions(name, validOptions, options) {
322
+ const validOptionsMap = new Map(validOptions);
323
+ for (const option in options) {
324
+ if (!validOptionsMap.has(option)) {
325
+ throw new Error(`Invalid format option for ${name}: "${option}".
326
+ Allowed options are ${JSON.stringify(Array.from(validOptionsMap.keys()))}.`);
327
+ }
328
+ const validOptionValues = validOptionsMap.get(option);
329
+ const optionValue = options[option];
330
+ if (!validOptionValues.includes(optionValue)) {
331
+ throw new Error(`Invalid format option value for ${name}: "${option}".
332
+ Allowed option values are ${JSON.stringify(validOptionValues)} but received "${optionValue}".`);
333
+ }
334
+ }
335
+ }
336
+ function parseFormatOptions(optionString = "{}") {
337
+ return JSON.parse(optionString);
338
+ }
339
+
340
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
341
+ import { getFileSystem } from "@angular/compiler-cli/private/localize";
342
+
343
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/icu_parsing.mjs
344
+ function extractIcuPlaceholders(text) {
345
+ const state = new StateStack();
346
+ const pieces = new IcuPieces();
347
+ const braces = /[{}]/g;
348
+ let lastPos = 0;
349
+ let match;
350
+ while (match = braces.exec(text)) {
351
+ if (match[0] == "{") {
352
+ state.enterBlock();
353
+ } else {
354
+ state.leaveBlock();
355
+ }
356
+ if (state.getCurrent() === "placeholder") {
357
+ const name = tryParsePlaceholder(text, braces.lastIndex);
358
+ if (name) {
359
+ pieces.addText(text.substring(lastPos, braces.lastIndex - 1));
360
+ pieces.addPlaceholder(name);
361
+ braces.lastIndex += name.length + 1;
362
+ state.leaveBlock();
363
+ } else {
364
+ pieces.addText(text.substring(lastPos, braces.lastIndex));
365
+ state.nestedIcu();
366
+ }
367
+ } else {
368
+ pieces.addText(text.substring(lastPos, braces.lastIndex));
369
+ }
370
+ lastPos = braces.lastIndex;
371
+ }
372
+ pieces.addText(text.substring(lastPos));
373
+ return pieces.toArray();
374
+ }
375
+ var IcuPieces = class {
376
+ constructor() {
377
+ this.pieces = [""];
378
+ }
379
+ addText(text) {
380
+ this.pieces[this.pieces.length - 1] += text;
381
+ }
382
+ addPlaceholder(name) {
383
+ this.pieces.push(name);
384
+ this.pieces.push("");
385
+ }
386
+ toArray() {
387
+ return this.pieces;
388
+ }
389
+ };
390
+ var StateStack = class {
391
+ constructor() {
392
+ this.stack = [];
393
+ }
394
+ enterBlock() {
395
+ const current = this.getCurrent();
396
+ switch (current) {
397
+ case "icu":
398
+ this.stack.push("case");
399
+ break;
400
+ case "case":
401
+ this.stack.push("placeholder");
402
+ break;
403
+ case "placeholder":
404
+ this.stack.push("case");
405
+ break;
406
+ default:
407
+ this.stack.push("icu");
408
+ break;
409
+ }
410
+ }
411
+ leaveBlock() {
412
+ return this.stack.pop();
413
+ }
414
+ nestedIcu() {
415
+ const current = this.stack.pop();
416
+ assert(current === "placeholder", "A nested ICU must replace a placeholder but got " + current);
417
+ this.stack.push("icu");
418
+ }
419
+ getCurrent() {
420
+ return this.stack[this.stack.length - 1];
421
+ }
422
+ };
423
+ function tryParsePlaceholder(text, start) {
424
+ for (let i = start; i < text.length; i++) {
425
+ if (text[i] === ",") {
426
+ break;
427
+ }
428
+ if (text[i] === "}") {
429
+ return text.substring(start, i);
430
+ }
431
+ }
432
+ return null;
433
+ }
434
+ function assert(test, message) {
435
+ if (!test) {
436
+ throw new Error("Assertion failure: " + message);
437
+ }
438
+ }
439
+
440
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xml_file.mjs
441
+ var XmlFile = class {
442
+ constructor() {
443
+ this.output = '<?xml version="1.0" encoding="UTF-8" ?>\n';
444
+ this.indent = "";
445
+ this.elements = [];
446
+ this.preservingWhitespace = false;
447
+ }
448
+ toString() {
449
+ return this.output;
450
+ }
451
+ startTag(name, attributes = {}, { selfClosing = false, preserveWhitespace } = {}) {
452
+ if (!this.preservingWhitespace) {
453
+ this.output += this.indent;
454
+ }
455
+ this.output += `<${name}`;
456
+ for (const [attrName, attrValue] of Object.entries(attributes)) {
457
+ if (attrValue) {
458
+ this.output += ` ${attrName}="${escapeXml(attrValue)}"`;
459
+ }
460
+ }
461
+ if (selfClosing) {
462
+ this.output += "/>";
463
+ } else {
464
+ this.output += ">";
465
+ this.elements.push(name);
466
+ this.incIndent();
467
+ }
468
+ if (preserveWhitespace !== void 0) {
469
+ this.preservingWhitespace = preserveWhitespace;
470
+ }
471
+ if (!this.preservingWhitespace) {
472
+ this.output += `
473
+ `;
474
+ }
475
+ return this;
476
+ }
477
+ endTag(name, { preserveWhitespace } = {}) {
478
+ const expectedTag = this.elements.pop();
479
+ if (expectedTag !== name) {
480
+ throw new Error(`Unexpected closing tag: "${name}", expected: "${expectedTag}"`);
481
+ }
482
+ this.decIndent();
483
+ if (!this.preservingWhitespace) {
484
+ this.output += this.indent;
485
+ }
486
+ this.output += `</${name}>`;
487
+ if (preserveWhitespace !== void 0) {
488
+ this.preservingWhitespace = preserveWhitespace;
489
+ }
490
+ if (!this.preservingWhitespace) {
491
+ this.output += `
492
+ `;
493
+ }
494
+ return this;
495
+ }
496
+ text(str) {
497
+ this.output += escapeXml(str);
498
+ return this;
499
+ }
500
+ rawText(str) {
501
+ this.output += str;
502
+ return this;
503
+ }
504
+ incIndent() {
505
+ this.indent = this.indent + " ";
506
+ }
507
+ decIndent() {
508
+ this.indent = this.indent.slice(0, -2);
509
+ }
510
+ };
511
+ var _ESCAPED_CHARS = [
512
+ [/&/g, "&amp;"],
513
+ [/"/g, "&quot;"],
514
+ [/'/g, "&apos;"],
515
+ [/</g, "&lt;"],
516
+ [/>/g, "&gt;"]
517
+ ];
518
+ function escapeXml(text) {
519
+ return _ESCAPED_CHARS.reduce((text2, entry) => text2.replace(entry[0], entry[1]), text);
520
+ }
521
+
522
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
523
+ var LEGACY_XLIFF_MESSAGE_LENGTH = 40;
524
+ var Xliff1TranslationSerializer = class {
525
+ constructor(sourceLocale, basePath, useLegacyIds, formatOptions = {}, fs = getFileSystem()) {
526
+ this.sourceLocale = sourceLocale;
527
+ this.basePath = basePath;
528
+ this.useLegacyIds = useLegacyIds;
529
+ this.formatOptions = formatOptions;
530
+ this.fs = fs;
531
+ validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions);
532
+ }
533
+ serialize(messages) {
534
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
535
+ const xml = new XmlFile();
536
+ xml.startTag("xliff", { "version": "1.2", "xmlns": "urn:oasis:names:tc:xliff:document:1.2" });
537
+ xml.startTag("file", __spreadValues({
538
+ "source-language": this.sourceLocale,
539
+ "datatype": "plaintext",
540
+ "original": "ng2.template"
541
+ }, this.formatOptions));
542
+ xml.startTag("body");
543
+ for (const duplicateMessages of messageGroups) {
544
+ const message = duplicateMessages[0];
545
+ const id = this.getMessageId(message);
546
+ xml.startTag("trans-unit", { id, datatype: "html" });
547
+ xml.startTag("source", {}, { preserveWhitespace: true });
548
+ this.serializeMessage(xml, message);
549
+ xml.endTag("source", { preserveWhitespace: false });
550
+ for (const { location } of duplicateMessages.filter(hasLocation)) {
551
+ this.serializeLocation(xml, location);
552
+ }
553
+ if (message.description) {
554
+ this.serializeNote(xml, "description", message.description);
555
+ }
556
+ if (message.meaning) {
557
+ this.serializeNote(xml, "meaning", message.meaning);
558
+ }
559
+ xml.endTag("trans-unit");
560
+ }
561
+ xml.endTag("body");
562
+ xml.endTag("file");
563
+ xml.endTag("xliff");
564
+ return xml.toString();
565
+ }
566
+ serializeMessage(xml, message) {
567
+ var _a;
568
+ const length = message.messageParts.length - 1;
569
+ for (let i = 0; i < length; i++) {
570
+ this.serializeTextPart(xml, message.messageParts[i]);
571
+ const name = message.placeholderNames[i];
572
+ const location = (_a = message.substitutionLocations) == null ? void 0 : _a[name];
573
+ const associatedMessageId = message.associatedMessageIds && message.associatedMessageIds[name];
574
+ this.serializePlaceholder(xml, name, location == null ? void 0 : location.text, associatedMessageId);
575
+ }
576
+ this.serializeTextPart(xml, message.messageParts[length]);
577
+ }
578
+ serializeTextPart(xml, text) {
579
+ const pieces = extractIcuPlaceholders(text);
580
+ const length = pieces.length - 1;
581
+ for (let i = 0; i < length; i += 2) {
582
+ xml.text(pieces[i]);
583
+ this.serializePlaceholder(xml, pieces[i + 1], void 0, void 0);
584
+ }
585
+ xml.text(pieces[length]);
586
+ }
587
+ serializePlaceholder(xml, id, text, associatedId) {
588
+ const attrs = { id };
589
+ const ctype = getCtypeForPlaceholder(id);
590
+ if (ctype !== null) {
591
+ attrs.ctype = ctype;
592
+ }
593
+ if (text !== void 0) {
594
+ attrs["equiv-text"] = text;
595
+ }
596
+ if (associatedId !== void 0) {
597
+ attrs["xid"] = associatedId;
598
+ }
599
+ xml.startTag("x", attrs, { selfClosing: true });
600
+ }
601
+ serializeNote(xml, name, value) {
602
+ xml.startTag("note", { priority: "1", from: name }, { preserveWhitespace: true });
603
+ xml.text(value);
604
+ xml.endTag("note", { preserveWhitespace: false });
605
+ }
606
+ serializeLocation(xml, location) {
607
+ xml.startTag("context-group", { purpose: "location" });
608
+ this.renderContext(xml, "sourcefile", this.fs.relative(this.basePath, location.file));
609
+ const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
610
+ this.renderContext(xml, "linenumber", `${location.start.line + 1}${endLineString}`);
611
+ xml.endTag("context-group");
612
+ }
613
+ renderContext(xml, type, value) {
614
+ xml.startTag("context", { "context-type": type }, { preserveWhitespace: true });
615
+ xml.text(value);
616
+ xml.endTag("context", { preserveWhitespace: false });
617
+ }
618
+ getMessageId(message) {
619
+ return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length === LEGACY_XLIFF_MESSAGE_LENGTH) || message.id;
620
+ }
621
+ };
622
+ function getCtypeForPlaceholder(placeholder) {
623
+ const tag = placeholder.replace(/^(START_|CLOSE_)/, "");
624
+ switch (tag) {
625
+ case "LINE_BREAK":
626
+ return "lb";
627
+ case "TAG_IMG":
628
+ return "image";
629
+ default:
630
+ const element = tag.startsWith("TAG_") ? tag.replace(/^TAG_(.+)/, (_, tagName) => tagName.toLowerCase()) : TAG_MAP[tag];
631
+ if (element === void 0) {
632
+ return null;
633
+ }
634
+ return `x-${element}`;
635
+ }
636
+ }
637
+ var TAG_MAP = {
638
+ "LINK": "a",
639
+ "BOLD_TEXT": "b",
640
+ "EMPHASISED_TEXT": "em",
641
+ "HEADING_LEVEL1": "h1",
642
+ "HEADING_LEVEL2": "h2",
643
+ "HEADING_LEVEL3": "h3",
644
+ "HEADING_LEVEL4": "h4",
645
+ "HEADING_LEVEL5": "h5",
646
+ "HEADING_LEVEL6": "h6",
647
+ "HORIZONTAL_RULE": "hr",
648
+ "ITALIC_TEXT": "i",
649
+ "LIST_ITEM": "li",
650
+ "MEDIA_LINK": "link",
651
+ "ORDERED_LIST": "ol",
652
+ "PARAGRAPH": "p",
653
+ "QUOTATION": "q",
654
+ "STRIKETHROUGH_TEXT": "s",
655
+ "SMALL_TEXT": "small",
656
+ "SUBSTRIPT": "sub",
657
+ "SUPERSCRIPT": "sup",
658
+ "TABLE_BODY": "tbody",
659
+ "TABLE_CELL": "td",
660
+ "TABLE_FOOTER": "tfoot",
661
+ "TABLE_HEADER_CELL": "th",
662
+ "TABLE_HEADER": "thead",
663
+ "TABLE_ROW": "tr",
664
+ "MONOSPACED_TEXT": "tt",
665
+ "UNDERLINED_TEXT": "u",
666
+ "UNORDERED_LIST": "ul"
667
+ };
668
+
669
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff2_translation_serializer.mjs
670
+ import { getFileSystem as getFileSystem2 } from "@angular/compiler-cli/private/localize";
671
+ var MAX_LEGACY_XLIFF_2_MESSAGE_LENGTH = 20;
672
+ var Xliff2TranslationSerializer = class {
673
+ constructor(sourceLocale, basePath, useLegacyIds, formatOptions = {}, fs = getFileSystem2()) {
674
+ this.sourceLocale = sourceLocale;
675
+ this.basePath = basePath;
676
+ this.useLegacyIds = useLegacyIds;
677
+ this.formatOptions = formatOptions;
678
+ this.fs = fs;
679
+ this.currentPlaceholderId = 0;
680
+ validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions);
681
+ }
682
+ serialize(messages) {
683
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
684
+ const xml = new XmlFile();
685
+ xml.startTag("xliff", {
686
+ "version": "2.0",
687
+ "xmlns": "urn:oasis:names:tc:xliff:document:2.0",
688
+ "srcLang": this.sourceLocale
689
+ });
690
+ xml.startTag("file", __spreadValues({ "id": "ngi18n", "original": "ng.template" }, this.formatOptions));
691
+ for (const duplicateMessages of messageGroups) {
692
+ const message = duplicateMessages[0];
693
+ const id = this.getMessageId(message);
694
+ xml.startTag("unit", { id });
695
+ const messagesWithLocations = duplicateMessages.filter(hasLocation);
696
+ if (message.meaning || message.description || messagesWithLocations.length) {
697
+ xml.startTag("notes");
698
+ for (const { location: { file, start, end } } of messagesWithLocations) {
699
+ const endLineString = end !== void 0 && end.line !== start.line ? `,${end.line + 1}` : "";
700
+ this.serializeNote(xml, "location", `${this.fs.relative(this.basePath, file)}:${start.line + 1}${endLineString}`);
701
+ }
702
+ if (message.description) {
703
+ this.serializeNote(xml, "description", message.description);
704
+ }
705
+ if (message.meaning) {
706
+ this.serializeNote(xml, "meaning", message.meaning);
707
+ }
708
+ xml.endTag("notes");
709
+ }
710
+ xml.startTag("segment");
711
+ xml.startTag("source", {}, { preserveWhitespace: true });
712
+ this.serializeMessage(xml, message);
713
+ xml.endTag("source", { preserveWhitespace: false });
714
+ xml.endTag("segment");
715
+ xml.endTag("unit");
716
+ }
717
+ xml.endTag("file");
718
+ xml.endTag("xliff");
719
+ return xml.toString();
720
+ }
721
+ serializeMessage(xml, message) {
722
+ this.currentPlaceholderId = 0;
723
+ const length = message.messageParts.length - 1;
724
+ for (let i = 0; i < length; i++) {
725
+ this.serializeTextPart(xml, message.messageParts[i]);
726
+ const name = message.placeholderNames[i];
727
+ const associatedMessageId = message.associatedMessageIds && message.associatedMessageIds[name];
728
+ this.serializePlaceholder(xml, name, message.substitutionLocations, associatedMessageId);
729
+ }
730
+ this.serializeTextPart(xml, message.messageParts[length]);
731
+ }
732
+ serializeTextPart(xml, text) {
733
+ const pieces = extractIcuPlaceholders(text);
734
+ const length = pieces.length - 1;
735
+ for (let i = 0; i < length; i += 2) {
736
+ xml.text(pieces[i]);
737
+ this.serializePlaceholder(xml, pieces[i + 1], void 0, void 0);
738
+ }
739
+ xml.text(pieces[length]);
740
+ }
741
+ serializePlaceholder(xml, placeholderName, substitutionLocations, associatedMessageId) {
742
+ var _a, _b;
743
+ const text = (_a = substitutionLocations == null ? void 0 : substitutionLocations[placeholderName]) == null ? void 0 : _a.text;
744
+ if (placeholderName.startsWith("START_")) {
745
+ const closingPlaceholderName = placeholderName.replace(/^START/, "CLOSE").replace(/_\d+$/, "");
746
+ const closingText = (_b = substitutionLocations == null ? void 0 : substitutionLocations[closingPlaceholderName]) == null ? void 0 : _b.text;
747
+ const attrs = {
748
+ id: `${this.currentPlaceholderId++}`,
749
+ equivStart: placeholderName,
750
+ equivEnd: closingPlaceholderName
751
+ };
752
+ const type = getTypeForPlaceholder(placeholderName);
753
+ if (type !== null) {
754
+ attrs.type = type;
755
+ }
756
+ if (text !== void 0) {
757
+ attrs.dispStart = text;
758
+ }
759
+ if (closingText !== void 0) {
760
+ attrs.dispEnd = closingText;
761
+ }
762
+ xml.startTag("pc", attrs);
763
+ } else if (placeholderName.startsWith("CLOSE_")) {
764
+ xml.endTag("pc");
765
+ } else {
766
+ const attrs = {
767
+ id: `${this.currentPlaceholderId++}`,
768
+ equiv: placeholderName
769
+ };
770
+ const type = getTypeForPlaceholder(placeholderName);
771
+ if (type !== null) {
772
+ attrs.type = type;
773
+ }
774
+ if (text !== void 0) {
775
+ attrs.disp = text;
776
+ }
777
+ if (associatedMessageId !== void 0) {
778
+ attrs["subFlows"] = associatedMessageId;
779
+ }
780
+ xml.startTag("ph", attrs, { selfClosing: true });
781
+ }
782
+ }
783
+ serializeNote(xml, name, value) {
784
+ xml.startTag("note", { category: name }, { preserveWhitespace: true });
785
+ xml.text(value);
786
+ xml.endTag("note", { preserveWhitespace: false });
787
+ }
788
+ getMessageId(message) {
789
+ return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length <= MAX_LEGACY_XLIFF_2_MESSAGE_LENGTH && !/[^0-9]/.test(id)) || message.id;
790
+ }
791
+ };
792
+ function getTypeForPlaceholder(placeholder) {
793
+ const tag = placeholder.replace(/^(START_|CLOSE_)/, "").replace(/_\d+$/, "");
794
+ switch (tag) {
795
+ case "BOLD_TEXT":
796
+ case "EMPHASISED_TEXT":
797
+ case "ITALIC_TEXT":
798
+ case "LINE_BREAK":
799
+ case "STRIKETHROUGH_TEXT":
800
+ case "UNDERLINED_TEXT":
801
+ return "fmt";
802
+ case "TAG_IMG":
803
+ return "image";
804
+ case "LINK":
805
+ return "link";
806
+ default:
807
+ return /^(START_|CLOSE_)/.test(placeholder) ? "other" : null;
808
+ }
809
+ }
810
+
811
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xmb_translation_serializer.mjs
812
+ import { getFileSystem as getFileSystem3 } from "@angular/compiler-cli/private/localize";
813
+ var XmbTranslationSerializer = class {
814
+ constructor(basePath, useLegacyIds, fs = getFileSystem3()) {
815
+ this.basePath = basePath;
816
+ this.useLegacyIds = useLegacyIds;
817
+ this.fs = fs;
818
+ }
819
+ serialize(messages) {
820
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
821
+ const xml = new XmlFile();
822
+ xml.rawText(`<!DOCTYPE messagebundle [
823
+ <!ELEMENT messagebundle (msg)*>
824
+ <!ATTLIST messagebundle class CDATA #IMPLIED>
825
+
826
+ <!ELEMENT msg (#PCDATA|ph|source)*>
827
+ <!ATTLIST msg id CDATA #IMPLIED>
828
+ <!ATTLIST msg seq CDATA #IMPLIED>
829
+ <!ATTLIST msg name CDATA #IMPLIED>
830
+ <!ATTLIST msg desc CDATA #IMPLIED>
831
+ <!ATTLIST msg meaning CDATA #IMPLIED>
832
+ <!ATTLIST msg obsolete (obsolete) #IMPLIED>
833
+ <!ATTLIST msg xml:space (default|preserve) "default">
834
+ <!ATTLIST msg is_hidden CDATA #IMPLIED>
835
+
836
+ <!ELEMENT source (#PCDATA)>
837
+
838
+ <!ELEMENT ph (#PCDATA|ex)*>
839
+ <!ATTLIST ph name CDATA #REQUIRED>
840
+
841
+ <!ELEMENT ex (#PCDATA)>
842
+ ]>
843
+ `);
844
+ xml.startTag("messagebundle");
845
+ for (const duplicateMessages of messageGroups) {
846
+ const message = duplicateMessages[0];
847
+ const id = this.getMessageId(message);
848
+ xml.startTag("msg", { id, desc: message.description, meaning: message.meaning }, { preserveWhitespace: true });
849
+ if (message.location) {
850
+ this.serializeLocation(xml, message.location);
851
+ }
852
+ this.serializeMessage(xml, message);
853
+ xml.endTag("msg", { preserveWhitespace: false });
854
+ }
855
+ xml.endTag("messagebundle");
856
+ return xml.toString();
857
+ }
858
+ serializeLocation(xml, location) {
859
+ xml.startTag("source");
860
+ const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
861
+ xml.text(`${this.fs.relative(this.basePath, location.file)}:${location.start.line}${endLineString}`);
862
+ xml.endTag("source");
863
+ }
864
+ serializeMessage(xml, message) {
865
+ const length = message.messageParts.length - 1;
866
+ for (let i = 0; i < length; i++) {
867
+ this.serializeTextPart(xml, message.messageParts[i]);
868
+ xml.startTag("ph", { name: message.placeholderNames[i] }, { selfClosing: true });
869
+ }
870
+ this.serializeTextPart(xml, message.messageParts[length]);
871
+ }
872
+ serializeTextPart(xml, text) {
873
+ const pieces = extractIcuPlaceholders(text);
874
+ const length = pieces.length - 1;
875
+ for (let i = 0; i < length; i += 2) {
876
+ xml.text(pieces[i]);
877
+ xml.startTag("ph", { name: pieces[i + 1] }, { selfClosing: true });
878
+ }
879
+ xml.text(pieces[length]);
880
+ }
881
+ getMessageId(message) {
882
+ return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length <= 20 && !/[^0-9]/.test(id)) || message.id;
883
+ }
884
+ };
885
+
886
+ export {
887
+ checkDuplicateMessages,
888
+ MessageExtractor,
889
+ ArbTranslationSerializer,
890
+ SimpleJsonTranslationSerializer,
891
+ LegacyMessageIdMigrationSerializer,
892
+ parseFormatOptions,
893
+ Xliff1TranslationSerializer,
894
+ Xliff2TranslationSerializer,
895
+ XmbTranslationSerializer
896
+ };
897
+ /**
898
+ * @license
899
+ * Copyright Google LLC All Rights Reserved.
900
+ *
901
+ * Use of this source code is governed by an MIT-style license that can be
902
+ * found in the LICENSE file at https://angular.io/license
903
+ */
904
+ //# sourceMappingURL=chunk-5AFPBPRI.js.map