@angular/localize 13.0.0-rc.1 → 13.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/src/localize/src/localize.mjs +2 -2
- package/esm2020/src/utils/src/messages.mjs +45 -10
- package/fesm2015/init.mjs +2 -2
- package/fesm2015/init.mjs.map +1 -1
- package/fesm2015/localize.mjs +45 -10
- package/fesm2015/localize.mjs.map +1 -1
- package/fesm2020/init.mjs +2 -2
- package/fesm2020/init.mjs.map +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/localize/src/localize.d.ts +1 -1
- package/src/utils/src/messages.d.ts +41 -9
- package/tools/bundles/chunk-5AFPBPRI.js +904 -0
- package/tools/bundles/chunk-5AFPBPRI.js.map +6 -0
- package/tools/bundles/chunk-JSM2M4H6.js +746 -0
- package/tools/bundles/chunk-JSM2M4H6.js.map +6 -0
- package/tools/bundles/chunk-KZHPLSGS.js +29 -0
- package/tools/bundles/chunk-KZHPLSGS.js.map +6 -0
- package/tools/bundles/chunk-PHXSPSJE.js +340 -0
- package/tools/bundles/chunk-PHXSPSJE.js.map +6 -0
- package/tools/bundles/index.js +32 -1888
- package/tools/bundles/index.js.map +2 -2
- package/tools/bundles/src/extract/cli.js +17 -1147
- package/tools/bundles/src/extract/cli.js.map +2 -2
- package/tools/bundles/src/migrate/cli.js +6 -5
- package/tools/bundles/src/migrate/cli.js.map +1 -1
- package/tools/bundles/src/translate/cli.js +32 -1046
- package/tools/bundles/src/translate/cli.js.map +2 -2
- package/tools/bundles_metadata.json +1 -1
|
@@ -3,76 +3,41 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
import {
|
|
7
|
+
ArbTranslationParser,
|
|
8
|
+
SimpleJsonTranslationParser,
|
|
9
|
+
Xliff1TranslationParser,
|
|
10
|
+
Xliff2TranslationParser,
|
|
11
|
+
XtbTranslationParser,
|
|
12
|
+
makeEs2015TranslatePlugin,
|
|
13
|
+
makeEs5TranslatePlugin,
|
|
14
|
+
makeLocalePlugin
|
|
15
|
+
} from "../../chunk-JSM2M4H6.js";
|
|
16
|
+
import {
|
|
17
|
+
Diagnostics,
|
|
18
|
+
parseSync,
|
|
19
|
+
transformFromAstSync
|
|
20
|
+
} from "../../chunk-PHXSPSJE.js";
|
|
21
|
+
import {
|
|
22
|
+
__spreadProps,
|
|
23
|
+
__spreadValues
|
|
24
|
+
} from "../../chunk-KZHPLSGS.js";
|
|
25
25
|
|
|
26
|
-
// bazel-out/
|
|
26
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/cli.mjs
|
|
27
27
|
import { NodeJSFileSystem, setFileSystem } from "@angular/compiler-cli/private/localize";
|
|
28
28
|
import glob from "glob";
|
|
29
29
|
import yargs from "yargs";
|
|
30
30
|
|
|
31
|
-
// bazel-out/
|
|
32
|
-
var Diagnostics = class {
|
|
33
|
-
constructor() {
|
|
34
|
-
this.messages = [];
|
|
35
|
-
}
|
|
36
|
-
get hasErrors() {
|
|
37
|
-
return this.messages.some((m) => m.type === "error");
|
|
38
|
-
}
|
|
39
|
-
add(type, message) {
|
|
40
|
-
if (type !== "ignore") {
|
|
41
|
-
this.messages.push({ type, message });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
warn(message) {
|
|
45
|
-
this.messages.push({ type: "warning", message });
|
|
46
|
-
}
|
|
47
|
-
error(message) {
|
|
48
|
-
this.messages.push({ type: "error", message });
|
|
49
|
-
}
|
|
50
|
-
merge(other) {
|
|
51
|
-
this.messages.push(...other.messages);
|
|
52
|
-
}
|
|
53
|
-
formatDiagnostics(message) {
|
|
54
|
-
const errors = this.messages.filter((d) => d.type === "error").map((d) => " - " + d.message);
|
|
55
|
-
const warnings = this.messages.filter((d) => d.type === "warning").map((d) => " - " + d.message);
|
|
56
|
-
if (errors.length) {
|
|
57
|
-
message += "\nERRORS:\n" + errors.join("\n");
|
|
58
|
-
}
|
|
59
|
-
if (warnings.length) {
|
|
60
|
-
message += "\nWARNINGS:\n" + warnings.join("\n");
|
|
61
|
-
}
|
|
62
|
-
return message;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/output_path.mjs
|
|
31
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/output_path.mjs
|
|
67
32
|
function getOutputPathFn(fs2, outputFolder) {
|
|
68
33
|
const [pre, post] = outputFolder.split("{{LOCALE}}");
|
|
69
34
|
return post === void 0 ? (_locale, relativePath) => fs2.join(pre, relativePath) : (locale, relativePath) => fs2.join(pre + locale + post, relativePath);
|
|
70
35
|
}
|
|
71
36
|
|
|
72
|
-
// bazel-out/
|
|
73
|
-
import { getFileSystem
|
|
37
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/index.mjs
|
|
38
|
+
import { getFileSystem, relativeFrom } from "@angular/compiler-cli/private/localize";
|
|
74
39
|
|
|
75
|
-
// bazel-out/
|
|
40
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/asset_files/asset_translation_handler.mjs
|
|
76
41
|
import { absoluteFrom } from "@angular/compiler-cli/private/localize";
|
|
77
42
|
var AssetTranslationHandler = class {
|
|
78
43
|
constructor(fs2) {
|
|
@@ -100,366 +65,8 @@ var AssetTranslationHandler = class {
|
|
|
100
65
|
}
|
|
101
66
|
};
|
|
102
67
|
|
|
103
|
-
// bazel-out/
|
|
68
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/source_files/source_file_translation_handler.mjs
|
|
104
69
|
import { absoluteFrom as absoluteFrom2 } from "@angular/compiler-cli/private/localize";
|
|
105
|
-
|
|
106
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/babel_core.mjs
|
|
107
|
-
import * as _babelNamespace from "@babel/core";
|
|
108
|
-
import _babelDefault from "@babel/core";
|
|
109
|
-
var _a;
|
|
110
|
-
var babel = (_a = _babelDefault) != null ? _a : _babelNamespace;
|
|
111
|
-
var _typesNamespace = _babelNamespace.types;
|
|
112
|
-
if (_babelDefault !== void 0) {
|
|
113
|
-
_typesNamespace = _babelDefault.types;
|
|
114
|
-
}
|
|
115
|
-
var types = _typesNamespace;
|
|
116
|
-
var NodePath = babel.NodePath;
|
|
117
|
-
var transformSync = babel.transformSync;
|
|
118
|
-
var parseSync = babel.parseSync;
|
|
119
|
-
var transformFromAstSync = babel.transformFromAstSync;
|
|
120
|
-
|
|
121
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/source_files/es2015_translate_plugin.mjs
|
|
122
|
-
import { getFileSystem as getFileSystem2 } from "@angular/compiler-cli/private/localize";
|
|
123
|
-
|
|
124
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/source_file_utils.mjs
|
|
125
|
-
import { getFileSystem } from "@angular/compiler-cli/private/localize";
|
|
126
|
-
import { \u0275isMissingTranslationError, \u0275makeTemplateObject, \u0275translate } from "@angular/localize";
|
|
127
|
-
function isLocalize(expression, localizeName) {
|
|
128
|
-
return isNamedIdentifier(expression, localizeName) && isGlobalIdentifier(expression);
|
|
129
|
-
}
|
|
130
|
-
function isNamedIdentifier(expression, name) {
|
|
131
|
-
return expression.isIdentifier() && expression.node.name === name;
|
|
132
|
-
}
|
|
133
|
-
function isGlobalIdentifier(identifier) {
|
|
134
|
-
return !identifier.scope || !identifier.scope.hasBinding(identifier.node.name);
|
|
135
|
-
}
|
|
136
|
-
function buildLocalizeReplacement(messageParts, substitutions) {
|
|
137
|
-
let mappedString = types.stringLiteral(messageParts[0]);
|
|
138
|
-
for (let i = 1; i < messageParts.length; i++) {
|
|
139
|
-
mappedString = types.binaryExpression("+", mappedString, wrapInParensIfNecessary(substitutions[i - 1]));
|
|
140
|
-
mappedString = types.binaryExpression("+", mappedString, types.stringLiteral(messageParts[i]));
|
|
141
|
-
}
|
|
142
|
-
return mappedString;
|
|
143
|
-
}
|
|
144
|
-
function unwrapMessagePartsFromLocalizeCall(call, fs2 = getFileSystem()) {
|
|
145
|
-
let cooked = call.get("arguments")[0];
|
|
146
|
-
if (cooked === void 0) {
|
|
147
|
-
throw new BabelParseError(call.node, "`$localize` called without any arguments.");
|
|
148
|
-
}
|
|
149
|
-
if (!cooked.isExpression()) {
|
|
150
|
-
throw new BabelParseError(cooked.node, "Unexpected argument to `$localize` (expected an array).");
|
|
151
|
-
}
|
|
152
|
-
let raw = cooked;
|
|
153
|
-
if (cooked.isLogicalExpression() && cooked.node.operator === "||" && cooked.get("left").isIdentifier()) {
|
|
154
|
-
const right = cooked.get("right");
|
|
155
|
-
if (right.isAssignmentExpression()) {
|
|
156
|
-
cooked = right.get("right");
|
|
157
|
-
if (!cooked.isExpression()) {
|
|
158
|
-
throw new BabelParseError(cooked.node, 'Unexpected "makeTemplateObject()" function (expected an expression).');
|
|
159
|
-
}
|
|
160
|
-
} else if (right.isSequenceExpression()) {
|
|
161
|
-
const expressions = right.get("expressions");
|
|
162
|
-
if (expressions.length > 2) {
|
|
163
|
-
const [first, second] = expressions;
|
|
164
|
-
if (first.isAssignmentExpression()) {
|
|
165
|
-
cooked = first.get("right");
|
|
166
|
-
if (!cooked.isExpression()) {
|
|
167
|
-
throw new BabelParseError(first.node, "Unexpected cooked value, expected an expression.");
|
|
168
|
-
}
|
|
169
|
-
if (second.isAssignmentExpression()) {
|
|
170
|
-
raw = second.get("right");
|
|
171
|
-
if (!raw.isExpression()) {
|
|
172
|
-
throw new BabelParseError(second.node, "Unexpected raw value, expected an expression.");
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
raw = cooked;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (cooked.isCallExpression()) {
|
|
182
|
-
let call2 = cooked;
|
|
183
|
-
if (call2.get("arguments").length === 0) {
|
|
184
|
-
call2 = unwrapLazyLoadHelperCall(call2);
|
|
185
|
-
}
|
|
186
|
-
cooked = call2.get("arguments")[0];
|
|
187
|
-
if (!cooked.isExpression()) {
|
|
188
|
-
throw new BabelParseError(cooked.node, 'Unexpected `cooked` argument to the "makeTemplateObject()" function (expected an expression).');
|
|
189
|
-
}
|
|
190
|
-
const arg2 = call2.get("arguments")[1];
|
|
191
|
-
if (arg2 && !arg2.isExpression()) {
|
|
192
|
-
throw new BabelParseError(arg2.node, 'Unexpected `raw` argument to the "makeTemplateObject()" function (expected an expression).');
|
|
193
|
-
}
|
|
194
|
-
raw = arg2 !== void 0 ? arg2 : cooked;
|
|
195
|
-
}
|
|
196
|
-
const [cookedStrings] = unwrapStringLiteralArray(cooked, fs2);
|
|
197
|
-
const [rawStrings, rawLocations] = unwrapStringLiteralArray(raw, fs2);
|
|
198
|
-
return [\u0275makeTemplateObject(cookedStrings, rawStrings), rawLocations];
|
|
199
|
-
}
|
|
200
|
-
function unwrapSubstitutionsFromLocalizeCall(call, fs2 = getFileSystem()) {
|
|
201
|
-
const expressions = call.get("arguments").splice(1);
|
|
202
|
-
if (!isArrayOfExpressions(expressions)) {
|
|
203
|
-
const badExpression = expressions.find((expression) => !expression.isExpression());
|
|
204
|
-
throw new BabelParseError(badExpression.node, "Invalid substitutions for `$localize` (expected all substitution arguments to be expressions).");
|
|
205
|
-
}
|
|
206
|
-
return [
|
|
207
|
-
expressions.map((path) => path.node),
|
|
208
|
-
expressions.map((expression) => getLocation(fs2, expression))
|
|
209
|
-
];
|
|
210
|
-
}
|
|
211
|
-
function unwrapMessagePartsFromTemplateLiteral(elements, fs2 = getFileSystem()) {
|
|
212
|
-
const cooked = elements.map((q) => {
|
|
213
|
-
if (q.node.value.cooked === void 0) {
|
|
214
|
-
throw new BabelParseError(q.node, `Unexpected undefined message part in "${elements.map((q2) => q2.node.value.cooked)}"`);
|
|
215
|
-
}
|
|
216
|
-
return q.node.value.cooked;
|
|
217
|
-
});
|
|
218
|
-
const raw = elements.map((q) => q.node.value.raw);
|
|
219
|
-
const locations = elements.map((q) => getLocation(fs2, q));
|
|
220
|
-
return [\u0275makeTemplateObject(cooked, raw), locations];
|
|
221
|
-
}
|
|
222
|
-
function wrapInParensIfNecessary(expression) {
|
|
223
|
-
if (types.isBinaryExpression(expression)) {
|
|
224
|
-
return types.parenthesizedExpression(expression);
|
|
225
|
-
} else {
|
|
226
|
-
return expression;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function unwrapStringLiteralArray(array, fs2 = getFileSystem()) {
|
|
230
|
-
if (!isStringLiteralArray(array.node)) {
|
|
231
|
-
throw new BabelParseError(array.node, "Unexpected messageParts for `$localize` (expected an array of strings).");
|
|
232
|
-
}
|
|
233
|
-
const elements = array.get("elements");
|
|
234
|
-
return [elements.map((str) => str.node.value), elements.map((str) => getLocation(fs2, str))];
|
|
235
|
-
}
|
|
236
|
-
function unwrapLazyLoadHelperCall(call) {
|
|
237
|
-
const callee = call.get("callee");
|
|
238
|
-
if (!callee.isIdentifier()) {
|
|
239
|
-
throw new BabelParseError(callee.node, "Unexpected lazy-load helper call (expected a call of the form `_templateObject()`).");
|
|
240
|
-
}
|
|
241
|
-
const lazyLoadBinding = call.scope.getBinding(callee.node.name);
|
|
242
|
-
if (!lazyLoadBinding) {
|
|
243
|
-
throw new BabelParseError(callee.node, "Missing declaration for lazy-load helper function");
|
|
244
|
-
}
|
|
245
|
-
const lazyLoadFn = lazyLoadBinding.path;
|
|
246
|
-
if (!lazyLoadFn.isFunctionDeclaration()) {
|
|
247
|
-
throw new BabelParseError(lazyLoadFn.node, "Unexpected expression (expected a function declaration");
|
|
248
|
-
}
|
|
249
|
-
const returnedNode = getReturnedExpression(lazyLoadFn);
|
|
250
|
-
if (returnedNode.isCallExpression()) {
|
|
251
|
-
return returnedNode;
|
|
252
|
-
}
|
|
253
|
-
if (returnedNode.isIdentifier()) {
|
|
254
|
-
const identifierName = returnedNode.node.name;
|
|
255
|
-
const declaration = returnedNode.scope.getBinding(identifierName);
|
|
256
|
-
if (declaration === void 0) {
|
|
257
|
-
throw new BabelParseError(returnedNode.node, "Missing declaration for return value from helper.");
|
|
258
|
-
}
|
|
259
|
-
if (!declaration.path.isVariableDeclarator()) {
|
|
260
|
-
throw new BabelParseError(declaration.path.node, "Unexpected helper return value declaration (expected a variable declaration).");
|
|
261
|
-
}
|
|
262
|
-
const initializer = declaration.path.get("init");
|
|
263
|
-
if (!initializer.isCallExpression()) {
|
|
264
|
-
throw new BabelParseError(declaration.path.node, "Unexpected return value from helper (expected a call expression).");
|
|
265
|
-
}
|
|
266
|
-
if (lazyLoadBinding.references === 1) {
|
|
267
|
-
lazyLoadFn.remove();
|
|
268
|
-
}
|
|
269
|
-
return initializer;
|
|
270
|
-
}
|
|
271
|
-
return call;
|
|
272
|
-
}
|
|
273
|
-
function getReturnedExpression(fn) {
|
|
274
|
-
const bodyStatements = fn.get("body").get("body");
|
|
275
|
-
for (const statement of bodyStatements) {
|
|
276
|
-
if (statement.isReturnStatement()) {
|
|
277
|
-
const argument = statement.get("argument");
|
|
278
|
-
if (argument.isSequenceExpression()) {
|
|
279
|
-
const expressions = argument.get("expressions");
|
|
280
|
-
return Array.isArray(expressions) ? expressions[expressions.length - 1] : expressions;
|
|
281
|
-
} else if (argument.isExpression()) {
|
|
282
|
-
return argument;
|
|
283
|
-
} else {
|
|
284
|
-
throw new BabelParseError(statement.node, "Invalid return argument in helper function (expected an expression).");
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
throw new BabelParseError(fn.node, "Missing return statement in helper function.");
|
|
289
|
-
}
|
|
290
|
-
function isStringLiteralArray(node) {
|
|
291
|
-
return types.isArrayExpression(node) && node.elements.every((element) => types.isStringLiteral(element));
|
|
292
|
-
}
|
|
293
|
-
function isArrayOfExpressions(paths) {
|
|
294
|
-
return paths.every((element) => element.isExpression());
|
|
295
|
-
}
|
|
296
|
-
function translate(diagnostics2, translations, messageParts, substitutions, missingTranslation2) {
|
|
297
|
-
try {
|
|
298
|
-
return \u0275translate(translations, messageParts, substitutions);
|
|
299
|
-
} catch (e) {
|
|
300
|
-
if (\u0275isMissingTranslationError(e)) {
|
|
301
|
-
diagnostics2.add(missingTranslation2, e.message);
|
|
302
|
-
return [
|
|
303
|
-
\u0275makeTemplateObject(e.parsedMessage.messageParts, e.parsedMessage.messageParts),
|
|
304
|
-
substitutions
|
|
305
|
-
];
|
|
306
|
-
} else {
|
|
307
|
-
diagnostics2.error(e.message);
|
|
308
|
-
return [messageParts, substitutions];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
var BabelParseError = class extends Error {
|
|
313
|
-
constructor(node, message) {
|
|
314
|
-
super(message);
|
|
315
|
-
this.node = node;
|
|
316
|
-
this.type = "BabelParseError";
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
function isBabelParseError(e) {
|
|
320
|
-
return e.type === "BabelParseError";
|
|
321
|
-
}
|
|
322
|
-
function buildCodeFrameError(fs2, path, e) {
|
|
323
|
-
let filename = path.hub.file.opts.filename;
|
|
324
|
-
if (filename) {
|
|
325
|
-
filename = fs2.resolve(filename);
|
|
326
|
-
let cwd = path.hub.file.opts.cwd;
|
|
327
|
-
if (cwd) {
|
|
328
|
-
cwd = fs2.resolve(cwd);
|
|
329
|
-
filename = fs2.relative(cwd, filename);
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
filename = "(unknown file)";
|
|
333
|
-
}
|
|
334
|
-
const message = path.hub.file.buildCodeFrameError(e.node, e.message).message;
|
|
335
|
-
return `${filename}: ${message}`;
|
|
336
|
-
}
|
|
337
|
-
function getLocation(fs2, startPath, endPath) {
|
|
338
|
-
const startLocation = startPath.node.loc;
|
|
339
|
-
const file = getFileFromPath(fs2, startPath);
|
|
340
|
-
if (!startLocation || !file) {
|
|
341
|
-
return void 0;
|
|
342
|
-
}
|
|
343
|
-
const endLocation = endPath && getFileFromPath(fs2, endPath) === file && endPath.node.loc || startLocation;
|
|
344
|
-
return {
|
|
345
|
-
start: getLineAndColumn(startLocation.start),
|
|
346
|
-
end: getLineAndColumn(endLocation.end),
|
|
347
|
-
file,
|
|
348
|
-
text: getText(startPath)
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
function getFileFromPath(fs2, path) {
|
|
352
|
-
var _a2;
|
|
353
|
-
const opts = path == null ? void 0 : path.hub.file.opts;
|
|
354
|
-
const filename = opts == null ? void 0 : opts.filename;
|
|
355
|
-
if (!filename) {
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
const relativePath = fs2.relative(opts.cwd, filename);
|
|
359
|
-
const root = (_a2 = opts.generatorOpts.sourceRoot) != null ? _a2 : opts.cwd;
|
|
360
|
-
const absPath = fs2.resolve(root, relativePath);
|
|
361
|
-
return absPath;
|
|
362
|
-
}
|
|
363
|
-
function getLineAndColumn(loc) {
|
|
364
|
-
return { line: loc.line - 1, column: loc.column };
|
|
365
|
-
}
|
|
366
|
-
function getText(path) {
|
|
367
|
-
if (path.node.start === null || path.node.end === null) {
|
|
368
|
-
return void 0;
|
|
369
|
-
}
|
|
370
|
-
return path.hub.file.code.substring(path.node.start, path.node.end);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/source_files/es2015_translate_plugin.mjs
|
|
374
|
-
function makeEs2015TranslatePlugin(diagnostics2, translations, { missingTranslation: missingTranslation2 = "error", localizeName = "$localize" } = {}, fs2 = getFileSystem2()) {
|
|
375
|
-
return {
|
|
376
|
-
visitor: {
|
|
377
|
-
TaggedTemplateExpression(path) {
|
|
378
|
-
try {
|
|
379
|
-
const tag = path.get("tag");
|
|
380
|
-
if (isLocalize(tag, localizeName)) {
|
|
381
|
-
const [messageParts] = unwrapMessagePartsFromTemplateLiteral(path.get("quasi").get("quasis"), fs2);
|
|
382
|
-
const translated = translate(diagnostics2, translations, messageParts, path.node.quasi.expressions, missingTranslation2);
|
|
383
|
-
path.replaceWith(buildLocalizeReplacement(translated[0], translated[1]));
|
|
384
|
-
}
|
|
385
|
-
} catch (e) {
|
|
386
|
-
if (isBabelParseError(e)) {
|
|
387
|
-
throw buildCodeFrameError(fs2, path, e);
|
|
388
|
-
} else {
|
|
389
|
-
throw e;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/source_files/es5_translate_plugin.mjs
|
|
398
|
-
import { getFileSystem as getFileSystem3 } from "@angular/compiler-cli/private/localize";
|
|
399
|
-
function makeEs5TranslatePlugin(diagnostics2, translations, { missingTranslation: missingTranslation2 = "error", localizeName = "$localize" } = {}, fs2 = getFileSystem3()) {
|
|
400
|
-
return {
|
|
401
|
-
visitor: {
|
|
402
|
-
CallExpression(callPath) {
|
|
403
|
-
try {
|
|
404
|
-
const calleePath = callPath.get("callee");
|
|
405
|
-
if (isLocalize(calleePath, localizeName)) {
|
|
406
|
-
const [messageParts] = unwrapMessagePartsFromLocalizeCall(callPath, fs2);
|
|
407
|
-
const [expressions] = unwrapSubstitutionsFromLocalizeCall(callPath, fs2);
|
|
408
|
-
const translated = translate(diagnostics2, translations, messageParts, expressions, missingTranslation2);
|
|
409
|
-
callPath.replaceWith(buildLocalizeReplacement(translated[0], translated[1]));
|
|
410
|
-
}
|
|
411
|
-
} catch (e) {
|
|
412
|
-
if (isBabelParseError(e)) {
|
|
413
|
-
diagnostics2.error(buildCodeFrameError(fs2, callPath, e));
|
|
414
|
-
} else {
|
|
415
|
-
throw e;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/source_files/locale_plugin.mjs
|
|
424
|
-
function makeLocalePlugin(locale, { localizeName = "$localize" } = {}) {
|
|
425
|
-
return {
|
|
426
|
-
visitor: {
|
|
427
|
-
MemberExpression(expression) {
|
|
428
|
-
const obj = expression.get("object");
|
|
429
|
-
if (!isLocalize(obj, localizeName)) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
const property = expression.get("property");
|
|
433
|
-
if (!property.isIdentifier({ name: "locale" })) {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (expression.parentPath.isAssignmentExpression() && expression.parentPath.get("left") === expression) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
const parent = expression.parentPath;
|
|
440
|
-
if (parent.isLogicalExpression({ operator: "&&" }) && parent.get("right") === expression) {
|
|
441
|
-
const left = parent.get("left");
|
|
442
|
-
if (isLocalizeGuard(left, localizeName)) {
|
|
443
|
-
parent.replaceWith(expression);
|
|
444
|
-
} else if (left.isLogicalExpression({ operator: "&&" }) && isLocalizeGuard(left.get("right"), localizeName)) {
|
|
445
|
-
left.replaceWith(left.get("left"));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
expression.replaceWith(types.stringLiteral(locale));
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
function isLocalizeGuard(expression, localizeName) {
|
|
454
|
-
if (!expression.isBinaryExpression() || !(expression.node.operator === "!==" || expression.node.operator === "!=")) {
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
const left = expression.get("left");
|
|
458
|
-
const right = expression.get("right");
|
|
459
|
-
return left.isUnaryExpression({ operator: "typeof" }) && isLocalize(left.get("argument"), localizeName) && right.isStringLiteral({ value: "undefined" }) || right.isUnaryExpression({ operator: "typeof" }) && isLocalize(right.get("argument"), localizeName) && left.isStringLiteral({ value: "undefined" });
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/source_files/source_file_translation_handler.mjs
|
|
463
70
|
var SourceFileTranslationHandler = class {
|
|
464
71
|
constructor(fs2, translationOptions = {}) {
|
|
465
72
|
this.fs = fs2;
|
|
@@ -525,7 +132,7 @@ var SourceFileTranslationHandler = class {
|
|
|
525
132
|
}
|
|
526
133
|
};
|
|
527
134
|
|
|
528
|
-
// bazel-out/
|
|
135
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_loader.mjs
|
|
529
136
|
var TranslationLoader = class {
|
|
530
137
|
constructor(fs2, translationParsers, duplicateTranslation2, diagnostics2) {
|
|
531
138
|
this.fs = fs2;
|
|
@@ -583,9 +190,9 @@ ${parser.constructor.name} cannot parse translation file.`));
|
|
|
583
190
|
}
|
|
584
191
|
}
|
|
585
192
|
Object.keys(nextBundle.translations).forEach((messageId) => {
|
|
586
|
-
var
|
|
193
|
+
var _a;
|
|
587
194
|
if (bundle.translations[messageId] !== void 0) {
|
|
588
|
-
(
|
|
195
|
+
(_a = this.diagnostics) == null ? void 0 : _a.add(this.duplicateTranslation, `Duplicate translations for message "${messageId}" when merging "${filePaths[i]}".`);
|
|
589
196
|
} else {
|
|
590
197
|
bundle.translations[messageId] = nextBundle.translations[messageId];
|
|
591
198
|
}
|
|
@@ -595,628 +202,7 @@ ${parser.constructor.name} cannot parse translation file.`));
|
|
|
595
202
|
}
|
|
596
203
|
};
|
|
597
204
|
|
|
598
|
-
// bazel-out/
|
|
599
|
-
import { \u0275parseTranslation } from "@angular/localize";
|
|
600
|
-
var ArbTranslationParser = class {
|
|
601
|
-
canParse(filePath, contents) {
|
|
602
|
-
const result = this.analyze(filePath, contents);
|
|
603
|
-
return result.canParse && result.hint;
|
|
604
|
-
}
|
|
605
|
-
analyze(_filePath, contents) {
|
|
606
|
-
const diagnostics2 = new Diagnostics();
|
|
607
|
-
if (!contents.includes('"@@locale"')) {
|
|
608
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
609
|
-
}
|
|
610
|
-
try {
|
|
611
|
-
return { canParse: true, diagnostics: diagnostics2, hint: this.tryParseArbFormat(contents) };
|
|
612
|
-
} catch {
|
|
613
|
-
diagnostics2.warn("File is not valid JSON.");
|
|
614
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
parse(_filePath, contents, arb = this.tryParseArbFormat(contents)) {
|
|
618
|
-
const bundle = {
|
|
619
|
-
locale: arb["@@locale"],
|
|
620
|
-
translations: {},
|
|
621
|
-
diagnostics: new Diagnostics()
|
|
622
|
-
};
|
|
623
|
-
for (const messageId of Object.keys(arb)) {
|
|
624
|
-
if (messageId.startsWith("@")) {
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
const targetMessage = arb[messageId];
|
|
628
|
-
bundle.translations[messageId] = \u0275parseTranslation(targetMessage);
|
|
629
|
-
}
|
|
630
|
-
return bundle;
|
|
631
|
-
}
|
|
632
|
-
tryParseArbFormat(contents) {
|
|
633
|
-
const json = JSON.parse(contents);
|
|
634
|
-
if (typeof json["@@locale"] !== "string") {
|
|
635
|
-
throw new Error("Missing @@locale property.");
|
|
636
|
-
}
|
|
637
|
-
return json;
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.mjs
|
|
642
|
-
import { \u0275parseTranslation as \u0275parseTranslation2 } from "@angular/localize";
|
|
643
|
-
import { extname } from "path";
|
|
644
|
-
var SimpleJsonTranslationParser = class {
|
|
645
|
-
canParse(filePath, contents) {
|
|
646
|
-
const result = this.analyze(filePath, contents);
|
|
647
|
-
return result.canParse && result.hint;
|
|
648
|
-
}
|
|
649
|
-
analyze(filePath, contents) {
|
|
650
|
-
const diagnostics2 = new Diagnostics();
|
|
651
|
-
if (extname(filePath) !== ".json" || !(contents.includes('"locale"') && contents.includes('"translations"'))) {
|
|
652
|
-
diagnostics2.warn("File does not have .json extension.");
|
|
653
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
654
|
-
}
|
|
655
|
-
try {
|
|
656
|
-
const json = JSON.parse(contents);
|
|
657
|
-
if (json.locale === void 0) {
|
|
658
|
-
diagnostics2.warn('Required "locale" property missing.');
|
|
659
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
660
|
-
}
|
|
661
|
-
if (typeof json.locale !== "string") {
|
|
662
|
-
diagnostics2.warn('The "locale" property is not a string.');
|
|
663
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
664
|
-
}
|
|
665
|
-
if (json.translations === void 0) {
|
|
666
|
-
diagnostics2.warn('Required "translations" property missing.');
|
|
667
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
668
|
-
}
|
|
669
|
-
if (typeof json.translations !== "object") {
|
|
670
|
-
diagnostics2.warn('The "translations" is not an object.');
|
|
671
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
672
|
-
}
|
|
673
|
-
return { canParse: true, diagnostics: diagnostics2, hint: json };
|
|
674
|
-
} catch (e) {
|
|
675
|
-
diagnostics2.warn("File is not valid JSON.");
|
|
676
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
parse(_filePath, contents, json) {
|
|
680
|
-
const { locale: parsedLocale, translations } = json || JSON.parse(contents);
|
|
681
|
-
const parsedTranslations = {};
|
|
682
|
-
for (const messageId in translations) {
|
|
683
|
-
const targetMessage = translations[messageId];
|
|
684
|
-
parsedTranslations[messageId] = \u0275parseTranslation2(targetMessage);
|
|
685
|
-
}
|
|
686
|
-
return { locale: parsedLocale, translations: parsedTranslations, diagnostics: new Diagnostics() };
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.mjs
|
|
691
|
-
import { ParseErrorLevel as ParseErrorLevel3, visitAll as visitAll2 } from "@angular/compiler";
|
|
692
|
-
|
|
693
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/base_visitor.mjs
|
|
694
|
-
var BaseVisitor = class {
|
|
695
|
-
visitElement(_element, _context) {
|
|
696
|
-
}
|
|
697
|
-
visitAttribute(_attribute, _context) {
|
|
698
|
-
}
|
|
699
|
-
visitText(_text, _context) {
|
|
700
|
-
}
|
|
701
|
-
visitComment(_comment, _context) {
|
|
702
|
-
}
|
|
703
|
-
visitExpansion(_expansion, _context) {
|
|
704
|
-
}
|
|
705
|
-
visitExpansionCase(_expansionCase, _context) {
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/message_serializer.mjs
|
|
710
|
-
import { Element as Element2, visitAll } from "@angular/compiler";
|
|
711
|
-
|
|
712
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/translation_parse_error.mjs
|
|
713
|
-
import { ParseErrorLevel } from "@angular/compiler";
|
|
714
|
-
var TranslationParseError = class extends Error {
|
|
715
|
-
constructor(span, msg, level = ParseErrorLevel.ERROR) {
|
|
716
|
-
super(contextualMessage(span, msg, level));
|
|
717
|
-
this.span = span;
|
|
718
|
-
this.msg = msg;
|
|
719
|
-
this.level = level;
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
function contextualMessage(span, msg, level) {
|
|
723
|
-
const ctx = span.start.getContext(100, 2);
|
|
724
|
-
msg += `
|
|
725
|
-
At ${span.start}${span.details ? `, ${span.details}` : ""}:
|
|
726
|
-
`;
|
|
727
|
-
if (ctx) {
|
|
728
|
-
msg += `...${ctx.before}[${ParseErrorLevel[level]} ->]${ctx.after}...
|
|
729
|
-
`;
|
|
730
|
-
}
|
|
731
|
-
return msg;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/translation_utils.mjs
|
|
735
|
-
import { Element, ParseError, ParseErrorLevel as ParseErrorLevel2, XmlParser } from "@angular/compiler";
|
|
736
|
-
function getAttrOrThrow(element, attrName) {
|
|
737
|
-
const attrValue = getAttribute(element, attrName);
|
|
738
|
-
if (attrValue === void 0) {
|
|
739
|
-
throw new TranslationParseError(element.sourceSpan, `Missing required "${attrName}" attribute:`);
|
|
740
|
-
}
|
|
741
|
-
return attrValue;
|
|
742
|
-
}
|
|
743
|
-
function getAttribute(element, attrName) {
|
|
744
|
-
const attr = element.attrs.find((a) => a.name === attrName);
|
|
745
|
-
return attr !== void 0 ? attr.value : void 0;
|
|
746
|
-
}
|
|
747
|
-
function parseInnerRange(element) {
|
|
748
|
-
const xmlParser = new XmlParser();
|
|
749
|
-
const xml = xmlParser.parse(element.sourceSpan.start.file.content, element.sourceSpan.start.file.url, { tokenizeExpansionForms: true, range: getInnerRange(element) });
|
|
750
|
-
return xml;
|
|
751
|
-
}
|
|
752
|
-
function getInnerRange(element) {
|
|
753
|
-
const start = element.startSourceSpan.end;
|
|
754
|
-
const end = element.endSourceSpan.start;
|
|
755
|
-
return {
|
|
756
|
-
startPos: start.offset,
|
|
757
|
-
startLine: start.line,
|
|
758
|
-
startCol: start.col,
|
|
759
|
-
endPos: end.offset
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
function canParseXml(filePath, contents, rootNodeName, attributes) {
|
|
763
|
-
const diagnostics2 = new Diagnostics();
|
|
764
|
-
const xmlParser = new XmlParser();
|
|
765
|
-
const xml = xmlParser.parse(contents, filePath);
|
|
766
|
-
if (xml.rootNodes.length === 0 || xml.errors.some((error) => error.level === ParseErrorLevel2.ERROR)) {
|
|
767
|
-
xml.errors.forEach((e) => addParseError(diagnostics2, e));
|
|
768
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
769
|
-
}
|
|
770
|
-
const rootElements = xml.rootNodes.filter(isNamedElement(rootNodeName));
|
|
771
|
-
const rootElement = rootElements[0];
|
|
772
|
-
if (rootElement === void 0) {
|
|
773
|
-
diagnostics2.warn(`The XML file does not contain a <${rootNodeName}> root node.`);
|
|
774
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
775
|
-
}
|
|
776
|
-
for (const attrKey of Object.keys(attributes)) {
|
|
777
|
-
const attr = rootElement.attrs.find((attr2) => attr2.name === attrKey);
|
|
778
|
-
if (attr === void 0 || attr.value !== attributes[attrKey]) {
|
|
779
|
-
addParseDiagnostic(diagnostics2, rootElement.sourceSpan, `The <${rootNodeName}> node does not have the required attribute: ${attrKey}="${attributes[attrKey]}".`, ParseErrorLevel2.WARNING);
|
|
780
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (rootElements.length > 1) {
|
|
784
|
-
xml.errors.push(new ParseError(xml.rootNodes[1].sourceSpan, "Unexpected root node. XLIFF 1.2 files should only have a single <xliff> root node.", ParseErrorLevel2.WARNING));
|
|
785
|
-
}
|
|
786
|
-
return { canParse: true, diagnostics: diagnostics2, hint: { element: rootElement, errors: xml.errors } };
|
|
787
|
-
}
|
|
788
|
-
function isNamedElement(name) {
|
|
789
|
-
function predicate(node) {
|
|
790
|
-
return node instanceof Element && node.name === name;
|
|
791
|
-
}
|
|
792
|
-
return predicate;
|
|
793
|
-
}
|
|
794
|
-
function addParseDiagnostic(diagnostics2, sourceSpan, message, level) {
|
|
795
|
-
addParseError(diagnostics2, new ParseError(sourceSpan, message, level));
|
|
796
|
-
}
|
|
797
|
-
function addParseError(diagnostics2, parseError) {
|
|
798
|
-
if (parseError.level === ParseErrorLevel2.ERROR) {
|
|
799
|
-
diagnostics2.error(parseError.toString());
|
|
800
|
-
} else {
|
|
801
|
-
diagnostics2.warn(parseError.toString());
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
function addErrorsToBundle(bundle, errors) {
|
|
805
|
-
for (const error of errors) {
|
|
806
|
-
addParseError(bundle.diagnostics, error);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/message_serializer.mjs
|
|
811
|
-
var MessageSerializer = class extends BaseVisitor {
|
|
812
|
-
constructor(renderer, config) {
|
|
813
|
-
super();
|
|
814
|
-
this.renderer = renderer;
|
|
815
|
-
this.config = config;
|
|
816
|
-
}
|
|
817
|
-
serialize(nodes) {
|
|
818
|
-
this.renderer.startRender();
|
|
819
|
-
visitAll(this, nodes);
|
|
820
|
-
this.renderer.endRender();
|
|
821
|
-
return this.renderer.message;
|
|
822
|
-
}
|
|
823
|
-
visitElement(element) {
|
|
824
|
-
if (this.config.placeholder && element.name === this.config.placeholder.elementName) {
|
|
825
|
-
const name = getAttrOrThrow(element, this.config.placeholder.nameAttribute);
|
|
826
|
-
const body = this.config.placeholder.bodyAttribute && getAttribute(element, this.config.placeholder.bodyAttribute);
|
|
827
|
-
this.visitPlaceholder(name, body);
|
|
828
|
-
} else if (this.config.placeholderContainer && element.name === this.config.placeholderContainer.elementName) {
|
|
829
|
-
const start = getAttrOrThrow(element, this.config.placeholderContainer.startAttribute);
|
|
830
|
-
const end = getAttrOrThrow(element, this.config.placeholderContainer.endAttribute);
|
|
831
|
-
this.visitPlaceholderContainer(start, element.children, end);
|
|
832
|
-
} else if (this.config.inlineElements.indexOf(element.name) !== -1) {
|
|
833
|
-
visitAll(this, element.children);
|
|
834
|
-
} else {
|
|
835
|
-
throw new TranslationParseError(element.sourceSpan, `Invalid element found in message.`);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
visitText(text) {
|
|
839
|
-
this.renderer.text(text.value);
|
|
840
|
-
}
|
|
841
|
-
visitExpansion(expansion) {
|
|
842
|
-
this.renderer.startIcu();
|
|
843
|
-
this.renderer.text(`${expansion.switchValue}, ${expansion.type},`);
|
|
844
|
-
visitAll(this, expansion.cases);
|
|
845
|
-
this.renderer.endIcu();
|
|
846
|
-
}
|
|
847
|
-
visitExpansionCase(expansionCase) {
|
|
848
|
-
this.renderer.text(` ${expansionCase.value} {`);
|
|
849
|
-
this.renderer.startContainer();
|
|
850
|
-
visitAll(this, expansionCase.expression);
|
|
851
|
-
this.renderer.closeContainer();
|
|
852
|
-
this.renderer.text(`}`);
|
|
853
|
-
}
|
|
854
|
-
visitContainedNodes(nodes) {
|
|
855
|
-
this.renderer.startContainer();
|
|
856
|
-
visitAll(this, nodes);
|
|
857
|
-
this.renderer.closeContainer();
|
|
858
|
-
}
|
|
859
|
-
visitPlaceholder(name, body) {
|
|
860
|
-
this.renderer.placeholder(name, body);
|
|
861
|
-
}
|
|
862
|
-
visitPlaceholderContainer(startName, children, closeName) {
|
|
863
|
-
this.renderer.startPlaceholder(startName);
|
|
864
|
-
this.visitContainedNodes(children);
|
|
865
|
-
this.renderer.closePlaceholder(closeName);
|
|
866
|
-
}
|
|
867
|
-
isPlaceholderContainer(node) {
|
|
868
|
-
return node instanceof Element2 && node.name === this.config.placeholderContainer.elementName;
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/target_message_renderer.mjs
|
|
873
|
-
import { \u0275makeParsedTranslation } from "@angular/localize";
|
|
874
|
-
var TargetMessageRenderer = class {
|
|
875
|
-
constructor() {
|
|
876
|
-
this.current = { messageParts: [], placeholderNames: [], text: "" };
|
|
877
|
-
this.icuDepth = 0;
|
|
878
|
-
}
|
|
879
|
-
get message() {
|
|
880
|
-
const { messageParts, placeholderNames } = this.current;
|
|
881
|
-
return \u0275makeParsedTranslation(messageParts, placeholderNames);
|
|
882
|
-
}
|
|
883
|
-
startRender() {
|
|
884
|
-
}
|
|
885
|
-
endRender() {
|
|
886
|
-
this.storeMessagePart();
|
|
887
|
-
}
|
|
888
|
-
text(text) {
|
|
889
|
-
this.current.text += text;
|
|
890
|
-
}
|
|
891
|
-
placeholder(name, body) {
|
|
892
|
-
this.renderPlaceholder(name);
|
|
893
|
-
}
|
|
894
|
-
startPlaceholder(name) {
|
|
895
|
-
this.renderPlaceholder(name);
|
|
896
|
-
}
|
|
897
|
-
closePlaceholder(name) {
|
|
898
|
-
this.renderPlaceholder(name);
|
|
899
|
-
}
|
|
900
|
-
startContainer() {
|
|
901
|
-
}
|
|
902
|
-
closeContainer() {
|
|
903
|
-
}
|
|
904
|
-
startIcu() {
|
|
905
|
-
this.icuDepth++;
|
|
906
|
-
this.text("{");
|
|
907
|
-
}
|
|
908
|
-
endIcu() {
|
|
909
|
-
this.icuDepth--;
|
|
910
|
-
this.text("}");
|
|
911
|
-
}
|
|
912
|
-
normalizePlaceholderName(name) {
|
|
913
|
-
return name.replace(/-/g, "_");
|
|
914
|
-
}
|
|
915
|
-
renderPlaceholder(name) {
|
|
916
|
-
name = this.normalizePlaceholderName(name);
|
|
917
|
-
if (this.icuDepth > 0) {
|
|
918
|
-
this.text(`{${name}}`);
|
|
919
|
-
} else {
|
|
920
|
-
this.storeMessagePart();
|
|
921
|
-
this.current.placeholderNames.push(name);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
storeMessagePart() {
|
|
925
|
-
this.current.messageParts.push(this.current.text);
|
|
926
|
-
this.current.text = "";
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/serialize_translation_message.mjs
|
|
931
|
-
function serializeTranslationMessage(element, config) {
|
|
932
|
-
const { rootNodes, errors: parseErrors } = parseInnerRange(element);
|
|
933
|
-
try {
|
|
934
|
-
const serializer = new MessageSerializer(new TargetMessageRenderer(), config);
|
|
935
|
-
const translation = serializer.serialize(rootNodes);
|
|
936
|
-
return { translation, parseErrors, serializeErrors: [] };
|
|
937
|
-
} catch (e) {
|
|
938
|
-
return { translation: null, parseErrors, serializeErrors: [e] };
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.mjs
|
|
943
|
-
var Xliff1TranslationParser = class {
|
|
944
|
-
canParse(filePath, contents) {
|
|
945
|
-
const result = this.analyze(filePath, contents);
|
|
946
|
-
return result.canParse && result.hint;
|
|
947
|
-
}
|
|
948
|
-
analyze(filePath, contents) {
|
|
949
|
-
return canParseXml(filePath, contents, "xliff", { version: "1.2" });
|
|
950
|
-
}
|
|
951
|
-
parse(filePath, contents, hint) {
|
|
952
|
-
if (hint) {
|
|
953
|
-
return this.extractBundle(hint);
|
|
954
|
-
} else {
|
|
955
|
-
return this.extractBundleDeprecated(filePath, contents);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
extractBundle({ element, errors }) {
|
|
959
|
-
const diagnostics2 = new Diagnostics();
|
|
960
|
-
errors.forEach((e) => addParseError(diagnostics2, e));
|
|
961
|
-
if (element.children.length === 0) {
|
|
962
|
-
addParseDiagnostic(diagnostics2, element.sourceSpan, "Missing expected <file> element", ParseErrorLevel3.WARNING);
|
|
963
|
-
return { locale: void 0, translations: {}, diagnostics: diagnostics2 };
|
|
964
|
-
}
|
|
965
|
-
const files = element.children.filter(isNamedElement("file"));
|
|
966
|
-
if (files.length === 0) {
|
|
967
|
-
addParseDiagnostic(diagnostics2, element.sourceSpan, "No <file> elements found in <xliff>", ParseErrorLevel3.WARNING);
|
|
968
|
-
} else if (files.length > 1) {
|
|
969
|
-
addParseDiagnostic(diagnostics2, files[1].sourceSpan, "More than one <file> element found in <xliff>", ParseErrorLevel3.WARNING);
|
|
970
|
-
}
|
|
971
|
-
const bundle = { locale: void 0, translations: {}, diagnostics: diagnostics2 };
|
|
972
|
-
const translationVisitor = new XliffTranslationVisitor();
|
|
973
|
-
const localesFound = new Set();
|
|
974
|
-
for (const file of files) {
|
|
975
|
-
const locale = getAttribute(file, "target-language");
|
|
976
|
-
if (locale !== void 0) {
|
|
977
|
-
localesFound.add(locale);
|
|
978
|
-
bundle.locale = locale;
|
|
979
|
-
}
|
|
980
|
-
visitAll2(translationVisitor, file.children, bundle);
|
|
981
|
-
}
|
|
982
|
-
if (localesFound.size > 1) {
|
|
983
|
-
addParseDiagnostic(diagnostics2, element.sourceSpan, `More than one locale found in translation file: ${JSON.stringify(Array.from(localesFound))}. Using "${bundle.locale}"`, ParseErrorLevel3.WARNING);
|
|
984
|
-
}
|
|
985
|
-
return bundle;
|
|
986
|
-
}
|
|
987
|
-
extractBundleDeprecated(filePath, contents) {
|
|
988
|
-
const hint = this.canParse(filePath, contents);
|
|
989
|
-
if (!hint) {
|
|
990
|
-
throw new Error(`Unable to parse "${filePath}" as XLIFF 1.2 format.`);
|
|
991
|
-
}
|
|
992
|
-
const bundle = this.extractBundle(hint);
|
|
993
|
-
if (bundle.diagnostics.hasErrors) {
|
|
994
|
-
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XLIFF 1.2 format`);
|
|
995
|
-
throw new Error(message);
|
|
996
|
-
}
|
|
997
|
-
return bundle;
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
var XliffTranslationVisitor = class extends BaseVisitor {
|
|
1001
|
-
visitElement(element, bundle) {
|
|
1002
|
-
if (element.name === "trans-unit") {
|
|
1003
|
-
this.visitTransUnitElement(element, bundle);
|
|
1004
|
-
} else {
|
|
1005
|
-
visitAll2(this, element.children, bundle);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
visitTransUnitElement(element, bundle) {
|
|
1009
|
-
const id = getAttribute(element, "id");
|
|
1010
|
-
if (id === void 0) {
|
|
1011
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <trans-unit> element.`, ParseErrorLevel3.ERROR);
|
|
1012
|
-
return;
|
|
1013
|
-
}
|
|
1014
|
-
if (bundle.translations[id] !== void 0) {
|
|
1015
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${id}"`, ParseErrorLevel3.ERROR);
|
|
1016
|
-
return;
|
|
1017
|
-
}
|
|
1018
|
-
let targetMessage = element.children.find(isNamedElement("target"));
|
|
1019
|
-
if (targetMessage === void 0) {
|
|
1020
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing <target> element", ParseErrorLevel3.WARNING);
|
|
1021
|
-
targetMessage = element.children.find(isNamedElement("source"));
|
|
1022
|
-
if (targetMessage === void 0) {
|
|
1023
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing required element: one of <target> or <source> is required", ParseErrorLevel3.ERROR);
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(targetMessage, {
|
|
1028
|
-
inlineElements: ["g", "bx", "ex", "bpt", "ept", "ph", "it", "mrk"],
|
|
1029
|
-
placeholder: { elementName: "x", nameAttribute: "id" }
|
|
1030
|
-
});
|
|
1031
|
-
if (translation !== null) {
|
|
1032
|
-
bundle.translations[id] = translation;
|
|
1033
|
-
}
|
|
1034
|
-
addErrorsToBundle(bundle, parseErrors);
|
|
1035
|
-
addErrorsToBundle(bundle, serializeErrors);
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
|
|
1039
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser.mjs
|
|
1040
|
-
import { Element as Element3, ParseErrorLevel as ParseErrorLevel4, visitAll as visitAll3 } from "@angular/compiler";
|
|
1041
|
-
var Xliff2TranslationParser = class {
|
|
1042
|
-
canParse(filePath, contents) {
|
|
1043
|
-
const result = this.analyze(filePath, contents);
|
|
1044
|
-
return result.canParse && result.hint;
|
|
1045
|
-
}
|
|
1046
|
-
analyze(filePath, contents) {
|
|
1047
|
-
return canParseXml(filePath, contents, "xliff", { version: "2.0" });
|
|
1048
|
-
}
|
|
1049
|
-
parse(filePath, contents, hint) {
|
|
1050
|
-
if (hint) {
|
|
1051
|
-
return this.extractBundle(hint);
|
|
1052
|
-
} else {
|
|
1053
|
-
return this.extractBundleDeprecated(filePath, contents);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
extractBundle({ element, errors }) {
|
|
1057
|
-
const diagnostics2 = new Diagnostics();
|
|
1058
|
-
errors.forEach((e) => addParseError(diagnostics2, e));
|
|
1059
|
-
const locale = getAttribute(element, "trgLang");
|
|
1060
|
-
const files = element.children.filter(isFileElement);
|
|
1061
|
-
if (files.length === 0) {
|
|
1062
|
-
addParseDiagnostic(diagnostics2, element.sourceSpan, "No <file> elements found in <xliff>", ParseErrorLevel4.WARNING);
|
|
1063
|
-
} else if (files.length > 1) {
|
|
1064
|
-
addParseDiagnostic(diagnostics2, files[1].sourceSpan, "More than one <file> element found in <xliff>", ParseErrorLevel4.WARNING);
|
|
1065
|
-
}
|
|
1066
|
-
const bundle = { locale, translations: {}, diagnostics: diagnostics2 };
|
|
1067
|
-
const translationVisitor = new Xliff2TranslationVisitor();
|
|
1068
|
-
for (const file of files) {
|
|
1069
|
-
visitAll3(translationVisitor, file.children, { bundle });
|
|
1070
|
-
}
|
|
1071
|
-
return bundle;
|
|
1072
|
-
}
|
|
1073
|
-
extractBundleDeprecated(filePath, contents) {
|
|
1074
|
-
const hint = this.canParse(filePath, contents);
|
|
1075
|
-
if (!hint) {
|
|
1076
|
-
throw new Error(`Unable to parse "${filePath}" as XLIFF 2.0 format.`);
|
|
1077
|
-
}
|
|
1078
|
-
const bundle = this.extractBundle(hint);
|
|
1079
|
-
if (bundle.diagnostics.hasErrors) {
|
|
1080
|
-
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XLIFF 2.0 format`);
|
|
1081
|
-
throw new Error(message);
|
|
1082
|
-
}
|
|
1083
|
-
return bundle;
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
var Xliff2TranslationVisitor = class extends BaseVisitor {
|
|
1087
|
-
visitElement(element, { bundle, unit }) {
|
|
1088
|
-
if (element.name === "unit") {
|
|
1089
|
-
this.visitUnitElement(element, bundle);
|
|
1090
|
-
} else if (element.name === "segment") {
|
|
1091
|
-
this.visitSegmentElement(element, bundle, unit);
|
|
1092
|
-
} else {
|
|
1093
|
-
visitAll3(this, element.children, { bundle, unit });
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
visitUnitElement(element, bundle) {
|
|
1097
|
-
const externalId = getAttribute(element, "id");
|
|
1098
|
-
if (externalId === void 0) {
|
|
1099
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <trans-unit> element.`, ParseErrorLevel4.ERROR);
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
if (bundle.translations[externalId] !== void 0) {
|
|
1103
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${externalId}"`, ParseErrorLevel4.ERROR);
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
visitAll3(this, element.children, { bundle, unit: externalId });
|
|
1107
|
-
}
|
|
1108
|
-
visitSegmentElement(element, bundle, unit) {
|
|
1109
|
-
if (unit === void 0) {
|
|
1110
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Invalid <segment> element: should be a child of a <unit> element.", ParseErrorLevel4.ERROR);
|
|
1111
|
-
return;
|
|
1112
|
-
}
|
|
1113
|
-
let targetMessage = element.children.find(isNamedElement("target"));
|
|
1114
|
-
if (targetMessage === void 0) {
|
|
1115
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing <target> element", ParseErrorLevel4.WARNING);
|
|
1116
|
-
targetMessage = element.children.find(isNamedElement("source"));
|
|
1117
|
-
if (targetMessage === void 0) {
|
|
1118
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing required element: one of <target> or <source> is required", ParseErrorLevel4.ERROR);
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(targetMessage, {
|
|
1123
|
-
inlineElements: ["cp", "sc", "ec", "mrk", "sm", "em"],
|
|
1124
|
-
placeholder: { elementName: "ph", nameAttribute: "equiv", bodyAttribute: "disp" },
|
|
1125
|
-
placeholderContainer: { elementName: "pc", startAttribute: "equivStart", endAttribute: "equivEnd" }
|
|
1126
|
-
});
|
|
1127
|
-
if (translation !== null) {
|
|
1128
|
-
bundle.translations[unit] = translation;
|
|
1129
|
-
}
|
|
1130
|
-
addErrorsToBundle(bundle, parseErrors);
|
|
1131
|
-
addErrorsToBundle(bundle, serializeErrors);
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
function isFileElement(node) {
|
|
1135
|
-
return node instanceof Element3 && node.name === "file";
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser.mjs
|
|
1139
|
-
import { ParseErrorLevel as ParseErrorLevel5, visitAll as visitAll4 } from "@angular/compiler";
|
|
1140
|
-
import { extname as extname2 } from "path";
|
|
1141
|
-
var XtbTranslationParser = class {
|
|
1142
|
-
canParse(filePath, contents) {
|
|
1143
|
-
const result = this.analyze(filePath, contents);
|
|
1144
|
-
return result.canParse && result.hint;
|
|
1145
|
-
}
|
|
1146
|
-
analyze(filePath, contents) {
|
|
1147
|
-
const extension = extname2(filePath);
|
|
1148
|
-
if (extension !== ".xtb" && extension !== ".xmb") {
|
|
1149
|
-
const diagnostics2 = new Diagnostics();
|
|
1150
|
-
diagnostics2.warn("Must have xtb or xmb extension.");
|
|
1151
|
-
return { canParse: false, diagnostics: diagnostics2 };
|
|
1152
|
-
}
|
|
1153
|
-
return canParseXml(filePath, contents, "translationbundle", {});
|
|
1154
|
-
}
|
|
1155
|
-
parse(filePath, contents, hint) {
|
|
1156
|
-
if (hint) {
|
|
1157
|
-
return this.extractBundle(hint);
|
|
1158
|
-
} else {
|
|
1159
|
-
return this.extractBundleDeprecated(filePath, contents);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
extractBundle({ element, errors }) {
|
|
1163
|
-
const langAttr = element.attrs.find((attr) => attr.name === "lang");
|
|
1164
|
-
const bundle = {
|
|
1165
|
-
locale: langAttr && langAttr.value,
|
|
1166
|
-
translations: {},
|
|
1167
|
-
diagnostics: new Diagnostics()
|
|
1168
|
-
};
|
|
1169
|
-
errors.forEach((e) => addParseError(bundle.diagnostics, e));
|
|
1170
|
-
const bundleVisitor = new XtbVisitor();
|
|
1171
|
-
visitAll4(bundleVisitor, element.children, bundle);
|
|
1172
|
-
return bundle;
|
|
1173
|
-
}
|
|
1174
|
-
extractBundleDeprecated(filePath, contents) {
|
|
1175
|
-
const hint = this.canParse(filePath, contents);
|
|
1176
|
-
if (!hint) {
|
|
1177
|
-
throw new Error(`Unable to parse "${filePath}" as XMB/XTB format.`);
|
|
1178
|
-
}
|
|
1179
|
-
const bundle = this.extractBundle(hint);
|
|
1180
|
-
if (bundle.diagnostics.hasErrors) {
|
|
1181
|
-
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XMB/XTB format`);
|
|
1182
|
-
throw new Error(message);
|
|
1183
|
-
}
|
|
1184
|
-
return bundle;
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
var XtbVisitor = class extends BaseVisitor {
|
|
1188
|
-
visitElement(element, bundle) {
|
|
1189
|
-
switch (element.name) {
|
|
1190
|
-
case "translation":
|
|
1191
|
-
const id = getAttribute(element, "id");
|
|
1192
|
-
if (id === void 0) {
|
|
1193
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <translation> element.`, ParseErrorLevel5.ERROR);
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
if (bundle.translations[id] !== void 0) {
|
|
1197
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${id}"`, ParseErrorLevel5.ERROR);
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(element, { inlineElements: [], placeholder: { elementName: "ph", nameAttribute: "name" } });
|
|
1201
|
-
if (parseErrors.length) {
|
|
1202
|
-
bundle.diagnostics.warn(computeParseWarning(id, parseErrors));
|
|
1203
|
-
} else if (translation !== null) {
|
|
1204
|
-
bundle.translations[id] = translation;
|
|
1205
|
-
}
|
|
1206
|
-
addErrorsToBundle(bundle, serializeErrors);
|
|
1207
|
-
break;
|
|
1208
|
-
default:
|
|
1209
|
-
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Unexpected <${element.name}> tag.`, ParseErrorLevel5.ERROR);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
function computeParseWarning(id, errors) {
|
|
1214
|
-
const msg = errors.map((e) => e.toString()).join("\n");
|
|
1215
|
-
return `Could not parse message with id "${id}" - perhaps it has an unrecognised ICU format?
|
|
1216
|
-
` + msg;
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
// bazel-out/k8-fastbuild/bin/packages/localize/tools/src/translate/translator.mjs
|
|
205
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translator.mjs
|
|
1220
206
|
var Translator = class {
|
|
1221
207
|
constructor(fs2, resourceHandlers, diagnostics2) {
|
|
1222
208
|
this.fs = fs2;
|
|
@@ -1238,9 +224,9 @@ var Translator = class {
|
|
|
1238
224
|
}
|
|
1239
225
|
};
|
|
1240
226
|
|
|
1241
|
-
// bazel-out/
|
|
227
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/index.mjs
|
|
1242
228
|
function translateFiles({ sourceRootPath: sourceRootPath2, sourceFilePaths: sourceFilePaths2, translationFilePaths: translationFilePaths2, translationFileLocales: translationFileLocales2, outputPathFn: outputPathFn2, diagnostics: diagnostics2, missingTranslation: missingTranslation2, duplicateTranslation: duplicateTranslation2, sourceLocale: sourceLocale2 }) {
|
|
1243
|
-
const fs2 =
|
|
229
|
+
const fs2 = getFileSystem();
|
|
1244
230
|
const translationLoader = new TranslationLoader(fs2, [
|
|
1245
231
|
new Xliff2TranslationParser(),
|
|
1246
232
|
new Xliff1TranslationParser(),
|
|
@@ -1258,7 +244,7 @@ function translateFiles({ sourceRootPath: sourceRootPath2, sourceFilePaths: sour
|
|
|
1258
244
|
resourceProcessor.translateFiles(sourceFilePaths2.map(relativeFrom), fs2.resolve(sourceRootPath2), outputPathFn2, translations, sourceLocale2);
|
|
1259
245
|
}
|
|
1260
246
|
|
|
1261
|
-
// bazel-out/
|
|
247
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/cli.mjs
|
|
1262
248
|
process.title = "Angular Localization Message Translator (localize-translate)";
|
|
1263
249
|
var args = process.argv.slice(2);
|
|
1264
250
|
var options = yargs(args).option("r", {
|