@angular/localize 13.0.0-next.9 → 13.0.0-rc.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.
Files changed (138) hide show
  1. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  2. package/esm2020/init/index.mjs +12 -0
  3. package/{esm2015/localize.js → esm2020/localize.mjs} +0 -0
  4. package/{esm2015/private.js → esm2020/private.mjs} +0 -0
  5. package/{esm2015/src/localize/index.js → esm2020/src/localize/index.mjs} +0 -0
  6. package/{esm2015/src/localize/src/global.js → esm2020/src/localize/src/global.mjs} +0 -0
  7. package/{esm2015/src/localize/src/localize.js → esm2020/src/localize/src/localize.mjs} +2 -2
  8. package/{esm2015/src/translate.js → esm2020/src/translate.mjs} +0 -0
  9. package/{esm2015/src/utils/index.js → esm2020/src/utils/index.mjs} +0 -0
  10. package/{esm2015/src/utils/src/constants.js → esm2020/src/utils/src/constants.mjs} +0 -0
  11. package/esm2020/src/utils/src/messages.mjs +159 -0
  12. package/{esm2015/src/utils/src/translations.js → esm2020/src/utils/src/translations.mjs} +0 -0
  13. package/fesm2015/{init.js → init.mjs} +3 -3
  14. package/fesm2015/init.mjs.map +1 -0
  15. package/fesm2015/{localize.js → localize.mjs} +7 -7
  16. package/fesm2015/localize.mjs.map +1 -0
  17. package/fesm2020/init.mjs +204 -0
  18. package/fesm2020/init.mjs.map +1 -0
  19. package/fesm2020/localize.mjs +449 -0
  20. package/fesm2020/localize.mjs.map +1 -0
  21. package/init/index.d.ts +1 -1
  22. package/init/package.json +5 -5
  23. package/package.json +43 -18
  24. package/schematics/ng-add/index.js +1 -1
  25. package/src/localize/src/localize.d.ts +1 -1
  26. package/src/utils/src/messages.d.ts +1 -1
  27. package/tools/README.md +4 -0
  28. package/tools/bundles/index.js +1929 -0
  29. package/tools/bundles/index.js.map +6 -0
  30. package/tools/bundles/src/extract/cli.js +1278 -0
  31. package/tools/bundles/src/extract/cli.js.map +6 -0
  32. package/tools/bundles/src/migrate/cli.js +77 -0
  33. package/tools/bundles/src/migrate/cli.js.map +6 -0
  34. package/tools/bundles/src/translate/cli.js +1340 -0
  35. package/tools/bundles/src/translate/cli.js.map +6 -0
  36. package/tools/bundles_metadata.json +1 -0
  37. package/tools/index.d.ts +26 -0
  38. package/tools/src/babel_core.d.ts +38 -0
  39. package/{src/tools → tools}/src/diagnostics.d.ts +1 -1
  40. package/tools/src/extract/cli.d.ts +10 -0
  41. package/{src/tools → tools}/src/extract/duplicates.d.ts +2 -2
  42. package/{src/tools → tools}/src/extract/extraction.d.ts +2 -3
  43. package/{src/tools/src/extract/main.d.ts → tools/src/extract/index.d.ts} +2 -4
  44. package/{src/tools → tools}/src/extract/source_files/es2015_extract_plugin.d.ts +3 -3
  45. package/{src/tools → tools}/src/extract/source_files/es5_extract_plugin.d.ts +3 -3
  46. package/{src/tools → tools}/src/extract/translation_files/arb_translation_serializer.d.ts +2 -2
  47. package/{src/tools → tools}/src/extract/translation_files/format_options.d.ts +1 -1
  48. package/{src/tools → tools}/src/extract/translation_files/icu_parsing.d.ts +1 -1
  49. package/{src/tools → tools}/src/extract/translation_files/json_translation_serializer.d.ts +1 -1
  50. package/{src/tools → tools}/src/extract/translation_files/legacy_message_id_migration_serializer.d.ts +1 -1
  51. package/{src/tools → tools}/src/extract/translation_files/translation_serializer.d.ts +1 -1
  52. package/{src/tools → tools}/src/extract/translation_files/utils.d.ts +1 -1
  53. package/{src/tools → tools}/src/extract/translation_files/xliff1_translation_serializer.d.ts +2 -2
  54. package/{src/tools → tools}/src/extract/translation_files/xliff2_translation_serializer.d.ts +2 -2
  55. package/{src/tools → tools}/src/extract/translation_files/xmb_translation_serializer.d.ts +2 -2
  56. package/{src/tools → tools}/src/extract/translation_files/xml_file.d.ts +1 -1
  57. package/tools/src/migrate/cli.d.ts +10 -0
  58. package/{src/tools/src/migrate/main.d.ts → tools/src/migrate/index.d.ts} +9 -3
  59. package/{src/tools → tools}/src/migrate/migrate.d.ts +1 -1
  60. package/{src/tools → tools}/src/source_file_utils.d.ts +3 -3
  61. package/{src/tools → tools}/src/translate/asset_files/asset_translation_handler.d.ts +2 -2
  62. package/tools/src/translate/cli.d.ts +3 -0
  63. package/{src/tools/src/translate/main.d.ts → tools/src/translate/index.d.ts} +1 -2
  64. package/{src/tools → tools}/src/translate/output_path.d.ts +2 -2
  65. package/{src/tools → tools}/src/translate/source_files/es2015_translate_plugin.d.ts +3 -3
  66. package/{src/tools → tools}/src/translate/source_files/es5_translate_plugin.d.ts +3 -3
  67. package/{src/tools → tools}/src/translate/source_files/locale_plugin.d.ts +2 -2
  68. package/{src/tools → tools}/src/translate/source_files/source_file_translation_handler.d.ts +2 -2
  69. package/{src/tools → tools}/src/translate/translation_files/base_visitor.d.ts +1 -1
  70. package/{src/tools → tools}/src/translate/translation_files/message_serialization/message_renderer.d.ts +1 -1
  71. package/{src/tools → tools}/src/translate/translation_files/message_serialization/message_serializer.d.ts +1 -1
  72. package/{src/tools → tools}/src/translate/translation_files/message_serialization/target_message_renderer.d.ts +1 -1
  73. package/{src/tools → tools}/src/translate/translation_files/translation_loader.d.ts +2 -2
  74. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/arb_translation_parser.d.ts +1 -1
  75. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/serialize_translation_message.d.ts +1 -1
  76. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/simple_json_translation_parser.d.ts +1 -1
  77. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_parse_error.d.ts +1 -1
  78. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_parser.d.ts +2 -2
  79. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_utils.d.ts +1 -1
  80. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xliff1_translation_parser.d.ts +1 -1
  81. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xliff2_translation_parser.d.ts +1 -1
  82. package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xtb_translation_parser.d.ts +1 -1
  83. package/{src/tools → tools}/src/translate/translator.d.ts +2 -2
  84. package/bundles/localize-init.umd.js +0 -218
  85. package/bundles/localize-init.umd.js.map +0 -1
  86. package/bundles/localize.umd.js +0 -782
  87. package/bundles/localize.umd.js.map +0 -1
  88. package/esm2015/init/index.js +0 -12
  89. package/esm2015/init/init.externs.js +0 -0
  90. package/esm2015/localize.externs.js +0 -0
  91. package/esm2015/src/localize/localize.externs.js +0 -0
  92. package/esm2015/src/utils/src/messages.js +0 -159
  93. package/esm2015/src/utils/utils.externs.js +0 -0
  94. package/fesm2015/init.js.map +0 -1
  95. package/fesm2015/localize.js.map +0 -1
  96. package/init.d.ts +0 -7
  97. package/src/tools/src/diagnostics.js +0 -68
  98. package/src/tools/src/extract/duplicates.js +0 -84
  99. package/src/tools/src/extract/extraction.js +0 -134
  100. package/src/tools/src/extract/main.js +0 -184
  101. package/src/tools/src/extract/source_files/es2015_extract_plugin.js +0 -36
  102. package/src/tools/src/extract/source_files/es5_extract_plugin.js +0 -49
  103. package/src/tools/src/extract/translation_files/arb_translation_serializer.js +0 -107
  104. package/src/tools/src/extract/translation_files/format_options.js +0 -52
  105. package/src/tools/src/extract/translation_files/icu_parsing.js +0 -224
  106. package/src/tools/src/extract/translation_files/json_translation_serializer.js +0 -47
  107. package/src/tools/src/extract/translation_files/legacy_message_id_migration_serializer.js +0 -63
  108. package/src/tools/src/extract/translation_files/translation_serializer.js +0 -13
  109. package/src/tools/src/extract/translation_files/utils.js +0 -102
  110. package/src/tools/src/extract/translation_files/xliff1_translation_serializer.js +0 -242
  111. package/src/tools/src/extract/translation_files/xliff2_translation_serializer.js +0 -231
  112. package/src/tools/src/extract/translation_files/xmb_translation_serializer.js +0 -139
  113. package/src/tools/src/extract/translation_files/xml_file.js +0 -117
  114. package/src/tools/src/migrate/main.js +0 -79
  115. package/src/tools/src/migrate/migrate.js +0 -48
  116. package/src/tools/src/source_file_utils.js +0 -443
  117. package/src/tools/src/translate/asset_files/asset_translation_handler.js +0 -65
  118. package/src/tools/src/translate/main.js +0 -157
  119. package/src/tools/src/translate/output_path.js +0 -28
  120. package/src/tools/src/translate/source_files/es2015_translate_plugin.js +0 -60
  121. package/src/tools/src/translate/source_files/es5_translate_plugin.js +0 -58
  122. package/src/tools/src/translate/source_files/locale_plugin.js +0 -95
  123. package/src/tools/src/translate/source_files/source_file_translation_handler.js +0 -127
  124. package/src/tools/src/translate/translation_files/base_visitor.js +0 -31
  125. package/src/tools/src/translate/translation_files/message_serialization/message_renderer.js +0 -20
  126. package/src/tools/src/translate/translation_files/message_serialization/message_serializer.js +0 -100
  127. package/src/tools/src/translate/translation_files/message_serialization/target_message_renderer.js +0 -84
  128. package/src/tools/src/translate/translation_files/translation_loader.js +0 -148
  129. package/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.js +0 -111
  130. package/src/tools/src/translate/translation_files/translation_parsers/serialize_translation_message.js +0 -32
  131. package/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.js +0 -96
  132. package/src/tools/src/translate/translation_files/translation_parsers/translation_parse_error.js +0 -47
  133. package/src/tools/src/translate/translation_files/translation_parsers/translation_parser.js +0 -13
  134. package/src/tools/src/translate/translation_files/translation_parsers/translation_utils.js +0 -175
  135. package/src/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.js +0 -175
  136. package/src/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser.js +0 -166
  137. package/src/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser.js +0 -133
  138. package/src/tools/src/translate/translator.js +0 -53
