@angular/localize 13.0.1 → 13.1.0-next.2
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.
- package/esm2020/src/utils/src/messages.mjs +45 -10
- package/fesm2015/init.mjs +1 -1
- package/fesm2015/localize.mjs +45 -10
- package/fesm2015/localize.mjs.map +1 -1
- package/fesm2020/init.mjs +1 -1
- package/fesm2020/localize.mjs +45 -10
- package/fesm2020/localize.mjs.map +1 -1
- package/package.json +3 -3
- package/schematics/ng-add/index.js +1 -1
- package/src/utils/src/messages.d.ts +41 -9
- package/tools/bundles/chunk-KHVODPDB.js +340 -0
- package/tools/bundles/chunk-KHVODPDB.js.map +6 -0
- package/tools/bundles/chunk-LVTJYDSU.js +29 -0
- package/tools/bundles/chunk-LVTJYDSU.js.map +6 -0
- package/tools/bundles/chunk-NTUC2PMV.js +746 -0
- package/tools/bundles/chunk-NTUC2PMV.js.map +6 -0
- package/tools/bundles/chunk-OCJTL5RA.js +904 -0
- package/tools/bundles/chunk-OCJTL5RA.js.map +6 -0
- package/tools/bundles/index.js +31 -1887
- package/tools/bundles/index.js.map +2 -2
- package/tools/bundles/src/extract/cli.js +13 -1143
- package/tools/bundles/src/extract/cli.js.map +2 -2
- package/tools/bundles/src/migrate/cli.js +1 -0
- package/tools/bundles/src/migrate/cli.js.map +1 -1
- package/tools/bundles/src/translate/cli.js +23 -1037
- package/tools/bundles/src/translate/cli.js.map +2 -2
- package/tools/bundles_metadata.json +1 -1
|
@@ -3,1155 +3,25 @@
|
|
|
3
3
|
import {createRequire as __cjsCompatRequire} from 'module';
|
|
4
4
|
const require = __cjsCompatRequire(import.meta.url);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
6
|
+
import {
|
|
7
|
+
ArbTranslationSerializer,
|
|
8
|
+
LegacyMessageIdMigrationSerializer,
|
|
9
|
+
MessageExtractor,
|
|
10
|
+
SimpleJsonTranslationSerializer,
|
|
11
|
+
Xliff1TranslationSerializer,
|
|
12
|
+
Xliff2TranslationSerializer,
|
|
13
|
+
XmbTranslationSerializer,
|
|
14
|
+
checkDuplicateMessages,
|
|
15
|
+
parseFormatOptions
|
|
16
|
+
} from "../../chunk-OCJTL5RA.js";
|
|
17
|
+
import "../../chunk-KHVODPDB.js";
|
|
18
|
+
import "../../chunk-LVTJYDSU.js";
|
|
22
19
|
|
|
23
20
|
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/extract/cli.mjs
|
|
24
21
|
import { ConsoleLogger, LogLevel, NodeJSFileSystem, setFileSystem } from "@angular/compiler-cli/private/localize";
|
|
25
22
|
import glob from "glob";
|
|
26
23
|
import yargs from "yargs";
|
|
27
24
|
|
|
28
|
-
// bazel-out/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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/k8-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
|
|
357
|
-
import { SourceFileLoader } from "@angular/compiler-cli/private/localize";
|
|
358
|
-
|
|
359
|
-
// bazel-out/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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/k8-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, "&"],
|
|
792
|
-
[/"/g, """],
|
|
793
|
-
[/'/g, "'"],
|
|
794
|
-
[/</g, "<"],
|
|
795
|
-
[/>/g, ">"]
|
|
796
|
-
];
|
|
797
|
-
function escapeXml(text) {
|
|
798
|
-
return _ESCAPED_CHARS.reduce((text2, entry) => text2.replace(entry[0], entry[1]), text);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// bazel-out/k8-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/k8-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/k8-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
25
|
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/extract/index.mjs
|
|
1156
26
|
function extractTranslations({ rootPath: rootPath2, sourceFilePaths: sourceFilePaths2, sourceLocale, format: format2, outputPath: output, logger: logger2, useSourceMaps, useLegacyIds, duplicateMessageHandling: duplicateMessageHandling2, formatOptions: formatOptions2 = {}, fileSystem: fs }) {
|
|
1157
27
|
const basePath = fs.resolve(rootPath2);
|