@@ -0,0 +1,1278 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {createRequire as __cjsCompatRequire} from 'module';
4
+ const require = __cjsCompatRequire(import.meta.url);
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+
23
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/cli.mjs
24
+ import { ConsoleLogger, LogLevel, NodeJSFileSystem, setFileSystem } from "@angular/compiler-cli/private/localize";
25
+ import glob from "glob";
26
+ import yargs from "yargs";
27
+
28
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/format_options.mjs
29
+ function validateOptions(name, validOptions, options2) {
30
+ const validOptionsMap = new Map(validOptions);
31
+ for (const option in options2) {
32
+ if (!validOptionsMap.has(option)) {
33
+ throw new Error(`Invalid format option for ${name}: "${option}".
34
+ Allowed options are ${JSON.stringify(Array.from(validOptionsMap.keys()))}.`);
35
+ }
36
+ const validOptionValues = validOptionsMap.get(option);
37
+ const optionValue = options2[option];
38
+ if (!validOptionValues.includes(optionValue)) {
39
+ throw new Error(`Invalid format option value for ${name}: "${option}".
40
+ Allowed option values are ${JSON.stringify(validOptionValues)} but received "${optionValue}".`);
41
+ }
42
+ }
43
+ }
44
+ function parseFormatOptions(optionString = "{}") {
45
+ return JSON.parse(optionString);
46
+ }
47
+
48
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/diagnostics.mjs
49
+ var Diagnostics = class {
50
+ constructor() {
51
+ this.messages = [];
52
+ }
53
+ get hasErrors() {
54
+ return this.messages.some((m) => m.type === "error");
55
+ }
56
+ add(type, message) {
57
+ if (type !== "ignore") {
58
+ this.messages.push({ type, message });
59
+ }
60
+ }
61
+ warn(message) {
62
+ this.messages.push({ type: "warning", message });
63
+ }
64
+ error(message) {
65
+ this.messages.push({ type: "error", message });
66
+ }
67
+ merge(other) {
68
+ this.messages.push(...other.messages);
69
+ }
70
+ formatDiagnostics(message) {
71
+ const errors = this.messages.filter((d) => d.type === "error").map((d) => " - " + d.message);
72
+ const warnings = this.messages.filter((d) => d.type === "warning").map((d) => " - " + d.message);
73
+ if (errors.length) {
74
+ message += "\nERRORS:\n" + errors.join("\n");
75
+ }
76
+ if (warnings.length) {
77
+ message += "\nWARNINGS:\n" + warnings.join("\n");
78
+ }
79
+ return message;
80
+ }
81
+ };
82
+
83
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/source_file_utils.mjs
84
+ import { getFileSystem } from "@angular/compiler-cli/private/localize";
85
+ import { \u0275isMissingTranslationError, \u0275makeTemplateObject, \u0275translate } from "@angular/localize";
86
+
87
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/babel_core.mjs
88
+ import * as _babelNamespace from "@babel/core";
89
+ import _babelDefault from "@babel/core";
90
+ var _a;
91
+ var babel = (_a = _babelDefault) != null ? _a : _babelNamespace;
92
+ var _typesNamespace = _babelNamespace.types;
93
+ if (_babelDefault !== void 0) {
94
+ _typesNamespace = _babelDefault.types;
95
+ }
96
+ var types = _typesNamespace;
97
+ var NodePath = babel.NodePath;
98
+ var transformSync = babel.transformSync;
99
+ var parseSync = babel.parseSync;
100
+ var transformFromAstSync = babel.transformFromAstSync;
101
+
102
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/source_file_utils.mjs
103
+ function isNamedIdentifier(expression, name) {
104
+ return expression.isIdentifier() && expression.node.name === name;
105
+ }
106
+ function isGlobalIdentifier(identifier) {
107
+ return !identifier.scope || !identifier.scope.hasBinding(identifier.node.name);
108
+ }
109
+ function unwrapMessagePartsFromLocalizeCall(call, fs = getFileSystem()) {
110
+ let cooked = call.get("arguments")[0];
111
+ if (cooked === void 0) {
112
+ throw new BabelParseError(call.node, "`$localize` called without any arguments.");
113
+ }
114
+ if (!cooked.isExpression()) {
115
+ throw new BabelParseError(cooked.node, "Unexpected argument to `$localize` (expected an array).");
116
+ }
117
+ let raw = cooked;
118
+ if (cooked.isLogicalExpression() && cooked.node.operator === "||" && cooked.get("left").isIdentifier()) {
119
+ const right = cooked.get("right");
120
+ if (right.isAssignmentExpression()) {
121
+ cooked = right.get("right");
122
+ if (!cooked.isExpression()) {
123
+ throw new BabelParseError(cooked.node, 'Unexpected "makeTemplateObject()" function (expected an expression).');
124
+ }
125
+ } else if (right.isSequenceExpression()) {
126
+ const expressions = right.get("expressions");
127
+ if (expressions.length > 2) {
128
+ const [first, second] = expressions;
129
+ if (first.isAssignmentExpression()) {
130
+ cooked = first.get("right");
131
+ if (!cooked.isExpression()) {
132
+ throw new BabelParseError(first.node, "Unexpected cooked value, expected an expression.");
133
+ }
134
+ if (second.isAssignmentExpression()) {
135
+ raw = second.get("right");
136
+ if (!raw.isExpression()) {
137
+ throw new BabelParseError(second.node, "Unexpected raw value, expected an expression.");
138
+ }
139
+ } else {
140
+ raw = cooked;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ if (cooked.isCallExpression()) {
147
+ let call2 = cooked;
148
+ if (call2.get("arguments").length === 0) {
149
+ call2 = unwrapLazyLoadHelperCall(call2);
150
+ }
151
+ cooked = call2.get("arguments")[0];
152
+ if (!cooked.isExpression()) {
153
+ throw new BabelParseError(cooked.node, 'Unexpected `cooked` argument to the "makeTemplateObject()" function (expected an expression).');
154
+ }
155
+ const arg2 = call2.get("arguments")[1];
156
+ if (arg2 && !arg2.isExpression()) {
157
+ throw new BabelParseError(arg2.node, 'Unexpected `raw` argument to the "makeTemplateObject()" function (expected an expression).');
158
+ }
159
+ raw = arg2 !== void 0 ? arg2 : cooked;
160
+ }
161
+ const [cookedStrings] = unwrapStringLiteralArray(cooked, fs);
162
+ const [rawStrings, rawLocations] = unwrapStringLiteralArray(raw, fs);
163
+ return [\u0275makeTemplateObject(cookedStrings, rawStrings), rawLocations];
164
+ }
165
+ function unwrapSubstitutionsFromLocalizeCall(call, fs = getFileSystem()) {
166
+ const expressions = call.get("arguments").splice(1);
167
+ if (!isArrayOfExpressions(expressions)) {
168
+ const badExpression = expressions.find((expression) => !expression.isExpression());
169
+ throw new BabelParseError(badExpression.node, "Invalid substitutions for `$localize` (expected all substitution arguments to be expressions).");
170
+ }
171
+ return [
172
+ expressions.map((path) => path.node),
173
+ expressions.map((expression) => getLocation(fs, expression))
174
+ ];
175
+ }
176
+ function unwrapMessagePartsFromTemplateLiteral(elements, fs = getFileSystem()) {
177
+ const cooked = elements.map((q) => {
178
+ if (q.node.value.cooked === void 0) {
179
+ throw new BabelParseError(q.node, `Unexpected undefined message part in "${elements.map((q2) => q2.node.value.cooked)}"`);
180
+ }
181
+ return q.node.value.cooked;
182
+ });
183
+ const raw = elements.map((q) => q.node.value.raw);
184
+ const locations = elements.map((q) => getLocation(fs, q));
185
+ return [\u0275makeTemplateObject(cooked, raw), locations];
186
+ }
187
+ function unwrapExpressionsFromTemplateLiteral(quasi, fs = getFileSystem()) {
188
+ return [quasi.node.expressions, quasi.get("expressions").map((e) => getLocation(fs, e))];
189
+ }
190
+ function unwrapStringLiteralArray(array, fs = getFileSystem()) {
191
+ if (!isStringLiteralArray(array.node)) {
192
+ throw new BabelParseError(array.node, "Unexpected messageParts for `$localize` (expected an array of strings).");
193
+ }
194
+ const elements = array.get("elements");
195
+ return [elements.map((str) => str.node.value), elements.map((str) => getLocation(fs, str))];
196
+ }
197
+ function unwrapLazyLoadHelperCall(call) {
198
+ const callee = call.get("callee");
199
+ if (!callee.isIdentifier()) {
200
+ throw new BabelParseError(callee.node, "Unexpected lazy-load helper call (expected a call of the form `_templateObject()`).");
201
+ }
202
+ const lazyLoadBinding = call.scope.getBinding(callee.node.name);
203
+ if (!lazyLoadBinding) {
204
+ throw new BabelParseError(callee.node, "Missing declaration for lazy-load helper function");
205
+ }
206
+ const lazyLoadFn = lazyLoadBinding.path;
207
+ if (!lazyLoadFn.isFunctionDeclaration()) {
208
+ throw new BabelParseError(lazyLoadFn.node, "Unexpected expression (expected a function declaration");
209
+ }
210
+ const returnedNode = getReturnedExpression(lazyLoadFn);
211
+ if (returnedNode.isCallExpression()) {
212
+ return returnedNode;
213
+ }
214
+ if (returnedNode.isIdentifier()) {
215
+ const identifierName = returnedNode.node.name;
216
+ const declaration = returnedNode.scope.getBinding(identifierName);
217
+ if (declaration === void 0) {
218
+ throw new BabelParseError(returnedNode.node, "Missing declaration for return value from helper.");
219
+ }
220
+ if (!declaration.path.isVariableDeclarator()) {
221
+ throw new BabelParseError(declaration.path.node, "Unexpected helper return value declaration (expected a variable declaration).");
222
+ }
223
+ const initializer = declaration.path.get("init");
224
+ if (!initializer.isCallExpression()) {
225
+ throw new BabelParseError(declaration.path.node, "Unexpected return value from helper (expected a call expression).");
226
+ }
227
+ if (lazyLoadBinding.references === 1) {
228
+ lazyLoadFn.remove();
229
+ }
230
+ return initializer;
231
+ }
232
+ return call;
233
+ }
234
+ function getReturnedExpression(fn) {
235
+ const bodyStatements = fn.get("body").get("body");
236
+ for (const statement of bodyStatements) {
237
+ if (statement.isReturnStatement()) {
238
+ const argument = statement.get("argument");
239
+ if (argument.isSequenceExpression()) {
240
+ const expressions = argument.get("expressions");
241
+ return Array.isArray(expressions) ? expressions[expressions.length - 1] : expressions;
242
+ } else if (argument.isExpression()) {
243
+ return argument;
244
+ } else {
245
+ throw new BabelParseError(statement.node, "Invalid return argument in helper function (expected an expression).");
246
+ }
247
+ }
248
+ }
249
+ throw new BabelParseError(fn.node, "Missing return statement in helper function.");
250
+ }
251
+ function isStringLiteralArray(node) {
252
+ return types.isArrayExpression(node) && node.elements.every((element) => types.isStringLiteral(element));
253
+ }
254
+ function isArrayOfExpressions(paths) {
255
+ return paths.every((element) => element.isExpression());
256
+ }
257
+ var BabelParseError = class extends Error {
258
+ constructor(node, message) {
259
+ super(message);
260
+ this.node = node;
261
+ this.type = "BabelParseError";
262
+ }
263
+ };
264
+ function isBabelParseError(e) {
265
+ return e.type === "BabelParseError";
266
+ }
267
+ function buildCodeFrameError(fs, path, e) {
268
+ let filename = path.hub.file.opts.filename;
269
+ if (filename) {
270
+ filename = fs.resolve(filename);
271
+ let cwd = path.hub.file.opts.cwd;
272
+ if (cwd) {
273
+ cwd = fs.resolve(cwd);
274
+ filename = fs.relative(cwd, filename);
275
+ }
276
+ } else {
277
+ filename = "(unknown file)";
278
+ }
279
+ const message = path.hub.file.buildCodeFrameError(e.node, e.message).message;
280
+ return `${filename}: ${message}`;
281
+ }
282
+ function getLocation(fs, startPath, endPath) {
283
+ const startLocation = startPath.node.loc;
284
+ const file = getFileFromPath(fs, startPath);
285
+ if (!startLocation || !file) {
286
+ return void 0;
287
+ }
288
+ const endLocation = endPath && getFileFromPath(fs, endPath) === file && endPath.node.loc || startLocation;
289
+ return {
290
+ start: getLineAndColumn(startLocation.start),
291
+ end: getLineAndColumn(endLocation.end),
292
+ file,
293
+ text: getText(startPath)
294
+ };
295
+ }
296
+ function serializeLocationPosition(location) {
297
+ const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
298
+ return `${location.start.line + 1}${endLineString}`;
299
+ }
300
+ function getFileFromPath(fs, path) {
301
+ var _a2;
302
+ const opts = path == null ? void 0 : path.hub.file.opts;
303
+ const filename = opts == null ? void 0 : opts.filename;
304
+ if (!filename) {
305
+ return null;
306
+ }
307
+ const relativePath = fs.relative(opts.cwd, filename);
308
+ const root = (_a2 = opts.generatorOpts.sourceRoot) != null ? _a2 : opts.cwd;
309
+ const absPath = fs.resolve(root, relativePath);
310
+ return absPath;
311
+ }
312
+ function getLineAndColumn(loc) {
313
+ return { line: loc.line - 1, column: loc.column };
314
+ }
315
+ function getText(path) {
316
+ if (path.node.start === null || path.node.end === null) {
317
+ return void 0;
318
+ }
319
+ return path.hub.file.code.substring(path.node.start, path.node.end);
320
+ }
321
+
322
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/duplicates.mjs
323
+ function checkDuplicateMessages(fs, messages, duplicateMessageHandling2, basePath) {
324
+ const diagnostics = new Diagnostics();
325
+ if (duplicateMessageHandling2 === "ignore")
326
+ return diagnostics;
327
+ const messageMap = new Map();
328
+ for (const message of messages) {
329
+ if (messageMap.has(message.id)) {
330
+ messageMap.get(message.id).push(message);
331
+ } else {
332
+ messageMap.set(message.id, [message]);
333
+ }
334
+ }
335
+ for (const duplicates of messageMap.values()) {
336
+ if (duplicates.length <= 1)
337
+ continue;
338
+ if (duplicates.every((message) => message.text === duplicates[0].text))
339
+ continue;
340
+ const diagnosticMessage = `Duplicate messages with id "${duplicates[0].id}":
341
+ ` + duplicates.map((message) => serializeMessage(fs, basePath, message)).join("\n");
342
+ diagnostics.add(duplicateMessageHandling2, diagnosticMessage);
343
+ }
344
+ return diagnostics;
345
+ }
346
+ function serializeMessage(fs, basePath, message) {
347
+ if (message.location === void 0) {
348
+ return ` - "${message.text}"`;
349
+ } else {
350
+ const locationFile = fs.relative(basePath, message.location.file);
351
+ const locationPosition = serializeLocationPosition(message.location);
352
+ return ` - "${message.text}" : ${locationFile}:${locationPosition}`;
353
+ }
354
+ }
355
+
356
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
357
+ import { SourceFileLoader } from "@angular/compiler-cli/private/localize";
358
+
359
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es2015_extract_plugin.mjs
360
+ import { \u0275parseMessage } from "@angular/localize";
361
+ function makeEs2015ExtractPlugin(fs, messages, localizeName = "$localize") {
362
+ return {
363
+ visitor: {
364
+ TaggedTemplateExpression(path) {
365
+ const tag = path.get("tag");
366
+ if (isNamedIdentifier(tag, localizeName) && isGlobalIdentifier(tag)) {
367
+ const quasiPath = path.get("quasi");
368
+ const [messageParts, messagePartLocations] = unwrapMessagePartsFromTemplateLiteral(quasiPath.get("quasis"), fs);
369
+ const [expressions, expressionLocations] = unwrapExpressionsFromTemplateLiteral(quasiPath, fs);
370
+ const location = getLocation(fs, quasiPath);
371
+ const message = \u0275parseMessage(messageParts, expressions, location, messagePartLocations, expressionLocations);
372
+ messages.push(message);
373
+ }
374
+ }
375
+ }
376
+ };
377
+ }
378
+
379
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es5_extract_plugin.mjs
380
+ import { \u0275parseMessage as \u0275parseMessage2 } from "@angular/localize";
381
+ function makeEs5ExtractPlugin(fs, messages, localizeName = "$localize") {
382
+ return {
383
+ visitor: {
384
+ CallExpression(callPath) {
385
+ try {
386
+ const calleePath = callPath.get("callee");
387
+ if (isNamedIdentifier(calleePath, localizeName) && isGlobalIdentifier(calleePath)) {
388
+ const [messageParts, messagePartLocations] = unwrapMessagePartsFromLocalizeCall(callPath, fs);
389
+ const [expressions, expressionLocations] = unwrapSubstitutionsFromLocalizeCall(callPath, fs);
390
+ const [messagePartsArg, expressionsArg] = callPath.get("arguments");
391
+ const location = getLocation(fs, messagePartsArg, expressionsArg);
392
+ const message = \u0275parseMessage2(messageParts, expressions, location, messagePartLocations, expressionLocations);
393
+ messages.push(message);
394
+ }
395
+ } catch (e) {
396
+ if (isBabelParseError(e)) {
397
+ throw buildCodeFrameError(fs, callPath, e);
398
+ } else {
399
+ throw e;
400
+ }
401
+ }
402
+ }
403
+ }
404
+ };
405
+ }
406
+
407
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
408
+ var MessageExtractor = class {
409
+ constructor(fs, logger2, { basePath, useSourceMaps = true, localizeName = "$localize" }) {
410
+ this.fs = fs;
411
+ this.logger = logger2;
412
+ this.basePath = basePath;
413
+ this.useSourceMaps = useSourceMaps;
414
+ this.localizeName = localizeName;
415
+ this.loader = new SourceFileLoader(this.fs, this.logger, { webpack: basePath });
416
+ }
417
+ extractMessages(filename) {
418
+ const messages = [];
419
+ const sourceCode = this.fs.readFile(this.fs.resolve(this.basePath, filename));
420
+ if (sourceCode.includes(this.localizeName)) {
421
+ transformSync(sourceCode, {
422
+ sourceRoot: this.basePath,
423
+ filename,
424
+ plugins: [
425
+ makeEs2015ExtractPlugin(this.fs, messages, this.localizeName),
426
+ makeEs5ExtractPlugin(this.fs, messages, this.localizeName)
427
+ ],
428
+ code: false,
429
+ ast: false
430
+ });
431
+ if (this.useSourceMaps && messages.length > 0) {
432
+ this.updateSourceLocations(filename, sourceCode, messages);
433
+ }
434
+ }
435
+ return messages;
436
+ }
437
+ updateSourceLocations(filename, contents, messages) {
438
+ const sourceFile = this.loader.loadSourceFile(this.fs.resolve(this.basePath, filename), contents);
439
+ if (sourceFile === null) {
440
+ return;
441
+ }
442
+ for (const message of messages) {
443
+ if (message.location !== void 0) {
444
+ message.location = this.getOriginalLocation(sourceFile, message.location);
445
+ if (message.messagePartLocations) {
446
+ message.messagePartLocations = message.messagePartLocations.map((location) => location && this.getOriginalLocation(sourceFile, location));
447
+ }
448
+ if (message.substitutionLocations) {
449
+ const placeholderNames = Object.keys(message.substitutionLocations);
450
+ for (const placeholderName of placeholderNames) {
451
+ const location = message.substitutionLocations[placeholderName];
452
+ message.substitutionLocations[placeholderName] = location && this.getOriginalLocation(sourceFile, location);
453
+ }
454
+ }
455
+ }
456
+ }
457
+ }
458
+ getOriginalLocation(sourceFile, location) {
459
+ const originalStart = sourceFile.getOriginalLocation(location.start.line, location.start.column);
460
+ if (originalStart === null) {
461
+ return location;
462
+ }
463
+ const originalEnd = sourceFile.getOriginalLocation(location.end.line, location.end.column);
464
+ const start = { line: originalStart.line, column: originalStart.column };
465
+ const end = originalEnd !== null && originalEnd.file === originalStart.file ? { line: originalEnd.line, column: originalEnd.column } : start;
466
+ const originalSourceFile = sourceFile.sources.find((sf) => (sf == null ? void 0 : sf.sourcePath) === originalStart.file);
467
+ const startPos = originalSourceFile.startOfLinePositions[start.line] + start.column;
468
+ const endPos = originalSourceFile.startOfLinePositions[end.line] + end.column;
469
+ const text = originalSourceFile.contents.substring(startPos, endPos).trim();
470
+ return { file: originalStart.file, start, end, text };
471
+ }
472
+ };
473
+
474
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/utils.mjs
475
+ function consolidateMessages(messages, getMessageId2) {
476
+ const messageGroups = new Map();
477
+ for (const message of messages) {
478
+ const id = getMessageId2(message);
479
+ if (!messageGroups.has(id)) {
480
+ messageGroups.set(id, [message]);
481
+ } else {
482
+ messageGroups.get(id).push(message);
483
+ }
484
+ }
485
+ for (const messages2 of messageGroups.values()) {
486
+ messages2.sort(compareLocations);
487
+ }
488
+ return Array.from(messageGroups.values()).sort((a1, a2) => compareLocations(a1[0], a2[0]));
489
+ }
490
+ function hasLocation(message) {
491
+ return message.location !== void 0;
492
+ }
493
+ function compareLocations({ location: location1 }, { location: location2 }) {
494
+ if (location1 === location2) {
495
+ return 0;
496
+ }
497
+ if (location1 === void 0) {
498
+ return -1;
499
+ }
500
+ if (location2 === void 0) {
501
+ return 1;
502
+ }
503
+ if (location1.file !== location2.file) {
504
+ return location1.file < location2.file ? -1 : 1;
505
+ }
506
+ if (location1.start.line !== location2.start.line) {
507
+ return location1.start.line < location2.start.line ? -1 : 1;
508
+ }
509
+ if (location1.start.column !== location2.start.column) {
510
+ return location1.start.column < location2.start.column ? -1 : 1;
511
+ }
512
+ return 0;
513
+ }
514
+
515
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/arb_translation_serializer.mjs
516
+ var ArbTranslationSerializer = class {
517
+ constructor(sourceLocale, basePath, fs) {
518
+ this.sourceLocale = sourceLocale;
519
+ this.basePath = basePath;
520
+ this.fs = fs;
521
+ }
522
+ serialize(messages) {
523
+ const messageGroups = consolidateMessages(messages, (message) => getMessageId(message));
524
+ let output = `{
525
+ "@@locale": ${JSON.stringify(this.sourceLocale)}`;
526
+ for (const duplicateMessages of messageGroups) {
527
+ const message = duplicateMessages[0];
528
+ const id = getMessageId(message);
529
+ output += this.serializeMessage(id, message);
530
+ output += this.serializeMeta(id, message.description, message.meaning, duplicateMessages.filter(hasLocation).map((m) => m.location));
531
+ }
532
+ output += "\n}";
533
+ return output;
534
+ }
535
+ serializeMessage(id, message) {
536
+ return `,
537
+ ${JSON.stringify(id)}: ${JSON.stringify(message.text)}`;
538
+ }
539
+ serializeMeta(id, description, meaning, locations) {
540
+ const meta = [];
541
+ if (description) {
542
+ meta.push(`
543
+ "description": ${JSON.stringify(description)}`);
544
+ }
545
+ if (meaning) {
546
+ meta.push(`
547
+ "x-meaning": ${JSON.stringify(meaning)}`);
548
+ }
549
+ if (locations.length > 0) {
550
+ let locationStr = `
551
+ "x-locations": [`;
552
+ for (let i = 0; i < locations.length; i++) {
553
+ locationStr += (i > 0 ? ",\n" : "\n") + this.serializeLocation(locations[i]);
554
+ }
555
+ locationStr += "\n ]";
556
+ meta.push(locationStr);
557
+ }
558
+ return meta.length > 0 ? `,
559
+ ${JSON.stringify("@" + id)}: {${meta.join(",")}
560
+ }` : "";
561
+ }
562
+ serializeLocation({ file, start, end }) {
563
+ return [
564
+ ` {`,
565
+ ` "file": ${JSON.stringify(this.fs.relative(this.basePath, file))},`,
566
+ ` "start": { "line": "${start.line}", "column": "${start.column}" },`,
567
+ ` "end": { "line": "${end.line}", "column": "${end.column}" }`,
568
+ ` }`
569
+ ].join("\n");
570
+ }
571
+ };
572
+ function getMessageId(message) {
573
+ return message.customId || message.id;
574
+ }
575
+
576
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/json_translation_serializer.mjs
577
+ var SimpleJsonTranslationSerializer = class {
578
+ constructor(sourceLocale) {
579
+ this.sourceLocale = sourceLocale;
580
+ }
581
+ serialize(messages) {
582
+ const fileObj = { locale: this.sourceLocale, translations: {} };
583
+ for (const [message] of consolidateMessages(messages, (message2) => message2.id)) {
584
+ fileObj.translations[message.id] = message.text;
585
+ }
586
+ return JSON.stringify(fileObj, null, 2);
587
+ }
588
+ };
589
+
590
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/legacy_message_id_migration_serializer.mjs
591
+ var LegacyMessageIdMigrationSerializer = class {
592
+ constructor(_diagnostics) {
593
+ this._diagnostics = _diagnostics;
594
+ }
595
+ serialize(messages) {
596
+ let hasMessages = false;
597
+ const mapping = messages.reduce((output, message) => {
598
+ if (shouldMigrate(message)) {
599
+ for (const legacyId of message.legacyIds) {
600
+ if (output.hasOwnProperty(legacyId)) {
601
+ this._diagnostics.warn(`Detected duplicate legacy ID ${legacyId}.`);
602
+ }
603
+ output[legacyId] = message.id;
604
+ hasMessages = true;
605
+ }
606
+ }
607
+ return output;
608
+ }, {});
609
+ if (!hasMessages) {
610
+ this._diagnostics.warn("Could not find any legacy message IDs in source files while generating the legacy message migration file.");
611
+ }
612
+ return JSON.stringify(mapping, null, 2);
613
+ }
614
+ };
615
+ function shouldMigrate(message) {
616
+ return !message.customId && !!message.legacyIds && message.legacyIds.length > 0;
617
+ }
618
+
619
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
620
+ import { getFileSystem as getFileSystem2 } from "@angular/compiler-cli/private/localize";
621
+
622
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/icu_parsing.mjs
623
+ function extractIcuPlaceholders(text) {
624
+ const state = new StateStack();
625
+ const pieces = new IcuPieces();
626
+ const braces = /[{}]/g;
627
+ let lastPos = 0;
628
+ let match;
629
+ while (match = braces.exec(text)) {
630
+ if (match[0] == "{") {
631
+ state.enterBlock();
632
+ } else {
633
+ state.leaveBlock();
634
+ }
635
+ if (state.getCurrent() === "placeholder") {
636
+ const name = tryParsePlaceholder(text, braces.lastIndex);
637
+ if (name) {
638
+ pieces.addText(text.substring(lastPos, braces.lastIndex - 1));
639
+ pieces.addPlaceholder(name);
640
+ braces.lastIndex += name.length + 1;
641
+ state.leaveBlock();
642
+ } else {
643
+ pieces.addText(text.substring(lastPos, braces.lastIndex));
644
+ state.nestedIcu();
645
+ }
646
+ } else {
647
+ pieces.addText(text.substring(lastPos, braces.lastIndex));
648
+ }
649
+ lastPos = braces.lastIndex;
650
+ }
651
+ pieces.addText(text.substring(lastPos));
652
+ return pieces.toArray();
653
+ }
654
+ var IcuPieces = class {
655
+ constructor() {
656
+ this.pieces = [""];
657
+ }
658
+ addText(text) {
659
+ this.pieces[this.pieces.length - 1] += text;
660
+ }
661
+ addPlaceholder(name) {
662
+ this.pieces.push(name);
663
+ this.pieces.push("");
664
+ }
665
+ toArray() {
666
+ return this.pieces;
667
+ }
668
+ };
669
+ var StateStack = class {
670
+ constructor() {
671
+ this.stack = [];
672
+ }
673
+ enterBlock() {
674
+ const current = this.getCurrent();
675
+ switch (current) {
676
+ case "icu":
677
+ this.stack.push("case");
678
+ break;
679
+ case "case":
680
+ this.stack.push("placeholder");
681
+ break;
682
+ case "placeholder":
683
+ this.stack.push("case");
684
+ break;
685
+ default:
686
+ this.stack.push("icu");
687
+ break;
688
+ }
689
+ }
690
+ leaveBlock() {
691
+ return this.stack.pop();
692
+ }
693
+ nestedIcu() {
694
+ const current = this.stack.pop();
695
+ assert(current === "placeholder", "A nested ICU must replace a placeholder but got " + current);
696
+ this.stack.push("icu");
697
+ }
698
+ getCurrent() {
699
+ return this.stack[this.stack.length - 1];
700
+ }
701
+ };
702
+ function tryParsePlaceholder(text, start) {
703
+ for (let i = start; i < text.length; i++) {
704
+ if (text[i] === ",") {
705
+ break;
706
+ }
707
+ if (text[i] === "}") {
708
+ return text.substring(start, i);
709
+ }
710
+ }
711
+ return null;
712
+ }
713
+ function assert(test, message) {
714
+ if (!test) {
715
+ throw new Error("Assertion failure: " + message);
716
+ }
717
+ }
718
+
719
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xml_file.mjs
720
+ var XmlFile = class {
721
+ constructor() {
722
+ this.output = '<?xml version="1.0" encoding="UTF-8" ?>\n';
723
+ this.indent = "";
724
+ this.elements = [];
725
+ this.preservingWhitespace = false;
726
+ }
727
+ toString() {
728
+ return this.output;
729
+ }
730
+ startTag(name, attributes = {}, { selfClosing = false, preserveWhitespace } = {}) {
731
+ if (!this.preservingWhitespace) {
732
+ this.output += this.indent;
733
+ }
734
+ this.output += `<${name}`;
735
+ for (const [attrName, attrValue] of Object.entries(attributes)) {
736
+ if (attrValue) {
737
+ this.output += ` ${attrName}="${escapeXml(attrValue)}"`;
738
+ }
739
+ }
740
+ if (selfClosing) {
741
+ this.output += "/>";
742
+ } else {
743
+ this.output += ">";
744
+ this.elements.push(name);
745
+ this.incIndent();
746
+ }
747
+ if (preserveWhitespace !== void 0) {
748
+ this.preservingWhitespace = preserveWhitespace;
749
+ }
750
+ if (!this.preservingWhitespace) {
751
+ this.output += `
752
+ `;
753
+ }
754
+ return this;
755
+ }
756
+ endTag(name, { preserveWhitespace } = {}) {
757
+ const expectedTag = this.elements.pop();
758
+ if (expectedTag !== name) {
759
+ throw new Error(`Unexpected closing tag: "${name}", expected: "${expectedTag}"`);
760
+ }
761
+ this.decIndent();
762
+ if (!this.preservingWhitespace) {
763
+ this.output += this.indent;
764
+ }
765
+ this.output += `</${name}>`;
766
+ if (preserveWhitespace !== void 0) {
767
+ this.preservingWhitespace = preserveWhitespace;
768
+ }
769
+ if (!this.preservingWhitespace) {
770
+ this.output += `
771
+ `;
772
+ }
773
+ return this;
774
+ }
775
+ text(str) {
776
+ this.output += escapeXml(str);
777
+ return this;
778
+ }
779
+ rawText(str) {
780
+ this.output += str;
781
+ return this;
782
+ }
783
+ incIndent() {
784
+ this.indent = this.indent + " ";
785
+ }
786
+ decIndent() {
787
+ this.indent = this.indent.slice(0, -2);
788
+ }
789
+ };
790
+ var _ESCAPED_CHARS = [
791
+ [/&/g, "&amp;"],
792
+ [/"/g, "&quot;"],
793
+ [/'/g, "&apos;"],
794
+ [/</g, "&lt;"],
795
+ [/>/g, "&gt;"]
796
+ ];
797
+ function escapeXml(text) {
798
+ return _ESCAPED_CHARS.reduce((text2, entry) => text2.replace(entry[0], entry[1]), text);
799
+ }
800
+
801
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
802
+ var LEGACY_XLIFF_MESSAGE_LENGTH = 40;
803
+ var Xliff1TranslationSerializer = class {
804
+ constructor(sourceLocale, basePath, useLegacyIds, formatOptions2 = {}, fs = getFileSystem2()) {
805
+ this.sourceLocale = sourceLocale;
806
+ this.basePath = basePath;
807
+ this.useLegacyIds = useLegacyIds;
808
+ this.formatOptions = formatOptions2;
809
+ this.fs = fs;
810
+ validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions2);
811
+ }
812
+ serialize(messages) {
813
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
814
+ const xml = new XmlFile();
815
+ xml.startTag("xliff", { "version": "1.2", "xmlns": "urn:oasis:names:tc:xliff:document:1.2" });
816
+ xml.startTag("file", __spreadValues({
817
+ "source-language": this.sourceLocale,
818
+ "datatype": "plaintext",
819
+ "original": "ng2.template"
820
+ }, this.formatOptions));
821
+ xml.startTag("body");
822
+ for (const duplicateMessages of messageGroups) {
823
+ const message = duplicateMessages[0];
824
+ const id = this.getMessageId(message);
825
+ xml.startTag("trans-unit", { id, datatype: "html" });
826
+ xml.startTag("source", {}, { preserveWhitespace: true });
827
+ this.serializeMessage(xml, message);
828
+ xml.endTag("source", { preserveWhitespace: false });
829
+ for (const { location } of duplicateMessages.filter(hasLocation)) {
830
+ this.serializeLocation(xml, location);
831
+ }
832
+ if (message.description) {
833
+ this.serializeNote(xml, "description", message.description);
834
+ }
835
+ if (message.meaning) {
836
+ this.serializeNote(xml, "meaning", message.meaning);
837
+ }
838
+ xml.endTag("trans-unit");
839
+ }
840
+ xml.endTag("body");
841
+ xml.endTag("file");
842
+ xml.endTag("xliff");
843
+ return xml.toString();
844
+ }
845
+ serializeMessage(xml, message) {
846
+ var _a2;
847
+ const length = message.messageParts.length - 1;
848
+ for (let i = 0; i < length; i++) {
849
+ this.serializeTextPart(xml, message.messageParts[i]);
850
+ const location = (_a2 = message.substitutionLocations) == null ? void 0 : _a2[message.placeholderNames[i]];
851
+ this.serializePlaceholder(xml, message.placeholderNames[i], location == null ? void 0 : location.text);
852
+ }
853
+ this.serializeTextPart(xml, message.messageParts[length]);
854
+ }
855
+ serializeTextPart(xml, text) {
856
+ const pieces = extractIcuPlaceholders(text);
857
+ const length = pieces.length - 1;
858
+ for (let i = 0; i < length; i += 2) {
859
+ xml.text(pieces[i]);
860
+ this.serializePlaceholder(xml, pieces[i + 1], void 0);
861
+ }
862
+ xml.text(pieces[length]);
863
+ }
864
+ serializePlaceholder(xml, id, text) {
865
+ const attrs = { id };
866
+ const ctype = getCtypeForPlaceholder(id);
867
+ if (ctype !== null) {
868
+ attrs.ctype = ctype;
869
+ }
870
+ if (text !== void 0) {
871
+ attrs["equiv-text"] = text;
872
+ }
873
+ xml.startTag("x", attrs, { selfClosing: true });
874
+ }
875
+ serializeNote(xml, name, value) {
876
+ xml.startTag("note", { priority: "1", from: name }, { preserveWhitespace: true });
877
+ xml.text(value);
878
+ xml.endTag("note", { preserveWhitespace: false });
879
+ }
880
+ serializeLocation(xml, location) {
881
+ xml.startTag("context-group", { purpose: "location" });
882
+ this.renderContext(xml, "sourcefile", this.fs.relative(this.basePath, location.file));
883
+ const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
884
+ this.renderContext(xml, "linenumber", `${location.start.line + 1}${endLineString}`);
885
+ xml.endTag("context-group");
886
+ }
887
+ renderContext(xml, type, value) {
888
+ xml.startTag("context", { "context-type": type }, { preserveWhitespace: true });
889
+ xml.text(value);
890
+ xml.endTag("context", { preserveWhitespace: false });
891
+ }
892
+ getMessageId(message) {
893
+ return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length === LEGACY_XLIFF_MESSAGE_LENGTH) || message.id;
894
+ }
895
+ };
896
+ function getCtypeForPlaceholder(placeholder) {
897
+ const tag = placeholder.replace(/^(START_|CLOSE_)/, "");
898
+ switch (tag) {
899
+ case "LINE_BREAK":
900
+ return "lb";
901
+ case "TAG_IMG":
902
+ return "image";
903
+ default:
904
+ const element = tag.startsWith("TAG_") ? tag.replace(/^TAG_(.+)/, (_, tagName) => tagName.toLowerCase()) : TAG_MAP[tag];
905
+ if (element === void 0) {
906
+ return null;
907
+ }
908
+ return `x-${element}`;
909
+ }
910
+ }
911
+ var TAG_MAP = {
912
+ "LINK": "a",
913
+ "BOLD_TEXT": "b",
914
+ "EMPHASISED_TEXT": "em",
915
+ "HEADING_LEVEL1": "h1",
916
+ "HEADING_LEVEL2": "h2",
917
+ "HEADING_LEVEL3": "h3",
918
+ "HEADING_LEVEL4": "h4",
919
+ "HEADING_LEVEL5": "h5",
920
+ "HEADING_LEVEL6": "h6",
921
+ "HORIZONTAL_RULE": "hr",
922
+ "ITALIC_TEXT": "i",
923
+ "LIST_ITEM": "li",
924
+ "MEDIA_LINK": "link",
925
+ "ORDERED_LIST": "ol",
926
+ "PARAGRAPH": "p",
927
+ "QUOTATION": "q",
928
+ "STRIKETHROUGH_TEXT": "s",
929
+ "SMALL_TEXT": "small",
930
+ "SUBSTRIPT": "sub",
931
+ "SUPERSCRIPT": "sup",
932
+ "TABLE_BODY": "tbody",
933
+ "TABLE_CELL": "td",
934
+ "TABLE_FOOTER": "tfoot",
935
+ "TABLE_HEADER_CELL": "th",
936
+ "TABLE_HEADER": "thead",
937
+ "TABLE_ROW": "tr",
938
+ "MONOSPACED_TEXT": "tt",
939
+ "UNDERLINED_TEXT": "u",
940
+ "UNORDERED_LIST": "ul"
941
+ };
942
+
943
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff2_translation_serializer.mjs
944
+ import { getFileSystem as getFileSystem3 } from "@angular/compiler-cli/private/localize";
945
+ var MAX_LEGACY_XLIFF_2_MESSAGE_LENGTH = 20;
946
+ var Xliff2TranslationSerializer = class {
947
+ constructor(sourceLocale, basePath, useLegacyIds, formatOptions2 = {}, fs = getFileSystem3()) {
948
+ this.sourceLocale = sourceLocale;
949
+ this.basePath = basePath;
950
+ this.useLegacyIds = useLegacyIds;
951
+ this.formatOptions = formatOptions2;
952
+ this.fs = fs;
953
+ this.currentPlaceholderId = 0;
954
+ validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions2);
955
+ }
956
+ serialize(messages) {
957
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
958
+ const xml = new XmlFile();
959
+ xml.startTag("xliff", {
960
+ "version": "2.0",
961
+ "xmlns": "urn:oasis:names:tc:xliff:document:2.0",
962
+ "srcLang": this.sourceLocale
963
+ });
964
+ xml.startTag("file", __spreadValues({ "id": "ngi18n", "original": "ng.template" }, this.formatOptions));
965
+ for (const duplicateMessages of messageGroups) {
966
+ const message = duplicateMessages[0];
967
+ const id = this.getMessageId(message);
968
+ xml.startTag("unit", { id });
969
+ const messagesWithLocations = duplicateMessages.filter(hasLocation);
970
+ if (message.meaning || message.description || messagesWithLocations.length) {
971
+ xml.startTag("notes");
972
+ for (const { location: { file, start, end } } of messagesWithLocations) {
973
+ const endLineString = end !== void 0 && end.line !== start.line ? `,${end.line + 1}` : "";
974
+ this.serializeNote(xml, "location", `${this.fs.relative(this.basePath, file)}:${start.line + 1}${endLineString}`);
975
+ }
976
+ if (message.description) {
977
+ this.serializeNote(xml, "description", message.description);
978
+ }
979
+ if (message.meaning) {
980
+ this.serializeNote(xml, "meaning", message.meaning);
981
+ }
982
+ xml.endTag("notes");
983
+ }
984
+ xml.startTag("segment");
985
+ xml.startTag("source", {}, { preserveWhitespace: true });
986
+ this.serializeMessage(xml, message);
987
+ xml.endTag("source", { preserveWhitespace: false });
988
+ xml.endTag("segment");
989
+ xml.endTag("unit");
990
+ }
991
+ xml.endTag("file");
992
+ xml.endTag("xliff");
993
+ return xml.toString();
994
+ }
995
+ serializeMessage(xml, message) {
996
+ this.currentPlaceholderId = 0;
997
+ const length = message.messageParts.length - 1;
998
+ for (let i = 0; i < length; i++) {
999
+ this.serializeTextPart(xml, message.messageParts[i]);
1000
+ this.serializePlaceholder(xml, message.placeholderNames[i], message.substitutionLocations);
1001
+ }
1002
+ this.serializeTextPart(xml, message.messageParts[length]);
1003
+ }
1004
+ serializeTextPart(xml, text) {
1005
+ const pieces = extractIcuPlaceholders(text);
1006
+ const length = pieces.length - 1;
1007
+ for (let i = 0; i < length; i += 2) {
1008
+ xml.text(pieces[i]);
1009
+ this.serializePlaceholder(xml, pieces[i + 1], void 0);
1010
+ }
1011
+ xml.text(pieces[length]);
1012
+ }
1013
+ serializePlaceholder(xml, placeholderName, substitutionLocations) {
1014
+ var _a2, _b;
1015
+ const text = (_a2 = substitutionLocations == null ? void 0 : substitutionLocations[placeholderName]) == null ? void 0 : _a2.text;
1016
+ if (placeholderName.startsWith("START_")) {
1017
+ const closingPlaceholderName = placeholderName.replace(/^START/, "CLOSE").replace(/_\d+$/, "");
1018
+ const closingText = (_b = substitutionLocations == null ? void 0 : substitutionLocations[closingPlaceholderName]) == null ? void 0 : _b.text;
1019
+ const attrs = {
1020
+ id: `${this.currentPlaceholderId++}`,
1021
+ equivStart: placeholderName,
1022
+ equivEnd: closingPlaceholderName
1023
+ };
1024
+ const type = getTypeForPlaceholder(placeholderName);
1025
+ if (type !== null) {
1026
+ attrs.type = type;
1027
+ }
1028
+ if (text !== void 0) {
1029
+ attrs.dispStart = text;
1030
+ }
1031
+ if (closingText !== void 0) {
1032
+ attrs.dispEnd = closingText;
1033
+ }
1034
+ xml.startTag("pc", attrs);
1035
+ } else if (placeholderName.startsWith("CLOSE_")) {
1036
+ xml.endTag("pc");
1037
+ } else {
1038
+ const attrs = {
1039
+ id: `${this.currentPlaceholderId++}`,
1040
+ equiv: placeholderName
1041
+ };
1042
+ const type = getTypeForPlaceholder(placeholderName);
1043
+ if (type !== null) {
1044
+ attrs.type = type;
1045
+ }
1046
+ if (text !== void 0) {
1047
+ attrs.disp = text;
1048
+ }
1049
+ xml.startTag("ph", attrs, { selfClosing: true });
1050
+ }
1051
+ }
1052
+ serializeNote(xml, name, value) {
1053
+ xml.startTag("note", { category: name }, { preserveWhitespace: true });
1054
+ xml.text(value);
1055
+ xml.endTag("note", { preserveWhitespace: false });
1056
+ }
1057
+ getMessageId(message) {
1058
+ 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;
1059
+ }
1060
+ };
1061
+ function getTypeForPlaceholder(placeholder) {
1062
+ const tag = placeholder.replace(/^(START_|CLOSE_)/, "").replace(/_\d+$/, "");
1063
+ switch (tag) {
1064
+ case "BOLD_TEXT":
1065
+ case "EMPHASISED_TEXT":
1066
+ case "ITALIC_TEXT":
1067
+ case "LINE_BREAK":
1068
+ case "STRIKETHROUGH_TEXT":
1069
+ case "UNDERLINED_TEXT":
1070
+ return "fmt";
1071
+ case "TAG_IMG":
1072
+ return "image";
1073
+ case "LINK":
1074
+ return "link";
1075
+ default:
1076
+ return /^(START_|CLOSE_)/.test(placeholder) ? "other" : null;
1077
+ }
1078
+ }
1079
+
1080
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xmb_translation_serializer.mjs
1081
+ import { getFileSystem as getFileSystem4 } from "@angular/compiler-cli/private/localize";
1082
+ var XmbTranslationSerializer = class {
1083
+ constructor(basePath, useLegacyIds, fs = getFileSystem4()) {
1084
+ this.basePath = basePath;
1085
+ this.useLegacyIds = useLegacyIds;
1086
+ this.fs = fs;
1087
+ }
1088
+ serialize(messages) {
1089
+ const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
1090
+ const xml = new XmlFile();
1091
+ xml.rawText(`<!DOCTYPE messagebundle [
1092
+ <!ELEMENT messagebundle (msg)*>
1093
+ <!ATTLIST messagebundle class CDATA #IMPLIED>
1094
+
1095
+ <!ELEMENT msg (#PCDATA|ph|source)*>
1096
+ <!ATTLIST msg id CDATA #IMPLIED>
1097
+ <!ATTLIST msg seq CDATA #IMPLIED>
1098
+ <!ATTLIST msg name CDATA #IMPLIED>
1099
+ <!ATTLIST msg desc CDATA #IMPLIED>
1100
+ <!ATTLIST msg meaning CDATA #IMPLIED>
1101
+ <!ATTLIST msg obsolete (obsolete) #IMPLIED>
1102
+ <!ATTLIST msg xml:space (default|preserve) "default">
1103
+ <!ATTLIST msg is_hidden CDATA #IMPLIED>
1104
+
1105
+ <!ELEMENT source (#PCDATA)>
1106
+
1107
+ <!ELEMENT ph (#PCDATA|ex)*>
1108
+ <!ATTLIST ph name CDATA #REQUIRED>
1109
+
1110
+ <!ELEMENT ex (#PCDATA)>
1111
+ ]>
1112
+ `);
1113
+ xml.startTag("messagebundle");
1114
+ for (const duplicateMessages of messageGroups) {
1115
+ const message = duplicateMessages[0];
1116
+ const id = this.getMessageId(message);
1117
+ xml.startTag("msg", { id, desc: message.description, meaning: message.meaning }, { preserveWhitespace: true });
1118
+ if (message.location) {
1119
+ this.serializeLocation(xml, message.location);
1120
+ }
1121
+ this.serializeMessage(xml, message);
1122
+ xml.endTag("msg", { preserveWhitespace: false });
1123
+ }
1124
+ xml.endTag("messagebundle");
1125
+ return xml.toString();
1126
+ }
1127
+ serializeLocation(xml, location) {
1128
+ xml.startTag("source");
1129
+ const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
1130
+ xml.text(`${this.fs.relative(this.basePath, location.file)}:${location.start.line}${endLineString}`);
1131
+ xml.endTag("source");
1132
+ }
1133
+ serializeMessage(xml, message) {
1134
+ const length = message.messageParts.length - 1;
1135
+ for (let i = 0; i < length; i++) {
1136
+ this.serializeTextPart(xml, message.messageParts[i]);
1137
+ xml.startTag("ph", { name: message.placeholderNames[i] }, { selfClosing: true });
1138
+ }
1139
+ this.serializeTextPart(xml, message.messageParts[length]);
1140
+ }
1141
+ serializeTextPart(xml, text) {
1142
+ const pieces = extractIcuPlaceholders(text);
1143
+ const length = pieces.length - 1;
1144
+ for (let i = 0; i < length; i += 2) {
1145
+ xml.text(pieces[i]);
1146
+ xml.startTag("ph", { name: pieces[i + 1] }, { selfClosing: true });
1147
+ }
1148
+ xml.text(pieces[length]);
1149
+ }
1150
+ getMessageId(message) {
1151
+ return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length <= 20 && !/[^0-9]/.test(id)) || message.id;
1152
+ }
1153
+ };
1154
+
1155
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/index.mjs
1156
+ function extractTranslations({ rootPath: rootPath2, sourceFilePaths: sourceFilePaths2, sourceLocale, format: format2, outputPath: output, logger: logger2, useSourceMaps, useLegacyIds, duplicateMessageHandling: duplicateMessageHandling2, formatOptions: formatOptions2 = {}, fileSystem: fs }) {
1157
+ const basePath = fs.resolve(rootPath2);
1158
+ const extractor = new MessageExtractor(fs, logger2, { basePath, useSourceMaps });
1159
+ const messages = [];
1160
+ for (const file of sourceFilePaths2) {
1161
+ messages.push(...extractor.extractMessages(file));
1162
+ }
1163
+ const diagnostics = checkDuplicateMessages(fs, messages, duplicateMessageHandling2, basePath);
1164
+ if (diagnostics.hasErrors) {
1165
+ throw new Error(diagnostics.formatDiagnostics("Failed to extract messages"));
1166
+ }
1167
+ const outputPath = fs.resolve(rootPath2, output);
1168
+ const serializer = getSerializer(format2, sourceLocale, fs.dirname(outputPath), useLegacyIds, formatOptions2, fs, diagnostics);
1169
+ const translationFile = serializer.serialize(messages);
1170
+ fs.ensureDir(fs.dirname(outputPath));
1171
+ fs.writeFile(outputPath, translationFile);
1172
+ if (diagnostics.messages.length) {
1173
+ logger2.warn(diagnostics.formatDiagnostics("Messages extracted with warnings"));
1174
+ }
1175
+ }
1176
+ function getSerializer(format2, sourceLocale, rootPath2, useLegacyIds, formatOptions2 = {}, fs, diagnostics) {
1177
+ switch (format2) {
1178
+ case "xlf":
1179
+ case "xlif":
1180
+ case "xliff":
1181
+ return new Xliff1TranslationSerializer(sourceLocale, rootPath2, useLegacyIds, formatOptions2, fs);
1182
+ case "xlf2":
1183
+ case "xlif2":
1184
+ case "xliff2":
1185
+ return new Xliff2TranslationSerializer(sourceLocale, rootPath2, useLegacyIds, formatOptions2, fs);
1186
+ case "xmb":
1187
+ return new XmbTranslationSerializer(rootPath2, useLegacyIds, fs);
1188
+ case "json":
1189
+ return new SimpleJsonTranslationSerializer(sourceLocale);
1190
+ case "arb":
1191
+ return new ArbTranslationSerializer(sourceLocale, rootPath2, fs);
1192
+ case "legacy-migrate":
1193
+ return new LegacyMessageIdMigrationSerializer(diagnostics);
1194
+ }
1195
+ throw new Error(`No translation serializer can handle the provided format: ${format2}`);
1196
+ }
1197
+
1198
+ // bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/cli.mjs
1199
+ process.title = "Angular Localization Message Extractor (localize-extract)";
1200
+ var args = process.argv.slice(2);
1201
+ var options = yargs(args).option("l", {
1202
+ alias: "locale",
1203
+ describe: "The locale of the source being processed",
1204
+ default: "en",
1205
+ type: "string"
1206
+ }).option("r", {
1207
+ alias: "root",
1208
+ default: ".",
1209
+ describe: "The root path for other paths provided in these options.\nThis should either be absolute or relative to the current working directory.",
1210
+ type: "string"
1211
+ }).option("s", {
1212
+ alias: "source",
1213
+ required: true,
1214
+ describe: "A glob pattern indicating what files to search for translations, e.g. `./dist/**/*.js`.\nThis should be relative to the root path.",
1215
+ type: "string"
1216
+ }).option("f", {
1217
+ alias: "format",
1218
+ required: true,
1219
+ choices: ["xmb", "xlf", "xlif", "xliff", "xlf2", "xlif2", "xliff2", "json", "legacy-migrate"],
1220
+ describe: "The format of the translation file.",
1221
+ type: "string"
1222
+ }).option("formatOptions", {
1223
+ describe: 'Additional options to pass to the translation file serializer, in the form of JSON formatted key-value string pairs:\nFor example: `--formatOptions {"xml:space":"preserve"}.\nThe meaning of the options is specific to the format being serialized.',
1224
+ type: "string"
1225
+ }).option("o", {
1226
+ alias: "outputPath",
1227
+ required: true,
1228
+ describe: "A path to where the translation file will be written. This should be relative to the root path.",
1229
+ type: "string"
1230
+ }).option("loglevel", {
1231
+ describe: "The lowest severity logging message that should be output.",
1232
+ choices: ["debug", "info", "warn", "error"],
1233
+ type: "string"
1234
+ }).option("useSourceMaps", {
1235
+ type: "boolean",
1236
+ default: true,
1237
+ describe: "Whether to generate source information in the output files by following source-map mappings found in the source files"
1238
+ }).option("useLegacyIds", {
1239
+ type: "boolean",
1240
+ default: true,
1241
+ describe: "Whether to use the legacy id format for messages that were extracted from Angular templates."
1242
+ }).option("d", {
1243
+ alias: "duplicateMessageHandling",
1244
+ describe: "How to handle messages with the same id but different text.",
1245
+ choices: ["error", "warning", "ignore"],
1246
+ default: "warning",
1247
+ type: "string"
1248
+ }).strict().help().parseSync();
1249
+ var fileSystem = new NodeJSFileSystem();
1250
+ setFileSystem(fileSystem);
1251
+ var rootPath = options.r;
1252
+ var sourceFilePaths = glob.sync(options.s, { cwd: rootPath, nodir: true });
1253
+ var logLevel = options.loglevel;
1254
+ var logger = new ConsoleLogger(logLevel ? LogLevel[logLevel] : LogLevel.warn);
1255
+ var duplicateMessageHandling = options.d;
1256
+ var formatOptions = parseFormatOptions(options.formatOptions);
1257
+ var format = options.f;
1258
+ extractTranslations({
1259
+ rootPath,
1260
+ sourceFilePaths,
1261
+ sourceLocale: options.l,
1262
+ format,
1263
+ outputPath: options.o,
1264
+ logger,
1265
+ useSourceMaps: options.useSourceMaps,
1266
+ useLegacyIds: format === "legacy-migrate" || options.useLegacyIds,
1267
+ duplicateMessageHandling,
1268
+ formatOptions,
1269
+ fileSystem
1270
+ });
1271
+ /**
1272
+ * @license
1273
+ * Copyright Google LLC All Rights Reserved.
1274
+ *
1275
+ * Use of this source code is governed by an MIT-style license that can be
1276
+ * found in the LICENSE file at https://angular.io/license
1277
+ */
1278
+ //# sourceMappingURL=cli.js.map