@angular/localize 13.0.0-next.9 → 13.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- package/esm2020/init/index.mjs +12 -0
- package/{esm2015/localize.js → esm2020/localize.mjs} +0 -0
- package/{esm2015/private.js → esm2020/private.mjs} +0 -0
- package/{esm2015/src/localize/index.js → esm2020/src/localize/index.mjs} +0 -0
- package/{esm2015/src/localize/src/global.js → esm2020/src/localize/src/global.mjs} +0 -0
- package/{esm2015/src/localize/src/localize.js → esm2020/src/localize/src/localize.mjs} +2 -2
- package/{esm2015/src/translate.js → esm2020/src/translate.mjs} +0 -0
- package/{esm2015/src/utils/index.js → esm2020/src/utils/index.mjs} +0 -0
- package/{esm2015/src/utils/src/constants.js → esm2020/src/utils/src/constants.mjs} +0 -0
- package/esm2020/src/utils/src/messages.mjs +159 -0
- package/{esm2015/src/utils/src/translations.js → esm2020/src/utils/src/translations.mjs} +0 -0
- package/fesm2015/{init.js → init.mjs} +3 -3
- package/fesm2015/init.mjs.map +1 -0
- package/fesm2015/{localize.js → localize.mjs} +7 -7
- package/fesm2015/localize.mjs.map +1 -0
- package/fesm2020/init.mjs +204 -0
- package/fesm2020/init.mjs.map +1 -0
- package/fesm2020/localize.mjs +449 -0
- package/fesm2020/localize.mjs.map +1 -0
- package/init/index.d.ts +1 -1
- package/init/package.json +5 -5
- package/package.json +43 -18
- package/schematics/ng-add/index.js +1 -1
- package/src/localize/src/localize.d.ts +1 -1
- package/src/utils/src/messages.d.ts +1 -1
- package/tools/README.md +4 -0
- package/tools/bundles/index.js +1929 -0
- package/tools/bundles/index.js.map +6 -0
- package/tools/bundles/src/extract/cli.js +1278 -0
- package/tools/bundles/src/extract/cli.js.map +6 -0
- package/tools/bundles/src/migrate/cli.js +77 -0
- package/tools/bundles/src/migrate/cli.js.map +6 -0
- package/tools/bundles/src/translate/cli.js +1340 -0
- package/tools/bundles/src/translate/cli.js.map +6 -0
- package/tools/bundles_metadata.json +1 -0
- package/tools/index.d.ts +26 -0
- package/tools/src/babel_core.d.ts +38 -0
- package/{src/tools → tools}/src/diagnostics.d.ts +1 -1
- package/tools/src/extract/cli.d.ts +10 -0
- package/{src/tools → tools}/src/extract/duplicates.d.ts +2 -2
- package/{src/tools → tools}/src/extract/extraction.d.ts +2 -3
- package/{src/tools/src/extract/main.d.ts → tools/src/extract/index.d.ts} +2 -4
- package/{src/tools → tools}/src/extract/source_files/es2015_extract_plugin.d.ts +3 -3
- package/{src/tools → tools}/src/extract/source_files/es5_extract_plugin.d.ts +3 -3
- package/{src/tools → tools}/src/extract/translation_files/arb_translation_serializer.d.ts +2 -2
- package/{src/tools → tools}/src/extract/translation_files/format_options.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/icu_parsing.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/json_translation_serializer.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/legacy_message_id_migration_serializer.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/translation_serializer.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/utils.d.ts +1 -1
- package/{src/tools → tools}/src/extract/translation_files/xliff1_translation_serializer.d.ts +2 -2
- package/{src/tools → tools}/src/extract/translation_files/xliff2_translation_serializer.d.ts +2 -2
- package/{src/tools → tools}/src/extract/translation_files/xmb_translation_serializer.d.ts +2 -2
- package/{src/tools → tools}/src/extract/translation_files/xml_file.d.ts +1 -1
- package/tools/src/migrate/cli.d.ts +10 -0
- package/{src/tools/src/migrate/main.d.ts → tools/src/migrate/index.d.ts} +9 -3
- package/{src/tools → tools}/src/migrate/migrate.d.ts +1 -1
- package/{src/tools → tools}/src/source_file_utils.d.ts +3 -3
- package/{src/tools → tools}/src/translate/asset_files/asset_translation_handler.d.ts +2 -2
- package/tools/src/translate/cli.d.ts +3 -0
- package/{src/tools/src/translate/main.d.ts → tools/src/translate/index.d.ts} +1 -2
- package/{src/tools → tools}/src/translate/output_path.d.ts +2 -2
- package/{src/tools → tools}/src/translate/source_files/es2015_translate_plugin.d.ts +3 -3
- package/{src/tools → tools}/src/translate/source_files/es5_translate_plugin.d.ts +3 -3
- package/{src/tools → tools}/src/translate/source_files/locale_plugin.d.ts +2 -2
- package/{src/tools → tools}/src/translate/source_files/source_file_translation_handler.d.ts +2 -2
- package/{src/tools → tools}/src/translate/translation_files/base_visitor.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/message_serialization/message_renderer.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/message_serialization/message_serializer.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/message_serialization/target_message_renderer.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_loader.d.ts +2 -2
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/arb_translation_parser.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/serialize_translation_message.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/simple_json_translation_parser.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_parse_error.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_parser.d.ts +2 -2
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/translation_utils.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xliff1_translation_parser.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xliff2_translation_parser.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translation_files/translation_parsers/xtb_translation_parser.d.ts +1 -1
- package/{src/tools → tools}/src/translate/translator.d.ts +2 -2
- package/bundles/localize-init.umd.js +0 -218
- package/bundles/localize-init.umd.js.map +0 -1
- package/bundles/localize.umd.js +0 -782
- package/bundles/localize.umd.js.map +0 -1
- package/esm2015/init/index.js +0 -12
- package/esm2015/init/init.externs.js +0 -0
- package/esm2015/localize.externs.js +0 -0
- package/esm2015/src/localize/localize.externs.js +0 -0
- package/esm2015/src/utils/src/messages.js +0 -159
- package/esm2015/src/utils/utils.externs.js +0 -0
- package/fesm2015/init.js.map +0 -1
- package/fesm2015/localize.js.map +0 -1
- package/init.d.ts +0 -7
- package/src/tools/src/diagnostics.js +0 -68
- package/src/tools/src/extract/duplicates.js +0 -84
- package/src/tools/src/extract/extraction.js +0 -134
- package/src/tools/src/extract/main.js +0 -184
- package/src/tools/src/extract/source_files/es2015_extract_plugin.js +0 -36
- package/src/tools/src/extract/source_files/es5_extract_plugin.js +0 -49
- package/src/tools/src/extract/translation_files/arb_translation_serializer.js +0 -107
- package/src/tools/src/extract/translation_files/format_options.js +0 -52
- package/src/tools/src/extract/translation_files/icu_parsing.js +0 -224
- package/src/tools/src/extract/translation_files/json_translation_serializer.js +0 -47
- package/src/tools/src/extract/translation_files/legacy_message_id_migration_serializer.js +0 -63
- package/src/tools/src/extract/translation_files/translation_serializer.js +0 -13
- package/src/tools/src/extract/translation_files/utils.js +0 -102
- package/src/tools/src/extract/translation_files/xliff1_translation_serializer.js +0 -242
- package/src/tools/src/extract/translation_files/xliff2_translation_serializer.js +0 -231
- package/src/tools/src/extract/translation_files/xmb_translation_serializer.js +0 -139
- package/src/tools/src/extract/translation_files/xml_file.js +0 -117
- package/src/tools/src/migrate/main.js +0 -79
- package/src/tools/src/migrate/migrate.js +0 -48
- package/src/tools/src/source_file_utils.js +0 -443
- package/src/tools/src/translate/asset_files/asset_translation_handler.js +0 -65
- package/src/tools/src/translate/main.js +0 -157
- package/src/tools/src/translate/output_path.js +0 -28
- package/src/tools/src/translate/source_files/es2015_translate_plugin.js +0 -60
- package/src/tools/src/translate/source_files/es5_translate_plugin.js +0 -58
- package/src/tools/src/translate/source_files/locale_plugin.js +0 -95
- package/src/tools/src/translate/source_files/source_file_translation_handler.js +0 -127
- package/src/tools/src/translate/translation_files/base_visitor.js +0 -31
- package/src/tools/src/translate/translation_files/message_serialization/message_renderer.js +0 -20
- package/src/tools/src/translate/translation_files/message_serialization/message_serializer.js +0 -100
- package/src/tools/src/translate/translation_files/message_serialization/target_message_renderer.js +0 -84
- package/src/tools/src/translate/translation_files/translation_loader.js +0 -148
- package/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.js +0 -111
- package/src/tools/src/translate/translation_files/translation_parsers/serialize_translation_message.js +0 -32
- package/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.js +0 -96
- package/src/tools/src/translate/translation_files/translation_parsers/translation_parse_error.js +0 -47
- package/src/tools/src/translate/translation_files/translation_parsers/translation_parser.js +0 -13
- package/src/tools/src/translate/translation_files/translation_parsers/translation_utils.js +0 -175
- package/src/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.js +0 -175
- package/src/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser.js +0 -166
- package/src/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser.js +0 -133
- package/src/tools/src/translate/translator.js +0 -53
|
@@ -0,0 +1,1929 @@
|
|
|
1
|
+
|
|
2
|
+
import {createRequire as __cjsCompatRequire} from 'module';
|
|
3
|
+
const require = __cjsCompatRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/index.mjs
|
|
23
|
+
import { NodeJSFileSystem, setFileSystem } from "@angular/compiler-cli/private/localize";
|
|
24
|
+
|
|
25
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/diagnostics.mjs
|
|
26
|
+
var Diagnostics = class {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.messages = [];
|
|
29
|
+
}
|
|
30
|
+
get hasErrors() {
|
|
31
|
+
return this.messages.some((m) => m.type === "error");
|
|
32
|
+
}
|
|
33
|
+
add(type, message) {
|
|
34
|
+
if (type !== "ignore") {
|
|
35
|
+
this.messages.push({ type, message });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
warn(message) {
|
|
39
|
+
this.messages.push({ type: "warning", message });
|
|
40
|
+
}
|
|
41
|
+
error(message) {
|
|
42
|
+
this.messages.push({ type: "error", message });
|
|
43
|
+
}
|
|
44
|
+
merge(other) {
|
|
45
|
+
this.messages.push(...other.messages);
|
|
46
|
+
}
|
|
47
|
+
formatDiagnostics(message) {
|
|
48
|
+
const errors = this.messages.filter((d) => d.type === "error").map((d) => " - " + d.message);
|
|
49
|
+
const warnings = this.messages.filter((d) => d.type === "warning").map((d) => " - " + d.message);
|
|
50
|
+
if (errors.length) {
|
|
51
|
+
message += "\nERRORS:\n" + errors.join("\n");
|
|
52
|
+
}
|
|
53
|
+
if (warnings.length) {
|
|
54
|
+
message += "\nWARNINGS:\n" + warnings.join("\n");
|
|
55
|
+
}
|
|
56
|
+
return message;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/source_file_utils.mjs
|
|
61
|
+
import { getFileSystem } from "@angular/compiler-cli/private/localize";
|
|
62
|
+
import { \u0275isMissingTranslationError, \u0275makeTemplateObject, \u0275translate } from "@angular/localize";
|
|
63
|
+
|
|
64
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/babel_core.mjs
|
|
65
|
+
import * as _babelNamespace from "@babel/core";
|
|
66
|
+
import _babelDefault from "@babel/core";
|
|
67
|
+
var _a;
|
|
68
|
+
var babel = (_a = _babelDefault) != null ? _a : _babelNamespace;
|
|
69
|
+
var _typesNamespace = _babelNamespace.types;
|
|
70
|
+
if (_babelDefault !== void 0) {
|
|
71
|
+
_typesNamespace = _babelDefault.types;
|
|
72
|
+
}
|
|
73
|
+
var types = _typesNamespace;
|
|
74
|
+
var NodePath = babel.NodePath;
|
|
75
|
+
var transformSync = babel.transformSync;
|
|
76
|
+
var parseSync = babel.parseSync;
|
|
77
|
+
var transformFromAstSync = babel.transformFromAstSync;
|
|
78
|
+
|
|
79
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/source_file_utils.mjs
|
|
80
|
+
function isLocalize(expression, localizeName) {
|
|
81
|
+
return isNamedIdentifier(expression, localizeName) && isGlobalIdentifier(expression);
|
|
82
|
+
}
|
|
83
|
+
function isNamedIdentifier(expression, name) {
|
|
84
|
+
return expression.isIdentifier() && expression.node.name === name;
|
|
85
|
+
}
|
|
86
|
+
function isGlobalIdentifier(identifier) {
|
|
87
|
+
return !identifier.scope || !identifier.scope.hasBinding(identifier.node.name);
|
|
88
|
+
}
|
|
89
|
+
function buildLocalizeReplacement(messageParts, substitutions) {
|
|
90
|
+
let mappedString = types.stringLiteral(messageParts[0]);
|
|
91
|
+
for (let i = 1; i < messageParts.length; i++) {
|
|
92
|
+
mappedString = types.binaryExpression("+", mappedString, wrapInParensIfNecessary(substitutions[i - 1]));
|
|
93
|
+
mappedString = types.binaryExpression("+", mappedString, types.stringLiteral(messageParts[i]));
|
|
94
|
+
}
|
|
95
|
+
return mappedString;
|
|
96
|
+
}
|
|
97
|
+
function unwrapMessagePartsFromLocalizeCall(call, fs = getFileSystem()) {
|
|
98
|
+
let cooked = call.get("arguments")[0];
|
|
99
|
+
if (cooked === void 0) {
|
|
100
|
+
throw new BabelParseError(call.node, "`$localize` called without any arguments.");
|
|
101
|
+
}
|
|
102
|
+
if (!cooked.isExpression()) {
|
|
103
|
+
throw new BabelParseError(cooked.node, "Unexpected argument to `$localize` (expected an array).");
|
|
104
|
+
}
|
|
105
|
+
let raw = cooked;
|
|
106
|
+
if (cooked.isLogicalExpression() && cooked.node.operator === "||" && cooked.get("left").isIdentifier()) {
|
|
107
|
+
const right = cooked.get("right");
|
|
108
|
+
if (right.isAssignmentExpression()) {
|
|
109
|
+
cooked = right.get("right");
|
|
110
|
+
if (!cooked.isExpression()) {
|
|
111
|
+
throw new BabelParseError(cooked.node, 'Unexpected "makeTemplateObject()" function (expected an expression).');
|
|
112
|
+
}
|
|
113
|
+
} else if (right.isSequenceExpression()) {
|
|
114
|
+
const expressions = right.get("expressions");
|
|
115
|
+
if (expressions.length > 2) {
|
|
116
|
+
const [first, second] = expressions;
|
|
117
|
+
if (first.isAssignmentExpression()) {
|
|
118
|
+
cooked = first.get("right");
|
|
119
|
+
if (!cooked.isExpression()) {
|
|
120
|
+
throw new BabelParseError(first.node, "Unexpected cooked value, expected an expression.");
|
|
121
|
+
}
|
|
122
|
+
if (second.isAssignmentExpression()) {
|
|
123
|
+
raw = second.get("right");
|
|
124
|
+
if (!raw.isExpression()) {
|
|
125
|
+
throw new BabelParseError(second.node, "Unexpected raw value, expected an expression.");
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
raw = cooked;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (cooked.isCallExpression()) {
|
|
135
|
+
let call2 = cooked;
|
|
136
|
+
if (call2.get("arguments").length === 0) {
|
|
137
|
+
call2 = unwrapLazyLoadHelperCall(call2);
|
|
138
|
+
}
|
|
139
|
+
cooked = call2.get("arguments")[0];
|
|
140
|
+
if (!cooked.isExpression()) {
|
|
141
|
+
throw new BabelParseError(cooked.node, 'Unexpected `cooked` argument to the "makeTemplateObject()" function (expected an expression).');
|
|
142
|
+
}
|
|
143
|
+
const arg2 = call2.get("arguments")[1];
|
|
144
|
+
if (arg2 && !arg2.isExpression()) {
|
|
145
|
+
throw new BabelParseError(arg2.node, 'Unexpected `raw` argument to the "makeTemplateObject()" function (expected an expression).');
|
|
146
|
+
}
|
|
147
|
+
raw = arg2 !== void 0 ? arg2 : cooked;
|
|
148
|
+
}
|
|
149
|
+
const [cookedStrings] = unwrapStringLiteralArray(cooked, fs);
|
|
150
|
+
const [rawStrings, rawLocations] = unwrapStringLiteralArray(raw, fs);
|
|
151
|
+
return [\u0275makeTemplateObject(cookedStrings, rawStrings), rawLocations];
|
|
152
|
+
}
|
|
153
|
+
function unwrapSubstitutionsFromLocalizeCall(call, fs = getFileSystem()) {
|
|
154
|
+
const expressions = call.get("arguments").splice(1);
|
|
155
|
+
if (!isArrayOfExpressions(expressions)) {
|
|
156
|
+
const badExpression = expressions.find((expression) => !expression.isExpression());
|
|
157
|
+
throw new BabelParseError(badExpression.node, "Invalid substitutions for `$localize` (expected all substitution arguments to be expressions).");
|
|
158
|
+
}
|
|
159
|
+
return [
|
|
160
|
+
expressions.map((path) => path.node),
|
|
161
|
+
expressions.map((expression) => getLocation(fs, expression))
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
function unwrapMessagePartsFromTemplateLiteral(elements, fs = getFileSystem()) {
|
|
165
|
+
const cooked = elements.map((q) => {
|
|
166
|
+
if (q.node.value.cooked === void 0) {
|
|
167
|
+
throw new BabelParseError(q.node, `Unexpected undefined message part in "${elements.map((q2) => q2.node.value.cooked)}"`);
|
|
168
|
+
}
|
|
169
|
+
return q.node.value.cooked;
|
|
170
|
+
});
|
|
171
|
+
const raw = elements.map((q) => q.node.value.raw);
|
|
172
|
+
const locations = elements.map((q) => getLocation(fs, q));
|
|
173
|
+
return [\u0275makeTemplateObject(cooked, raw), locations];
|
|
174
|
+
}
|
|
175
|
+
function unwrapExpressionsFromTemplateLiteral(quasi, fs = getFileSystem()) {
|
|
176
|
+
return [quasi.node.expressions, quasi.get("expressions").map((e) => getLocation(fs, e))];
|
|
177
|
+
}
|
|
178
|
+
function wrapInParensIfNecessary(expression) {
|
|
179
|
+
if (types.isBinaryExpression(expression)) {
|
|
180
|
+
return types.parenthesizedExpression(expression);
|
|
181
|
+
} else {
|
|
182
|
+
return expression;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function unwrapStringLiteralArray(array, fs = getFileSystem()) {
|
|
186
|
+
if (!isStringLiteralArray(array.node)) {
|
|
187
|
+
throw new BabelParseError(array.node, "Unexpected messageParts for `$localize` (expected an array of strings).");
|
|
188
|
+
}
|
|
189
|
+
const elements = array.get("elements");
|
|
190
|
+
return [elements.map((str) => str.node.value), elements.map((str) => getLocation(fs, str))];
|
|
191
|
+
}
|
|
192
|
+
function unwrapLazyLoadHelperCall(call) {
|
|
193
|
+
const callee = call.get("callee");
|
|
194
|
+
if (!callee.isIdentifier()) {
|
|
195
|
+
throw new BabelParseError(callee.node, "Unexpected lazy-load helper call (expected a call of the form `_templateObject()`).");
|
|
196
|
+
}
|
|
197
|
+
const lazyLoadBinding = call.scope.getBinding(callee.node.name);
|
|
198
|
+
if (!lazyLoadBinding) {
|
|
199
|
+
throw new BabelParseError(callee.node, "Missing declaration for lazy-load helper function");
|
|
200
|
+
}
|
|
201
|
+
const lazyLoadFn = lazyLoadBinding.path;
|
|
202
|
+
if (!lazyLoadFn.isFunctionDeclaration()) {
|
|
203
|
+
throw new BabelParseError(lazyLoadFn.node, "Unexpected expression (expected a function declaration");
|
|
204
|
+
}
|
|
205
|
+
const returnedNode = getReturnedExpression(lazyLoadFn);
|
|
206
|
+
if (returnedNode.isCallExpression()) {
|
|
207
|
+
return returnedNode;
|
|
208
|
+
}
|
|
209
|
+
if (returnedNode.isIdentifier()) {
|
|
210
|
+
const identifierName = returnedNode.node.name;
|
|
211
|
+
const declaration = returnedNode.scope.getBinding(identifierName);
|
|
212
|
+
if (declaration === void 0) {
|
|
213
|
+
throw new BabelParseError(returnedNode.node, "Missing declaration for return value from helper.");
|
|
214
|
+
}
|
|
215
|
+
if (!declaration.path.isVariableDeclarator()) {
|
|
216
|
+
throw new BabelParseError(declaration.path.node, "Unexpected helper return value declaration (expected a variable declaration).");
|
|
217
|
+
}
|
|
218
|
+
const initializer = declaration.path.get("init");
|
|
219
|
+
if (!initializer.isCallExpression()) {
|
|
220
|
+
throw new BabelParseError(declaration.path.node, "Unexpected return value from helper (expected a call expression).");
|
|
221
|
+
}
|
|
222
|
+
if (lazyLoadBinding.references === 1) {
|
|
223
|
+
lazyLoadFn.remove();
|
|
224
|
+
}
|
|
225
|
+
return initializer;
|
|
226
|
+
}
|
|
227
|
+
return call;
|
|
228
|
+
}
|
|
229
|
+
function getReturnedExpression(fn) {
|
|
230
|
+
const bodyStatements = fn.get("body").get("body");
|
|
231
|
+
for (const statement of bodyStatements) {
|
|
232
|
+
if (statement.isReturnStatement()) {
|
|
233
|
+
const argument = statement.get("argument");
|
|
234
|
+
if (argument.isSequenceExpression()) {
|
|
235
|
+
const expressions = argument.get("expressions");
|
|
236
|
+
return Array.isArray(expressions) ? expressions[expressions.length - 1] : expressions;
|
|
237
|
+
} else if (argument.isExpression()) {
|
|
238
|
+
return argument;
|
|
239
|
+
} else {
|
|
240
|
+
throw new BabelParseError(statement.node, "Invalid return argument in helper function (expected an expression).");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
throw new BabelParseError(fn.node, "Missing return statement in helper function.");
|
|
245
|
+
}
|
|
246
|
+
function isStringLiteralArray(node) {
|
|
247
|
+
return types.isArrayExpression(node) && node.elements.every((element) => types.isStringLiteral(element));
|
|
248
|
+
}
|
|
249
|
+
function isArrayOfExpressions(paths) {
|
|
250
|
+
return paths.every((element) => element.isExpression());
|
|
251
|
+
}
|
|
252
|
+
function translate(diagnostics, translations, messageParts, substitutions, missingTranslation) {
|
|
253
|
+
try {
|
|
254
|
+
return \u0275translate(translations, messageParts, substitutions);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
if (\u0275isMissingTranslationError(e)) {
|
|
257
|
+
diagnostics.add(missingTranslation, e.message);
|
|
258
|
+
return [
|
|
259
|
+
\u0275makeTemplateObject(e.parsedMessage.messageParts, e.parsedMessage.messageParts),
|
|
260
|
+
substitutions
|
|
261
|
+
];
|
|
262
|
+
} else {
|
|
263
|
+
diagnostics.error(e.message);
|
|
264
|
+
return [messageParts, substitutions];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
var BabelParseError = class extends Error {
|
|
269
|
+
constructor(node, message) {
|
|
270
|
+
super(message);
|
|
271
|
+
this.node = node;
|
|
272
|
+
this.type = "BabelParseError";
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
function isBabelParseError(e) {
|
|
276
|
+
return e.type === "BabelParseError";
|
|
277
|
+
}
|
|
278
|
+
function buildCodeFrameError(fs, path, e) {
|
|
279
|
+
let filename = path.hub.file.opts.filename;
|
|
280
|
+
if (filename) {
|
|
281
|
+
filename = fs.resolve(filename);
|
|
282
|
+
let cwd = path.hub.file.opts.cwd;
|
|
283
|
+
if (cwd) {
|
|
284
|
+
cwd = fs.resolve(cwd);
|
|
285
|
+
filename = fs.relative(cwd, filename);
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
filename = "(unknown file)";
|
|
289
|
+
}
|
|
290
|
+
const message = path.hub.file.buildCodeFrameError(e.node, e.message).message;
|
|
291
|
+
return `${filename}: ${message}`;
|
|
292
|
+
}
|
|
293
|
+
function getLocation(fs, startPath, endPath) {
|
|
294
|
+
const startLocation = startPath.node.loc;
|
|
295
|
+
const file = getFileFromPath(fs, startPath);
|
|
296
|
+
if (!startLocation || !file) {
|
|
297
|
+
return void 0;
|
|
298
|
+
}
|
|
299
|
+
const endLocation = endPath && getFileFromPath(fs, endPath) === file && endPath.node.loc || startLocation;
|
|
300
|
+
return {
|
|
301
|
+
start: getLineAndColumn(startLocation.start),
|
|
302
|
+
end: getLineAndColumn(endLocation.end),
|
|
303
|
+
file,
|
|
304
|
+
text: getText(startPath)
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function serializeLocationPosition(location) {
|
|
308
|
+
const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
|
|
309
|
+
return `${location.start.line + 1}${endLineString}`;
|
|
310
|
+
}
|
|
311
|
+
function getFileFromPath(fs, path) {
|
|
312
|
+
var _a2;
|
|
313
|
+
const opts = path == null ? void 0 : path.hub.file.opts;
|
|
314
|
+
const filename = opts == null ? void 0 : opts.filename;
|
|
315
|
+
if (!filename) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const relativePath = fs.relative(opts.cwd, filename);
|
|
319
|
+
const root = (_a2 = opts.generatorOpts.sourceRoot) != null ? _a2 : opts.cwd;
|
|
320
|
+
const absPath = fs.resolve(root, relativePath);
|
|
321
|
+
return absPath;
|
|
322
|
+
}
|
|
323
|
+
function getLineAndColumn(loc) {
|
|
324
|
+
return { line: loc.line - 1, column: loc.column };
|
|
325
|
+
}
|
|
326
|
+
function getText(path) {
|
|
327
|
+
if (path.node.start === null || path.node.end === null) {
|
|
328
|
+
return void 0;
|
|
329
|
+
}
|
|
330
|
+
return path.hub.file.code.substring(path.node.start, path.node.end);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/duplicates.mjs
|
|
334
|
+
function checkDuplicateMessages(fs, messages, duplicateMessageHandling, basePath) {
|
|
335
|
+
const diagnostics = new Diagnostics();
|
|
336
|
+
if (duplicateMessageHandling === "ignore")
|
|
337
|
+
return diagnostics;
|
|
338
|
+
const messageMap = new Map();
|
|
339
|
+
for (const message of messages) {
|
|
340
|
+
if (messageMap.has(message.id)) {
|
|
341
|
+
messageMap.get(message.id).push(message);
|
|
342
|
+
} else {
|
|
343
|
+
messageMap.set(message.id, [message]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
for (const duplicates of messageMap.values()) {
|
|
347
|
+
if (duplicates.length <= 1)
|
|
348
|
+
continue;
|
|
349
|
+
if (duplicates.every((message) => message.text === duplicates[0].text))
|
|
350
|
+
continue;
|
|
351
|
+
const diagnosticMessage = `Duplicate messages with id "${duplicates[0].id}":
|
|
352
|
+
` + duplicates.map((message) => serializeMessage(fs, basePath, message)).join("\n");
|
|
353
|
+
diagnostics.add(duplicateMessageHandling, diagnosticMessage);
|
|
354
|
+
}
|
|
355
|
+
return diagnostics;
|
|
356
|
+
}
|
|
357
|
+
function serializeMessage(fs, basePath, message) {
|
|
358
|
+
if (message.location === void 0) {
|
|
359
|
+
return ` - "${message.text}"`;
|
|
360
|
+
} else {
|
|
361
|
+
const locationFile = fs.relative(basePath, message.location.file);
|
|
362
|
+
const locationPosition = serializeLocationPosition(message.location);
|
|
363
|
+
return ` - "${message.text}" : ${locationFile}:${locationPosition}`;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
|
|
368
|
+
import { SourceFileLoader } from "@angular/compiler-cli/private/localize";
|
|
369
|
+
|
|
370
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es2015_extract_plugin.mjs
|
|
371
|
+
import { \u0275parseMessage } from "@angular/localize";
|
|
372
|
+
function makeEs2015ExtractPlugin(fs, messages, localizeName = "$localize") {
|
|
373
|
+
return {
|
|
374
|
+
visitor: {
|
|
375
|
+
TaggedTemplateExpression(path) {
|
|
376
|
+
const tag = path.get("tag");
|
|
377
|
+
if (isNamedIdentifier(tag, localizeName) && isGlobalIdentifier(tag)) {
|
|
378
|
+
const quasiPath = path.get("quasi");
|
|
379
|
+
const [messageParts, messagePartLocations] = unwrapMessagePartsFromTemplateLiteral(quasiPath.get("quasis"), fs);
|
|
380
|
+
const [expressions, expressionLocations] = unwrapExpressionsFromTemplateLiteral(quasiPath, fs);
|
|
381
|
+
const location = getLocation(fs, quasiPath);
|
|
382
|
+
const message = \u0275parseMessage(messageParts, expressions, location, messagePartLocations, expressionLocations);
|
|
383
|
+
messages.push(message);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/source_files/es5_extract_plugin.mjs
|
|
391
|
+
import { \u0275parseMessage as \u0275parseMessage2 } from "@angular/localize";
|
|
392
|
+
function makeEs5ExtractPlugin(fs, messages, localizeName = "$localize") {
|
|
393
|
+
return {
|
|
394
|
+
visitor: {
|
|
395
|
+
CallExpression(callPath) {
|
|
396
|
+
try {
|
|
397
|
+
const calleePath = callPath.get("callee");
|
|
398
|
+
if (isNamedIdentifier(calleePath, localizeName) && isGlobalIdentifier(calleePath)) {
|
|
399
|
+
const [messageParts, messagePartLocations] = unwrapMessagePartsFromLocalizeCall(callPath, fs);
|
|
400
|
+
const [expressions, expressionLocations] = unwrapSubstitutionsFromLocalizeCall(callPath, fs);
|
|
401
|
+
const [messagePartsArg, expressionsArg] = callPath.get("arguments");
|
|
402
|
+
const location = getLocation(fs, messagePartsArg, expressionsArg);
|
|
403
|
+
const message = \u0275parseMessage2(messageParts, expressions, location, messagePartLocations, expressionLocations);
|
|
404
|
+
messages.push(message);
|
|
405
|
+
}
|
|
406
|
+
} catch (e) {
|
|
407
|
+
if (isBabelParseError(e)) {
|
|
408
|
+
throw buildCodeFrameError(fs, callPath, e);
|
|
409
|
+
} else {
|
|
410
|
+
throw e;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/extraction.mjs
|
|
419
|
+
var MessageExtractor = class {
|
|
420
|
+
constructor(fs, logger, { basePath, useSourceMaps = true, localizeName = "$localize" }) {
|
|
421
|
+
this.fs = fs;
|
|
422
|
+
this.logger = logger;
|
|
423
|
+
this.basePath = basePath;
|
|
424
|
+
this.useSourceMaps = useSourceMaps;
|
|
425
|
+
this.localizeName = localizeName;
|
|
426
|
+
this.loader = new SourceFileLoader(this.fs, this.logger, { webpack: basePath });
|
|
427
|
+
}
|
|
428
|
+
extractMessages(filename) {
|
|
429
|
+
const messages = [];
|
|
430
|
+
const sourceCode = this.fs.readFile(this.fs.resolve(this.basePath, filename));
|
|
431
|
+
if (sourceCode.includes(this.localizeName)) {
|
|
432
|
+
transformSync(sourceCode, {
|
|
433
|
+
sourceRoot: this.basePath,
|
|
434
|
+
filename,
|
|
435
|
+
plugins: [
|
|
436
|
+
makeEs2015ExtractPlugin(this.fs, messages, this.localizeName),
|
|
437
|
+
makeEs5ExtractPlugin(this.fs, messages, this.localizeName)
|
|
438
|
+
],
|
|
439
|
+
code: false,
|
|
440
|
+
ast: false
|
|
441
|
+
});
|
|
442
|
+
if (this.useSourceMaps && messages.length > 0) {
|
|
443
|
+
this.updateSourceLocations(filename, sourceCode, messages);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return messages;
|
|
447
|
+
}
|
|
448
|
+
updateSourceLocations(filename, contents, messages) {
|
|
449
|
+
const sourceFile = this.loader.loadSourceFile(this.fs.resolve(this.basePath, filename), contents);
|
|
450
|
+
if (sourceFile === null) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
for (const message of messages) {
|
|
454
|
+
if (message.location !== void 0) {
|
|
455
|
+
message.location = this.getOriginalLocation(sourceFile, message.location);
|
|
456
|
+
if (message.messagePartLocations) {
|
|
457
|
+
message.messagePartLocations = message.messagePartLocations.map((location) => location && this.getOriginalLocation(sourceFile, location));
|
|
458
|
+
}
|
|
459
|
+
if (message.substitutionLocations) {
|
|
460
|
+
const placeholderNames = Object.keys(message.substitutionLocations);
|
|
461
|
+
for (const placeholderName of placeholderNames) {
|
|
462
|
+
const location = message.substitutionLocations[placeholderName];
|
|
463
|
+
message.substitutionLocations[placeholderName] = location && this.getOriginalLocation(sourceFile, location);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
getOriginalLocation(sourceFile, location) {
|
|
470
|
+
const originalStart = sourceFile.getOriginalLocation(location.start.line, location.start.column);
|
|
471
|
+
if (originalStart === null) {
|
|
472
|
+
return location;
|
|
473
|
+
}
|
|
474
|
+
const originalEnd = sourceFile.getOriginalLocation(location.end.line, location.end.column);
|
|
475
|
+
const start = { line: originalStart.line, column: originalStart.column };
|
|
476
|
+
const end = originalEnd !== null && originalEnd.file === originalStart.file ? { line: originalEnd.line, column: originalEnd.column } : start;
|
|
477
|
+
const originalSourceFile = sourceFile.sources.find((sf) => (sf == null ? void 0 : sf.sourcePath) === originalStart.file);
|
|
478
|
+
const startPos = originalSourceFile.startOfLinePositions[start.line] + start.column;
|
|
479
|
+
const endPos = originalSourceFile.startOfLinePositions[end.line] + end.column;
|
|
480
|
+
const text = originalSourceFile.contents.substring(startPos, endPos).trim();
|
|
481
|
+
return { file: originalStart.file, start, end, text };
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/utils.mjs
|
|
486
|
+
function consolidateMessages(messages, getMessageId2) {
|
|
487
|
+
const messageGroups = new Map();
|
|
488
|
+
for (const message of messages) {
|
|
489
|
+
const id = getMessageId2(message);
|
|
490
|
+
if (!messageGroups.has(id)) {
|
|
491
|
+
messageGroups.set(id, [message]);
|
|
492
|
+
} else {
|
|
493
|
+
messageGroups.get(id).push(message);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
for (const messages2 of messageGroups.values()) {
|
|
497
|
+
messages2.sort(compareLocations);
|
|
498
|
+
}
|
|
499
|
+
return Array.from(messageGroups.values()).sort((a1, a2) => compareLocations(a1[0], a2[0]));
|
|
500
|
+
}
|
|
501
|
+
function hasLocation(message) {
|
|
502
|
+
return message.location !== void 0;
|
|
503
|
+
}
|
|
504
|
+
function compareLocations({ location: location1 }, { location: location2 }) {
|
|
505
|
+
if (location1 === location2) {
|
|
506
|
+
return 0;
|
|
507
|
+
}
|
|
508
|
+
if (location1 === void 0) {
|
|
509
|
+
return -1;
|
|
510
|
+
}
|
|
511
|
+
if (location2 === void 0) {
|
|
512
|
+
return 1;
|
|
513
|
+
}
|
|
514
|
+
if (location1.file !== location2.file) {
|
|
515
|
+
return location1.file < location2.file ? -1 : 1;
|
|
516
|
+
}
|
|
517
|
+
if (location1.start.line !== location2.start.line) {
|
|
518
|
+
return location1.start.line < location2.start.line ? -1 : 1;
|
|
519
|
+
}
|
|
520
|
+
if (location1.start.column !== location2.start.column) {
|
|
521
|
+
return location1.start.column < location2.start.column ? -1 : 1;
|
|
522
|
+
}
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/arb_translation_serializer.mjs
|
|
527
|
+
var ArbTranslationSerializer = class {
|
|
528
|
+
constructor(sourceLocale, basePath, fs) {
|
|
529
|
+
this.sourceLocale = sourceLocale;
|
|
530
|
+
this.basePath = basePath;
|
|
531
|
+
this.fs = fs;
|
|
532
|
+
}
|
|
533
|
+
serialize(messages) {
|
|
534
|
+
const messageGroups = consolidateMessages(messages, (message) => getMessageId(message));
|
|
535
|
+
let output = `{
|
|
536
|
+
"@@locale": ${JSON.stringify(this.sourceLocale)}`;
|
|
537
|
+
for (const duplicateMessages of messageGroups) {
|
|
538
|
+
const message = duplicateMessages[0];
|
|
539
|
+
const id = getMessageId(message);
|
|
540
|
+
output += this.serializeMessage(id, message);
|
|
541
|
+
output += this.serializeMeta(id, message.description, message.meaning, duplicateMessages.filter(hasLocation).map((m) => m.location));
|
|
542
|
+
}
|
|
543
|
+
output += "\n}";
|
|
544
|
+
return output;
|
|
545
|
+
}
|
|
546
|
+
serializeMessage(id, message) {
|
|
547
|
+
return `,
|
|
548
|
+
${JSON.stringify(id)}: ${JSON.stringify(message.text)}`;
|
|
549
|
+
}
|
|
550
|
+
serializeMeta(id, description, meaning, locations) {
|
|
551
|
+
const meta = [];
|
|
552
|
+
if (description) {
|
|
553
|
+
meta.push(`
|
|
554
|
+
"description": ${JSON.stringify(description)}`);
|
|
555
|
+
}
|
|
556
|
+
if (meaning) {
|
|
557
|
+
meta.push(`
|
|
558
|
+
"x-meaning": ${JSON.stringify(meaning)}`);
|
|
559
|
+
}
|
|
560
|
+
if (locations.length > 0) {
|
|
561
|
+
let locationStr = `
|
|
562
|
+
"x-locations": [`;
|
|
563
|
+
for (let i = 0; i < locations.length; i++) {
|
|
564
|
+
locationStr += (i > 0 ? ",\n" : "\n") + this.serializeLocation(locations[i]);
|
|
565
|
+
}
|
|
566
|
+
locationStr += "\n ]";
|
|
567
|
+
meta.push(locationStr);
|
|
568
|
+
}
|
|
569
|
+
return meta.length > 0 ? `,
|
|
570
|
+
${JSON.stringify("@" + id)}: {${meta.join(",")}
|
|
571
|
+
}` : "";
|
|
572
|
+
}
|
|
573
|
+
serializeLocation({ file, start, end }) {
|
|
574
|
+
return [
|
|
575
|
+
` {`,
|
|
576
|
+
` "file": ${JSON.stringify(this.fs.relative(this.basePath, file))},`,
|
|
577
|
+
` "start": { "line": "${start.line}", "column": "${start.column}" },`,
|
|
578
|
+
` "end": { "line": "${end.line}", "column": "${end.column}" }`,
|
|
579
|
+
` }`
|
|
580
|
+
].join("\n");
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
function getMessageId(message) {
|
|
584
|
+
return message.customId || message.id;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/json_translation_serializer.mjs
|
|
588
|
+
var SimpleJsonTranslationSerializer = class {
|
|
589
|
+
constructor(sourceLocale) {
|
|
590
|
+
this.sourceLocale = sourceLocale;
|
|
591
|
+
}
|
|
592
|
+
serialize(messages) {
|
|
593
|
+
const fileObj = { locale: this.sourceLocale, translations: {} };
|
|
594
|
+
for (const [message] of consolidateMessages(messages, (message2) => message2.id)) {
|
|
595
|
+
fileObj.translations[message.id] = message.text;
|
|
596
|
+
}
|
|
597
|
+
return JSON.stringify(fileObj, null, 2);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/legacy_message_id_migration_serializer.mjs
|
|
602
|
+
var LegacyMessageIdMigrationSerializer = class {
|
|
603
|
+
constructor(_diagnostics) {
|
|
604
|
+
this._diagnostics = _diagnostics;
|
|
605
|
+
}
|
|
606
|
+
serialize(messages) {
|
|
607
|
+
let hasMessages = false;
|
|
608
|
+
const mapping = messages.reduce((output, message) => {
|
|
609
|
+
if (shouldMigrate(message)) {
|
|
610
|
+
for (const legacyId of message.legacyIds) {
|
|
611
|
+
if (output.hasOwnProperty(legacyId)) {
|
|
612
|
+
this._diagnostics.warn(`Detected duplicate legacy ID ${legacyId}.`);
|
|
613
|
+
}
|
|
614
|
+
output[legacyId] = message.id;
|
|
615
|
+
hasMessages = true;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return output;
|
|
619
|
+
}, {});
|
|
620
|
+
if (!hasMessages) {
|
|
621
|
+
this._diagnostics.warn("Could not find any legacy message IDs in source files while generating the legacy message migration file.");
|
|
622
|
+
}
|
|
623
|
+
return JSON.stringify(mapping, null, 2);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
function shouldMigrate(message) {
|
|
627
|
+
return !message.customId && !!message.legacyIds && message.legacyIds.length > 0;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
|
|
631
|
+
import { getFileSystem as getFileSystem2 } from "@angular/compiler-cli/private/localize";
|
|
632
|
+
|
|
633
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/format_options.mjs
|
|
634
|
+
function validateOptions(name, validOptions, options) {
|
|
635
|
+
const validOptionsMap = new Map(validOptions);
|
|
636
|
+
for (const option in options) {
|
|
637
|
+
if (!validOptionsMap.has(option)) {
|
|
638
|
+
throw new Error(`Invalid format option for ${name}: "${option}".
|
|
639
|
+
Allowed options are ${JSON.stringify(Array.from(validOptionsMap.keys()))}.`);
|
|
640
|
+
}
|
|
641
|
+
const validOptionValues = validOptionsMap.get(option);
|
|
642
|
+
const optionValue = options[option];
|
|
643
|
+
if (!validOptionValues.includes(optionValue)) {
|
|
644
|
+
throw new Error(`Invalid format option value for ${name}: "${option}".
|
|
645
|
+
Allowed option values are ${JSON.stringify(validOptionValues)} but received "${optionValue}".`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/icu_parsing.mjs
|
|
651
|
+
function extractIcuPlaceholders(text) {
|
|
652
|
+
const state = new StateStack();
|
|
653
|
+
const pieces = new IcuPieces();
|
|
654
|
+
const braces = /[{}]/g;
|
|
655
|
+
let lastPos = 0;
|
|
656
|
+
let match;
|
|
657
|
+
while (match = braces.exec(text)) {
|
|
658
|
+
if (match[0] == "{") {
|
|
659
|
+
state.enterBlock();
|
|
660
|
+
} else {
|
|
661
|
+
state.leaveBlock();
|
|
662
|
+
}
|
|
663
|
+
if (state.getCurrent() === "placeholder") {
|
|
664
|
+
const name = tryParsePlaceholder(text, braces.lastIndex);
|
|
665
|
+
if (name) {
|
|
666
|
+
pieces.addText(text.substring(lastPos, braces.lastIndex - 1));
|
|
667
|
+
pieces.addPlaceholder(name);
|
|
668
|
+
braces.lastIndex += name.length + 1;
|
|
669
|
+
state.leaveBlock();
|
|
670
|
+
} else {
|
|
671
|
+
pieces.addText(text.substring(lastPos, braces.lastIndex));
|
|
672
|
+
state.nestedIcu();
|
|
673
|
+
}
|
|
674
|
+
} else {
|
|
675
|
+
pieces.addText(text.substring(lastPos, braces.lastIndex));
|
|
676
|
+
}
|
|
677
|
+
lastPos = braces.lastIndex;
|
|
678
|
+
}
|
|
679
|
+
pieces.addText(text.substring(lastPos));
|
|
680
|
+
return pieces.toArray();
|
|
681
|
+
}
|
|
682
|
+
var IcuPieces = class {
|
|
683
|
+
constructor() {
|
|
684
|
+
this.pieces = [""];
|
|
685
|
+
}
|
|
686
|
+
addText(text) {
|
|
687
|
+
this.pieces[this.pieces.length - 1] += text;
|
|
688
|
+
}
|
|
689
|
+
addPlaceholder(name) {
|
|
690
|
+
this.pieces.push(name);
|
|
691
|
+
this.pieces.push("");
|
|
692
|
+
}
|
|
693
|
+
toArray() {
|
|
694
|
+
return this.pieces;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var StateStack = class {
|
|
698
|
+
constructor() {
|
|
699
|
+
this.stack = [];
|
|
700
|
+
}
|
|
701
|
+
enterBlock() {
|
|
702
|
+
const current = this.getCurrent();
|
|
703
|
+
switch (current) {
|
|
704
|
+
case "icu":
|
|
705
|
+
this.stack.push("case");
|
|
706
|
+
break;
|
|
707
|
+
case "case":
|
|
708
|
+
this.stack.push("placeholder");
|
|
709
|
+
break;
|
|
710
|
+
case "placeholder":
|
|
711
|
+
this.stack.push("case");
|
|
712
|
+
break;
|
|
713
|
+
default:
|
|
714
|
+
this.stack.push("icu");
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
leaveBlock() {
|
|
719
|
+
return this.stack.pop();
|
|
720
|
+
}
|
|
721
|
+
nestedIcu() {
|
|
722
|
+
const current = this.stack.pop();
|
|
723
|
+
assert(current === "placeholder", "A nested ICU must replace a placeholder but got " + current);
|
|
724
|
+
this.stack.push("icu");
|
|
725
|
+
}
|
|
726
|
+
getCurrent() {
|
|
727
|
+
return this.stack[this.stack.length - 1];
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
function tryParsePlaceholder(text, start) {
|
|
731
|
+
for (let i = start; i < text.length; i++) {
|
|
732
|
+
if (text[i] === ",") {
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
if (text[i] === "}") {
|
|
736
|
+
return text.substring(start, i);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
function assert(test, message) {
|
|
742
|
+
if (!test) {
|
|
743
|
+
throw new Error("Assertion failure: " + message);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xml_file.mjs
|
|
748
|
+
var XmlFile = class {
|
|
749
|
+
constructor() {
|
|
750
|
+
this.output = '<?xml version="1.0" encoding="UTF-8" ?>\n';
|
|
751
|
+
this.indent = "";
|
|
752
|
+
this.elements = [];
|
|
753
|
+
this.preservingWhitespace = false;
|
|
754
|
+
}
|
|
755
|
+
toString() {
|
|
756
|
+
return this.output;
|
|
757
|
+
}
|
|
758
|
+
startTag(name, attributes = {}, { selfClosing = false, preserveWhitespace } = {}) {
|
|
759
|
+
if (!this.preservingWhitespace) {
|
|
760
|
+
this.output += this.indent;
|
|
761
|
+
}
|
|
762
|
+
this.output += `<${name}`;
|
|
763
|
+
for (const [attrName, attrValue] of Object.entries(attributes)) {
|
|
764
|
+
if (attrValue) {
|
|
765
|
+
this.output += ` ${attrName}="${escapeXml(attrValue)}"`;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (selfClosing) {
|
|
769
|
+
this.output += "/>";
|
|
770
|
+
} else {
|
|
771
|
+
this.output += ">";
|
|
772
|
+
this.elements.push(name);
|
|
773
|
+
this.incIndent();
|
|
774
|
+
}
|
|
775
|
+
if (preserveWhitespace !== void 0) {
|
|
776
|
+
this.preservingWhitespace = preserveWhitespace;
|
|
777
|
+
}
|
|
778
|
+
if (!this.preservingWhitespace) {
|
|
779
|
+
this.output += `
|
|
780
|
+
`;
|
|
781
|
+
}
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
endTag(name, { preserveWhitespace } = {}) {
|
|
785
|
+
const expectedTag = this.elements.pop();
|
|
786
|
+
if (expectedTag !== name) {
|
|
787
|
+
throw new Error(`Unexpected closing tag: "${name}", expected: "${expectedTag}"`);
|
|
788
|
+
}
|
|
789
|
+
this.decIndent();
|
|
790
|
+
if (!this.preservingWhitespace) {
|
|
791
|
+
this.output += this.indent;
|
|
792
|
+
}
|
|
793
|
+
this.output += `</${name}>`;
|
|
794
|
+
if (preserveWhitespace !== void 0) {
|
|
795
|
+
this.preservingWhitespace = preserveWhitespace;
|
|
796
|
+
}
|
|
797
|
+
if (!this.preservingWhitespace) {
|
|
798
|
+
this.output += `
|
|
799
|
+
`;
|
|
800
|
+
}
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
text(str) {
|
|
804
|
+
this.output += escapeXml(str);
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
rawText(str) {
|
|
808
|
+
this.output += str;
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
incIndent() {
|
|
812
|
+
this.indent = this.indent + " ";
|
|
813
|
+
}
|
|
814
|
+
decIndent() {
|
|
815
|
+
this.indent = this.indent.slice(0, -2);
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
var _ESCAPED_CHARS = [
|
|
819
|
+
[/&/g, "&"],
|
|
820
|
+
[/"/g, """],
|
|
821
|
+
[/'/g, "'"],
|
|
822
|
+
[/</g, "<"],
|
|
823
|
+
[/>/g, ">"]
|
|
824
|
+
];
|
|
825
|
+
function escapeXml(text) {
|
|
826
|
+
return _ESCAPED_CHARS.reduce((text2, entry) => text2.replace(entry[0], entry[1]), text);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.mjs
|
|
830
|
+
var LEGACY_XLIFF_MESSAGE_LENGTH = 40;
|
|
831
|
+
var Xliff1TranslationSerializer = class {
|
|
832
|
+
constructor(sourceLocale, basePath, useLegacyIds, formatOptions = {}, fs = getFileSystem2()) {
|
|
833
|
+
this.sourceLocale = sourceLocale;
|
|
834
|
+
this.basePath = basePath;
|
|
835
|
+
this.useLegacyIds = useLegacyIds;
|
|
836
|
+
this.formatOptions = formatOptions;
|
|
837
|
+
this.fs = fs;
|
|
838
|
+
validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions);
|
|
839
|
+
}
|
|
840
|
+
serialize(messages) {
|
|
841
|
+
const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
|
|
842
|
+
const xml = new XmlFile();
|
|
843
|
+
xml.startTag("xliff", { "version": "1.2", "xmlns": "urn:oasis:names:tc:xliff:document:1.2" });
|
|
844
|
+
xml.startTag("file", __spreadValues({
|
|
845
|
+
"source-language": this.sourceLocale,
|
|
846
|
+
"datatype": "plaintext",
|
|
847
|
+
"original": "ng2.template"
|
|
848
|
+
}, this.formatOptions));
|
|
849
|
+
xml.startTag("body");
|
|
850
|
+
for (const duplicateMessages of messageGroups) {
|
|
851
|
+
const message = duplicateMessages[0];
|
|
852
|
+
const id = this.getMessageId(message);
|
|
853
|
+
xml.startTag("trans-unit", { id, datatype: "html" });
|
|
854
|
+
xml.startTag("source", {}, { preserveWhitespace: true });
|
|
855
|
+
this.serializeMessage(xml, message);
|
|
856
|
+
xml.endTag("source", { preserveWhitespace: false });
|
|
857
|
+
for (const { location } of duplicateMessages.filter(hasLocation)) {
|
|
858
|
+
this.serializeLocation(xml, location);
|
|
859
|
+
}
|
|
860
|
+
if (message.description) {
|
|
861
|
+
this.serializeNote(xml, "description", message.description);
|
|
862
|
+
}
|
|
863
|
+
if (message.meaning) {
|
|
864
|
+
this.serializeNote(xml, "meaning", message.meaning);
|
|
865
|
+
}
|
|
866
|
+
xml.endTag("trans-unit");
|
|
867
|
+
}
|
|
868
|
+
xml.endTag("body");
|
|
869
|
+
xml.endTag("file");
|
|
870
|
+
xml.endTag("xliff");
|
|
871
|
+
return xml.toString();
|
|
872
|
+
}
|
|
873
|
+
serializeMessage(xml, message) {
|
|
874
|
+
var _a2;
|
|
875
|
+
const length = message.messageParts.length - 1;
|
|
876
|
+
for (let i = 0; i < length; i++) {
|
|
877
|
+
this.serializeTextPart(xml, message.messageParts[i]);
|
|
878
|
+
const location = (_a2 = message.substitutionLocations) == null ? void 0 : _a2[message.placeholderNames[i]];
|
|
879
|
+
this.serializePlaceholder(xml, message.placeholderNames[i], location == null ? void 0 : location.text);
|
|
880
|
+
}
|
|
881
|
+
this.serializeTextPart(xml, message.messageParts[length]);
|
|
882
|
+
}
|
|
883
|
+
serializeTextPart(xml, text) {
|
|
884
|
+
const pieces = extractIcuPlaceholders(text);
|
|
885
|
+
const length = pieces.length - 1;
|
|
886
|
+
for (let i = 0; i < length; i += 2) {
|
|
887
|
+
xml.text(pieces[i]);
|
|
888
|
+
this.serializePlaceholder(xml, pieces[i + 1], void 0);
|
|
889
|
+
}
|
|
890
|
+
xml.text(pieces[length]);
|
|
891
|
+
}
|
|
892
|
+
serializePlaceholder(xml, id, text) {
|
|
893
|
+
const attrs = { id };
|
|
894
|
+
const ctype = getCtypeForPlaceholder(id);
|
|
895
|
+
if (ctype !== null) {
|
|
896
|
+
attrs.ctype = ctype;
|
|
897
|
+
}
|
|
898
|
+
if (text !== void 0) {
|
|
899
|
+
attrs["equiv-text"] = text;
|
|
900
|
+
}
|
|
901
|
+
xml.startTag("x", attrs, { selfClosing: true });
|
|
902
|
+
}
|
|
903
|
+
serializeNote(xml, name, value) {
|
|
904
|
+
xml.startTag("note", { priority: "1", from: name }, { preserveWhitespace: true });
|
|
905
|
+
xml.text(value);
|
|
906
|
+
xml.endTag("note", { preserveWhitespace: false });
|
|
907
|
+
}
|
|
908
|
+
serializeLocation(xml, location) {
|
|
909
|
+
xml.startTag("context-group", { purpose: "location" });
|
|
910
|
+
this.renderContext(xml, "sourcefile", this.fs.relative(this.basePath, location.file));
|
|
911
|
+
const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
|
|
912
|
+
this.renderContext(xml, "linenumber", `${location.start.line + 1}${endLineString}`);
|
|
913
|
+
xml.endTag("context-group");
|
|
914
|
+
}
|
|
915
|
+
renderContext(xml, type, value) {
|
|
916
|
+
xml.startTag("context", { "context-type": type }, { preserveWhitespace: true });
|
|
917
|
+
xml.text(value);
|
|
918
|
+
xml.endTag("context", { preserveWhitespace: false });
|
|
919
|
+
}
|
|
920
|
+
getMessageId(message) {
|
|
921
|
+
return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length === LEGACY_XLIFF_MESSAGE_LENGTH) || message.id;
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
function getCtypeForPlaceholder(placeholder) {
|
|
925
|
+
const tag = placeholder.replace(/^(START_|CLOSE_)/, "");
|
|
926
|
+
switch (tag) {
|
|
927
|
+
case "LINE_BREAK":
|
|
928
|
+
return "lb";
|
|
929
|
+
case "TAG_IMG":
|
|
930
|
+
return "image";
|
|
931
|
+
default:
|
|
932
|
+
const element = tag.startsWith("TAG_") ? tag.replace(/^TAG_(.+)/, (_, tagName) => tagName.toLowerCase()) : TAG_MAP[tag];
|
|
933
|
+
if (element === void 0) {
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
return `x-${element}`;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
var TAG_MAP = {
|
|
940
|
+
"LINK": "a",
|
|
941
|
+
"BOLD_TEXT": "b",
|
|
942
|
+
"EMPHASISED_TEXT": "em",
|
|
943
|
+
"HEADING_LEVEL1": "h1",
|
|
944
|
+
"HEADING_LEVEL2": "h2",
|
|
945
|
+
"HEADING_LEVEL3": "h3",
|
|
946
|
+
"HEADING_LEVEL4": "h4",
|
|
947
|
+
"HEADING_LEVEL5": "h5",
|
|
948
|
+
"HEADING_LEVEL6": "h6",
|
|
949
|
+
"HORIZONTAL_RULE": "hr",
|
|
950
|
+
"ITALIC_TEXT": "i",
|
|
951
|
+
"LIST_ITEM": "li",
|
|
952
|
+
"MEDIA_LINK": "link",
|
|
953
|
+
"ORDERED_LIST": "ol",
|
|
954
|
+
"PARAGRAPH": "p",
|
|
955
|
+
"QUOTATION": "q",
|
|
956
|
+
"STRIKETHROUGH_TEXT": "s",
|
|
957
|
+
"SMALL_TEXT": "small",
|
|
958
|
+
"SUBSTRIPT": "sub",
|
|
959
|
+
"SUPERSCRIPT": "sup",
|
|
960
|
+
"TABLE_BODY": "tbody",
|
|
961
|
+
"TABLE_CELL": "td",
|
|
962
|
+
"TABLE_FOOTER": "tfoot",
|
|
963
|
+
"TABLE_HEADER_CELL": "th",
|
|
964
|
+
"TABLE_HEADER": "thead",
|
|
965
|
+
"TABLE_ROW": "tr",
|
|
966
|
+
"MONOSPACED_TEXT": "tt",
|
|
967
|
+
"UNDERLINED_TEXT": "u",
|
|
968
|
+
"UNORDERED_LIST": "ul"
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xliff2_translation_serializer.mjs
|
|
972
|
+
import { getFileSystem as getFileSystem3 } from "@angular/compiler-cli/private/localize";
|
|
973
|
+
var MAX_LEGACY_XLIFF_2_MESSAGE_LENGTH = 20;
|
|
974
|
+
var Xliff2TranslationSerializer = class {
|
|
975
|
+
constructor(sourceLocale, basePath, useLegacyIds, formatOptions = {}, fs = getFileSystem3()) {
|
|
976
|
+
this.sourceLocale = sourceLocale;
|
|
977
|
+
this.basePath = basePath;
|
|
978
|
+
this.useLegacyIds = useLegacyIds;
|
|
979
|
+
this.formatOptions = formatOptions;
|
|
980
|
+
this.fs = fs;
|
|
981
|
+
this.currentPlaceholderId = 0;
|
|
982
|
+
validateOptions("Xliff1TranslationSerializer", [["xml:space", ["preserve"]]], formatOptions);
|
|
983
|
+
}
|
|
984
|
+
serialize(messages) {
|
|
985
|
+
const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
|
|
986
|
+
const xml = new XmlFile();
|
|
987
|
+
xml.startTag("xliff", {
|
|
988
|
+
"version": "2.0",
|
|
989
|
+
"xmlns": "urn:oasis:names:tc:xliff:document:2.0",
|
|
990
|
+
"srcLang": this.sourceLocale
|
|
991
|
+
});
|
|
992
|
+
xml.startTag("file", __spreadValues({ "id": "ngi18n", "original": "ng.template" }, this.formatOptions));
|
|
993
|
+
for (const duplicateMessages of messageGroups) {
|
|
994
|
+
const message = duplicateMessages[0];
|
|
995
|
+
const id = this.getMessageId(message);
|
|
996
|
+
xml.startTag("unit", { id });
|
|
997
|
+
const messagesWithLocations = duplicateMessages.filter(hasLocation);
|
|
998
|
+
if (message.meaning || message.description || messagesWithLocations.length) {
|
|
999
|
+
xml.startTag("notes");
|
|
1000
|
+
for (const { location: { file, start, end } } of messagesWithLocations) {
|
|
1001
|
+
const endLineString = end !== void 0 && end.line !== start.line ? `,${end.line + 1}` : "";
|
|
1002
|
+
this.serializeNote(xml, "location", `${this.fs.relative(this.basePath, file)}:${start.line + 1}${endLineString}`);
|
|
1003
|
+
}
|
|
1004
|
+
if (message.description) {
|
|
1005
|
+
this.serializeNote(xml, "description", message.description);
|
|
1006
|
+
}
|
|
1007
|
+
if (message.meaning) {
|
|
1008
|
+
this.serializeNote(xml, "meaning", message.meaning);
|
|
1009
|
+
}
|
|
1010
|
+
xml.endTag("notes");
|
|
1011
|
+
}
|
|
1012
|
+
xml.startTag("segment");
|
|
1013
|
+
xml.startTag("source", {}, { preserveWhitespace: true });
|
|
1014
|
+
this.serializeMessage(xml, message);
|
|
1015
|
+
xml.endTag("source", { preserveWhitespace: false });
|
|
1016
|
+
xml.endTag("segment");
|
|
1017
|
+
xml.endTag("unit");
|
|
1018
|
+
}
|
|
1019
|
+
xml.endTag("file");
|
|
1020
|
+
xml.endTag("xliff");
|
|
1021
|
+
return xml.toString();
|
|
1022
|
+
}
|
|
1023
|
+
serializeMessage(xml, message) {
|
|
1024
|
+
this.currentPlaceholderId = 0;
|
|
1025
|
+
const length = message.messageParts.length - 1;
|
|
1026
|
+
for (let i = 0; i < length; i++) {
|
|
1027
|
+
this.serializeTextPart(xml, message.messageParts[i]);
|
|
1028
|
+
this.serializePlaceholder(xml, message.placeholderNames[i], message.substitutionLocations);
|
|
1029
|
+
}
|
|
1030
|
+
this.serializeTextPart(xml, message.messageParts[length]);
|
|
1031
|
+
}
|
|
1032
|
+
serializeTextPart(xml, text) {
|
|
1033
|
+
const pieces = extractIcuPlaceholders(text);
|
|
1034
|
+
const length = pieces.length - 1;
|
|
1035
|
+
for (let i = 0; i < length; i += 2) {
|
|
1036
|
+
xml.text(pieces[i]);
|
|
1037
|
+
this.serializePlaceholder(xml, pieces[i + 1], void 0);
|
|
1038
|
+
}
|
|
1039
|
+
xml.text(pieces[length]);
|
|
1040
|
+
}
|
|
1041
|
+
serializePlaceholder(xml, placeholderName, substitutionLocations) {
|
|
1042
|
+
var _a2, _b;
|
|
1043
|
+
const text = (_a2 = substitutionLocations == null ? void 0 : substitutionLocations[placeholderName]) == null ? void 0 : _a2.text;
|
|
1044
|
+
if (placeholderName.startsWith("START_")) {
|
|
1045
|
+
const closingPlaceholderName = placeholderName.replace(/^START/, "CLOSE").replace(/_\d+$/, "");
|
|
1046
|
+
const closingText = (_b = substitutionLocations == null ? void 0 : substitutionLocations[closingPlaceholderName]) == null ? void 0 : _b.text;
|
|
1047
|
+
const attrs = {
|
|
1048
|
+
id: `${this.currentPlaceholderId++}`,
|
|
1049
|
+
equivStart: placeholderName,
|
|
1050
|
+
equivEnd: closingPlaceholderName
|
|
1051
|
+
};
|
|
1052
|
+
const type = getTypeForPlaceholder(placeholderName);
|
|
1053
|
+
if (type !== null) {
|
|
1054
|
+
attrs.type = type;
|
|
1055
|
+
}
|
|
1056
|
+
if (text !== void 0) {
|
|
1057
|
+
attrs.dispStart = text;
|
|
1058
|
+
}
|
|
1059
|
+
if (closingText !== void 0) {
|
|
1060
|
+
attrs.dispEnd = closingText;
|
|
1061
|
+
}
|
|
1062
|
+
xml.startTag("pc", attrs);
|
|
1063
|
+
} else if (placeholderName.startsWith("CLOSE_")) {
|
|
1064
|
+
xml.endTag("pc");
|
|
1065
|
+
} else {
|
|
1066
|
+
const attrs = {
|
|
1067
|
+
id: `${this.currentPlaceholderId++}`,
|
|
1068
|
+
equiv: placeholderName
|
|
1069
|
+
};
|
|
1070
|
+
const type = getTypeForPlaceholder(placeholderName);
|
|
1071
|
+
if (type !== null) {
|
|
1072
|
+
attrs.type = type;
|
|
1073
|
+
}
|
|
1074
|
+
if (text !== void 0) {
|
|
1075
|
+
attrs.disp = text;
|
|
1076
|
+
}
|
|
1077
|
+
xml.startTag("ph", attrs, { selfClosing: true });
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
serializeNote(xml, name, value) {
|
|
1081
|
+
xml.startTag("note", { category: name }, { preserveWhitespace: true });
|
|
1082
|
+
xml.text(value);
|
|
1083
|
+
xml.endTag("note", { preserveWhitespace: false });
|
|
1084
|
+
}
|
|
1085
|
+
getMessageId(message) {
|
|
1086
|
+
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;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
function getTypeForPlaceholder(placeholder) {
|
|
1090
|
+
const tag = placeholder.replace(/^(START_|CLOSE_)/, "").replace(/_\d+$/, "");
|
|
1091
|
+
switch (tag) {
|
|
1092
|
+
case "BOLD_TEXT":
|
|
1093
|
+
case "EMPHASISED_TEXT":
|
|
1094
|
+
case "ITALIC_TEXT":
|
|
1095
|
+
case "LINE_BREAK":
|
|
1096
|
+
case "STRIKETHROUGH_TEXT":
|
|
1097
|
+
case "UNDERLINED_TEXT":
|
|
1098
|
+
return "fmt";
|
|
1099
|
+
case "TAG_IMG":
|
|
1100
|
+
return "image";
|
|
1101
|
+
case "LINK":
|
|
1102
|
+
return "link";
|
|
1103
|
+
default:
|
|
1104
|
+
return /^(START_|CLOSE_)/.test(placeholder) ? "other" : null;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/extract/translation_files/xmb_translation_serializer.mjs
|
|
1109
|
+
import { getFileSystem as getFileSystem4 } from "@angular/compiler-cli/private/localize";
|
|
1110
|
+
var XmbTranslationSerializer = class {
|
|
1111
|
+
constructor(basePath, useLegacyIds, fs = getFileSystem4()) {
|
|
1112
|
+
this.basePath = basePath;
|
|
1113
|
+
this.useLegacyIds = useLegacyIds;
|
|
1114
|
+
this.fs = fs;
|
|
1115
|
+
}
|
|
1116
|
+
serialize(messages) {
|
|
1117
|
+
const messageGroups = consolidateMessages(messages, (message) => this.getMessageId(message));
|
|
1118
|
+
const xml = new XmlFile();
|
|
1119
|
+
xml.rawText(`<!DOCTYPE messagebundle [
|
|
1120
|
+
<!ELEMENT messagebundle (msg)*>
|
|
1121
|
+
<!ATTLIST messagebundle class CDATA #IMPLIED>
|
|
1122
|
+
|
|
1123
|
+
<!ELEMENT msg (#PCDATA|ph|source)*>
|
|
1124
|
+
<!ATTLIST msg id CDATA #IMPLIED>
|
|
1125
|
+
<!ATTLIST msg seq CDATA #IMPLIED>
|
|
1126
|
+
<!ATTLIST msg name CDATA #IMPLIED>
|
|
1127
|
+
<!ATTLIST msg desc CDATA #IMPLIED>
|
|
1128
|
+
<!ATTLIST msg meaning CDATA #IMPLIED>
|
|
1129
|
+
<!ATTLIST msg obsolete (obsolete) #IMPLIED>
|
|
1130
|
+
<!ATTLIST msg xml:space (default|preserve) "default">
|
|
1131
|
+
<!ATTLIST msg is_hidden CDATA #IMPLIED>
|
|
1132
|
+
|
|
1133
|
+
<!ELEMENT source (#PCDATA)>
|
|
1134
|
+
|
|
1135
|
+
<!ELEMENT ph (#PCDATA|ex)*>
|
|
1136
|
+
<!ATTLIST ph name CDATA #REQUIRED>
|
|
1137
|
+
|
|
1138
|
+
<!ELEMENT ex (#PCDATA)>
|
|
1139
|
+
]>
|
|
1140
|
+
`);
|
|
1141
|
+
xml.startTag("messagebundle");
|
|
1142
|
+
for (const duplicateMessages of messageGroups) {
|
|
1143
|
+
const message = duplicateMessages[0];
|
|
1144
|
+
const id = this.getMessageId(message);
|
|
1145
|
+
xml.startTag("msg", { id, desc: message.description, meaning: message.meaning }, { preserveWhitespace: true });
|
|
1146
|
+
if (message.location) {
|
|
1147
|
+
this.serializeLocation(xml, message.location);
|
|
1148
|
+
}
|
|
1149
|
+
this.serializeMessage(xml, message);
|
|
1150
|
+
xml.endTag("msg", { preserveWhitespace: false });
|
|
1151
|
+
}
|
|
1152
|
+
xml.endTag("messagebundle");
|
|
1153
|
+
return xml.toString();
|
|
1154
|
+
}
|
|
1155
|
+
serializeLocation(xml, location) {
|
|
1156
|
+
xml.startTag("source");
|
|
1157
|
+
const endLineString = location.end !== void 0 && location.end.line !== location.start.line ? `,${location.end.line + 1}` : "";
|
|
1158
|
+
xml.text(`${this.fs.relative(this.basePath, location.file)}:${location.start.line}${endLineString}`);
|
|
1159
|
+
xml.endTag("source");
|
|
1160
|
+
}
|
|
1161
|
+
serializeMessage(xml, message) {
|
|
1162
|
+
const length = message.messageParts.length - 1;
|
|
1163
|
+
for (let i = 0; i < length; i++) {
|
|
1164
|
+
this.serializeTextPart(xml, message.messageParts[i]);
|
|
1165
|
+
xml.startTag("ph", { name: message.placeholderNames[i] }, { selfClosing: true });
|
|
1166
|
+
}
|
|
1167
|
+
this.serializeTextPart(xml, message.messageParts[length]);
|
|
1168
|
+
}
|
|
1169
|
+
serializeTextPart(xml, text) {
|
|
1170
|
+
const pieces = extractIcuPlaceholders(text);
|
|
1171
|
+
const length = pieces.length - 1;
|
|
1172
|
+
for (let i = 0; i < length; i += 2) {
|
|
1173
|
+
xml.text(pieces[i]);
|
|
1174
|
+
xml.startTag("ph", { name: pieces[i + 1] }, { selfClosing: true });
|
|
1175
|
+
}
|
|
1176
|
+
xml.text(pieces[length]);
|
|
1177
|
+
}
|
|
1178
|
+
getMessageId(message) {
|
|
1179
|
+
return message.customId || this.useLegacyIds && message.legacyIds !== void 0 && message.legacyIds.find((id) => id.length <= 20 && !/[^0-9]/.test(id)) || message.id;
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/source_files/es2015_translate_plugin.mjs
|
|
1184
|
+
import { getFileSystem as getFileSystem5 } from "@angular/compiler-cli/private/localize";
|
|
1185
|
+
function makeEs2015TranslatePlugin(diagnostics, translations, { missingTranslation = "error", localizeName = "$localize" } = {}, fs = getFileSystem5()) {
|
|
1186
|
+
return {
|
|
1187
|
+
visitor: {
|
|
1188
|
+
TaggedTemplateExpression(path) {
|
|
1189
|
+
try {
|
|
1190
|
+
const tag = path.get("tag");
|
|
1191
|
+
if (isLocalize(tag, localizeName)) {
|
|
1192
|
+
const [messageParts] = unwrapMessagePartsFromTemplateLiteral(path.get("quasi").get("quasis"), fs);
|
|
1193
|
+
const translated = translate(diagnostics, translations, messageParts, path.node.quasi.expressions, missingTranslation);
|
|
1194
|
+
path.replaceWith(buildLocalizeReplacement(translated[0], translated[1]));
|
|
1195
|
+
}
|
|
1196
|
+
} catch (e) {
|
|
1197
|
+
if (isBabelParseError(e)) {
|
|
1198
|
+
throw buildCodeFrameError(fs, path, e);
|
|
1199
|
+
} else {
|
|
1200
|
+
throw e;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/source_files/es5_translate_plugin.mjs
|
|
1209
|
+
import { getFileSystem as getFileSystem6 } from "@angular/compiler-cli/private/localize";
|
|
1210
|
+
function makeEs5TranslatePlugin(diagnostics, translations, { missingTranslation = "error", localizeName = "$localize" } = {}, fs = getFileSystem6()) {
|
|
1211
|
+
return {
|
|
1212
|
+
visitor: {
|
|
1213
|
+
CallExpression(callPath) {
|
|
1214
|
+
try {
|
|
1215
|
+
const calleePath = callPath.get("callee");
|
|
1216
|
+
if (isLocalize(calleePath, localizeName)) {
|
|
1217
|
+
const [messageParts] = unwrapMessagePartsFromLocalizeCall(callPath, fs);
|
|
1218
|
+
const [expressions] = unwrapSubstitutionsFromLocalizeCall(callPath, fs);
|
|
1219
|
+
const translated = translate(diagnostics, translations, messageParts, expressions, missingTranslation);
|
|
1220
|
+
callPath.replaceWith(buildLocalizeReplacement(translated[0], translated[1]));
|
|
1221
|
+
}
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
if (isBabelParseError(e)) {
|
|
1224
|
+
diagnostics.error(buildCodeFrameError(fs, callPath, e));
|
|
1225
|
+
} else {
|
|
1226
|
+
throw e;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/source_files/locale_plugin.mjs
|
|
1235
|
+
function makeLocalePlugin(locale, { localizeName = "$localize" } = {}) {
|
|
1236
|
+
return {
|
|
1237
|
+
visitor: {
|
|
1238
|
+
MemberExpression(expression) {
|
|
1239
|
+
const obj = expression.get("object");
|
|
1240
|
+
if (!isLocalize(obj, localizeName)) {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
const property = expression.get("property");
|
|
1244
|
+
if (!property.isIdentifier({ name: "locale" })) {
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
if (expression.parentPath.isAssignmentExpression() && expression.parentPath.get("left") === expression) {
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
const parent = expression.parentPath;
|
|
1251
|
+
if (parent.isLogicalExpression({ operator: "&&" }) && parent.get("right") === expression) {
|
|
1252
|
+
const left = parent.get("left");
|
|
1253
|
+
if (isLocalizeGuard(left, localizeName)) {
|
|
1254
|
+
parent.replaceWith(expression);
|
|
1255
|
+
} else if (left.isLogicalExpression({ operator: "&&" }) && isLocalizeGuard(left.get("right"), localizeName)) {
|
|
1256
|
+
left.replaceWith(left.get("left"));
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
expression.replaceWith(types.stringLiteral(locale));
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
function isLocalizeGuard(expression, localizeName) {
|
|
1265
|
+
if (!expression.isBinaryExpression() || !(expression.node.operator === "!==" || expression.node.operator === "!=")) {
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
const left = expression.get("left");
|
|
1269
|
+
const right = expression.get("right");
|
|
1270
|
+
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" });
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.mjs
|
|
1274
|
+
import { \u0275parseTranslation } from "@angular/localize";
|
|
1275
|
+
var ArbTranslationParser = class {
|
|
1276
|
+
canParse(filePath, contents) {
|
|
1277
|
+
const result = this.analyze(filePath, contents);
|
|
1278
|
+
return result.canParse && result.hint;
|
|
1279
|
+
}
|
|
1280
|
+
analyze(_filePath, contents) {
|
|
1281
|
+
const diagnostics = new Diagnostics();
|
|
1282
|
+
if (!contents.includes('"@@locale"')) {
|
|
1283
|
+
return { canParse: false, diagnostics };
|
|
1284
|
+
}
|
|
1285
|
+
try {
|
|
1286
|
+
return { canParse: true, diagnostics, hint: this.tryParseArbFormat(contents) };
|
|
1287
|
+
} catch {
|
|
1288
|
+
diagnostics.warn("File is not valid JSON.");
|
|
1289
|
+
return { canParse: false, diagnostics };
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
parse(_filePath, contents, arb = this.tryParseArbFormat(contents)) {
|
|
1293
|
+
const bundle = {
|
|
1294
|
+
locale: arb["@@locale"],
|
|
1295
|
+
translations: {},
|
|
1296
|
+
diagnostics: new Diagnostics()
|
|
1297
|
+
};
|
|
1298
|
+
for (const messageId of Object.keys(arb)) {
|
|
1299
|
+
if (messageId.startsWith("@")) {
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
const targetMessage = arb[messageId];
|
|
1303
|
+
bundle.translations[messageId] = \u0275parseTranslation(targetMessage);
|
|
1304
|
+
}
|
|
1305
|
+
return bundle;
|
|
1306
|
+
}
|
|
1307
|
+
tryParseArbFormat(contents) {
|
|
1308
|
+
const json = JSON.parse(contents);
|
|
1309
|
+
if (typeof json["@@locale"] !== "string") {
|
|
1310
|
+
throw new Error("Missing @@locale property.");
|
|
1311
|
+
}
|
|
1312
|
+
return json;
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1316
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.mjs
|
|
1317
|
+
import { \u0275parseTranslation as \u0275parseTranslation2 } from "@angular/localize";
|
|
1318
|
+
import { extname } from "path";
|
|
1319
|
+
var SimpleJsonTranslationParser = class {
|
|
1320
|
+
canParse(filePath, contents) {
|
|
1321
|
+
const result = this.analyze(filePath, contents);
|
|
1322
|
+
return result.canParse && result.hint;
|
|
1323
|
+
}
|
|
1324
|
+
analyze(filePath, contents) {
|
|
1325
|
+
const diagnostics = new Diagnostics();
|
|
1326
|
+
if (extname(filePath) !== ".json" || !(contents.includes('"locale"') && contents.includes('"translations"'))) {
|
|
1327
|
+
diagnostics.warn("File does not have .json extension.");
|
|
1328
|
+
return { canParse: false, diagnostics };
|
|
1329
|
+
}
|
|
1330
|
+
try {
|
|
1331
|
+
const json = JSON.parse(contents);
|
|
1332
|
+
if (json.locale === void 0) {
|
|
1333
|
+
diagnostics.warn('Required "locale" property missing.');
|
|
1334
|
+
return { canParse: false, diagnostics };
|
|
1335
|
+
}
|
|
1336
|
+
if (typeof json.locale !== "string") {
|
|
1337
|
+
diagnostics.warn('The "locale" property is not a string.');
|
|
1338
|
+
return { canParse: false, diagnostics };
|
|
1339
|
+
}
|
|
1340
|
+
if (json.translations === void 0) {
|
|
1341
|
+
diagnostics.warn('Required "translations" property missing.');
|
|
1342
|
+
return { canParse: false, diagnostics };
|
|
1343
|
+
}
|
|
1344
|
+
if (typeof json.translations !== "object") {
|
|
1345
|
+
diagnostics.warn('The "translations" is not an object.');
|
|
1346
|
+
return { canParse: false, diagnostics };
|
|
1347
|
+
}
|
|
1348
|
+
return { canParse: true, diagnostics, hint: json };
|
|
1349
|
+
} catch (e) {
|
|
1350
|
+
diagnostics.warn("File is not valid JSON.");
|
|
1351
|
+
return { canParse: false, diagnostics };
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
parse(_filePath, contents, json) {
|
|
1355
|
+
const { locale: parsedLocale, translations } = json || JSON.parse(contents);
|
|
1356
|
+
const parsedTranslations = {};
|
|
1357
|
+
for (const messageId in translations) {
|
|
1358
|
+
const targetMessage = translations[messageId];
|
|
1359
|
+
parsedTranslations[messageId] = \u0275parseTranslation2(targetMessage);
|
|
1360
|
+
}
|
|
1361
|
+
return { locale: parsedLocale, translations: parsedTranslations, diagnostics: new Diagnostics() };
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.mjs
|
|
1366
|
+
import { ParseErrorLevel as ParseErrorLevel3, visitAll as visitAll2 } from "@angular/compiler";
|
|
1367
|
+
|
|
1368
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/base_visitor.mjs
|
|
1369
|
+
var BaseVisitor = class {
|
|
1370
|
+
visitElement(_element, _context) {
|
|
1371
|
+
}
|
|
1372
|
+
visitAttribute(_attribute, _context) {
|
|
1373
|
+
}
|
|
1374
|
+
visitText(_text, _context) {
|
|
1375
|
+
}
|
|
1376
|
+
visitComment(_comment, _context) {
|
|
1377
|
+
}
|
|
1378
|
+
visitExpansion(_expansion, _context) {
|
|
1379
|
+
}
|
|
1380
|
+
visitExpansionCase(_expansionCase, _context) {
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/message_serializer.mjs
|
|
1385
|
+
import { Element as Element2, visitAll } from "@angular/compiler";
|
|
1386
|
+
|
|
1387
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/translation_parse_error.mjs
|
|
1388
|
+
import { ParseErrorLevel } from "@angular/compiler";
|
|
1389
|
+
var TranslationParseError = class extends Error {
|
|
1390
|
+
constructor(span, msg, level = ParseErrorLevel.ERROR) {
|
|
1391
|
+
super(contextualMessage(span, msg, level));
|
|
1392
|
+
this.span = span;
|
|
1393
|
+
this.msg = msg;
|
|
1394
|
+
this.level = level;
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
function contextualMessage(span, msg, level) {
|
|
1398
|
+
const ctx = span.start.getContext(100, 2);
|
|
1399
|
+
msg += `
|
|
1400
|
+
At ${span.start}${span.details ? `, ${span.details}` : ""}:
|
|
1401
|
+
`;
|
|
1402
|
+
if (ctx) {
|
|
1403
|
+
msg += `...${ctx.before}[${ParseErrorLevel[level]} ->]${ctx.after}...
|
|
1404
|
+
`;
|
|
1405
|
+
}
|
|
1406
|
+
return msg;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/translation_utils.mjs
|
|
1410
|
+
import { Element, ParseError, ParseErrorLevel as ParseErrorLevel2, XmlParser } from "@angular/compiler";
|
|
1411
|
+
function getAttrOrThrow(element, attrName) {
|
|
1412
|
+
const attrValue = getAttribute(element, attrName);
|
|
1413
|
+
if (attrValue === void 0) {
|
|
1414
|
+
throw new TranslationParseError(element.sourceSpan, `Missing required "${attrName}" attribute:`);
|
|
1415
|
+
}
|
|
1416
|
+
return attrValue;
|
|
1417
|
+
}
|
|
1418
|
+
function getAttribute(element, attrName) {
|
|
1419
|
+
const attr = element.attrs.find((a) => a.name === attrName);
|
|
1420
|
+
return attr !== void 0 ? attr.value : void 0;
|
|
1421
|
+
}
|
|
1422
|
+
function parseInnerRange(element) {
|
|
1423
|
+
const xmlParser = new XmlParser();
|
|
1424
|
+
const xml = xmlParser.parse(element.sourceSpan.start.file.content, element.sourceSpan.start.file.url, { tokenizeExpansionForms: true, range: getInnerRange(element) });
|
|
1425
|
+
return xml;
|
|
1426
|
+
}
|
|
1427
|
+
function getInnerRange(element) {
|
|
1428
|
+
const start = element.startSourceSpan.end;
|
|
1429
|
+
const end = element.endSourceSpan.start;
|
|
1430
|
+
return {
|
|
1431
|
+
startPos: start.offset,
|
|
1432
|
+
startLine: start.line,
|
|
1433
|
+
startCol: start.col,
|
|
1434
|
+
endPos: end.offset
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
function canParseXml(filePath, contents, rootNodeName, attributes) {
|
|
1438
|
+
const diagnostics = new Diagnostics();
|
|
1439
|
+
const xmlParser = new XmlParser();
|
|
1440
|
+
const xml = xmlParser.parse(contents, filePath);
|
|
1441
|
+
if (xml.rootNodes.length === 0 || xml.errors.some((error) => error.level === ParseErrorLevel2.ERROR)) {
|
|
1442
|
+
xml.errors.forEach((e) => addParseError(diagnostics, e));
|
|
1443
|
+
return { canParse: false, diagnostics };
|
|
1444
|
+
}
|
|
1445
|
+
const rootElements = xml.rootNodes.filter(isNamedElement(rootNodeName));
|
|
1446
|
+
const rootElement = rootElements[0];
|
|
1447
|
+
if (rootElement === void 0) {
|
|
1448
|
+
diagnostics.warn(`The XML file does not contain a <${rootNodeName}> root node.`);
|
|
1449
|
+
return { canParse: false, diagnostics };
|
|
1450
|
+
}
|
|
1451
|
+
for (const attrKey of Object.keys(attributes)) {
|
|
1452
|
+
const attr = rootElement.attrs.find((attr2) => attr2.name === attrKey);
|
|
1453
|
+
if (attr === void 0 || attr.value !== attributes[attrKey]) {
|
|
1454
|
+
addParseDiagnostic(diagnostics, rootElement.sourceSpan, `The <${rootNodeName}> node does not have the required attribute: ${attrKey}="${attributes[attrKey]}".`, ParseErrorLevel2.WARNING);
|
|
1455
|
+
return { canParse: false, diagnostics };
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if (rootElements.length > 1) {
|
|
1459
|
+
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));
|
|
1460
|
+
}
|
|
1461
|
+
return { canParse: true, diagnostics, hint: { element: rootElement, errors: xml.errors } };
|
|
1462
|
+
}
|
|
1463
|
+
function isNamedElement(name) {
|
|
1464
|
+
function predicate(node) {
|
|
1465
|
+
return node instanceof Element && node.name === name;
|
|
1466
|
+
}
|
|
1467
|
+
return predicate;
|
|
1468
|
+
}
|
|
1469
|
+
function addParseDiagnostic(diagnostics, sourceSpan, message, level) {
|
|
1470
|
+
addParseError(diagnostics, new ParseError(sourceSpan, message, level));
|
|
1471
|
+
}
|
|
1472
|
+
function addParseError(diagnostics, parseError) {
|
|
1473
|
+
if (parseError.level === ParseErrorLevel2.ERROR) {
|
|
1474
|
+
diagnostics.error(parseError.toString());
|
|
1475
|
+
} else {
|
|
1476
|
+
diagnostics.warn(parseError.toString());
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
function addErrorsToBundle(bundle, errors) {
|
|
1480
|
+
for (const error of errors) {
|
|
1481
|
+
addParseError(bundle.diagnostics, error);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/message_serializer.mjs
|
|
1486
|
+
var MessageSerializer = class extends BaseVisitor {
|
|
1487
|
+
constructor(renderer, config) {
|
|
1488
|
+
super();
|
|
1489
|
+
this.renderer = renderer;
|
|
1490
|
+
this.config = config;
|
|
1491
|
+
}
|
|
1492
|
+
serialize(nodes) {
|
|
1493
|
+
this.renderer.startRender();
|
|
1494
|
+
visitAll(this, nodes);
|
|
1495
|
+
this.renderer.endRender();
|
|
1496
|
+
return this.renderer.message;
|
|
1497
|
+
}
|
|
1498
|
+
visitElement(element) {
|
|
1499
|
+
if (this.config.placeholder && element.name === this.config.placeholder.elementName) {
|
|
1500
|
+
const name = getAttrOrThrow(element, this.config.placeholder.nameAttribute);
|
|
1501
|
+
const body = this.config.placeholder.bodyAttribute && getAttribute(element, this.config.placeholder.bodyAttribute);
|
|
1502
|
+
this.visitPlaceholder(name, body);
|
|
1503
|
+
} else if (this.config.placeholderContainer && element.name === this.config.placeholderContainer.elementName) {
|
|
1504
|
+
const start = getAttrOrThrow(element, this.config.placeholderContainer.startAttribute);
|
|
1505
|
+
const end = getAttrOrThrow(element, this.config.placeholderContainer.endAttribute);
|
|
1506
|
+
this.visitPlaceholderContainer(start, element.children, end);
|
|
1507
|
+
} else if (this.config.inlineElements.indexOf(element.name) !== -1) {
|
|
1508
|
+
visitAll(this, element.children);
|
|
1509
|
+
} else {
|
|
1510
|
+
throw new TranslationParseError(element.sourceSpan, `Invalid element found in message.`);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
visitText(text) {
|
|
1514
|
+
this.renderer.text(text.value);
|
|
1515
|
+
}
|
|
1516
|
+
visitExpansion(expansion) {
|
|
1517
|
+
this.renderer.startIcu();
|
|
1518
|
+
this.renderer.text(`${expansion.switchValue}, ${expansion.type},`);
|
|
1519
|
+
visitAll(this, expansion.cases);
|
|
1520
|
+
this.renderer.endIcu();
|
|
1521
|
+
}
|
|
1522
|
+
visitExpansionCase(expansionCase) {
|
|
1523
|
+
this.renderer.text(` ${expansionCase.value} {`);
|
|
1524
|
+
this.renderer.startContainer();
|
|
1525
|
+
visitAll(this, expansionCase.expression);
|
|
1526
|
+
this.renderer.closeContainer();
|
|
1527
|
+
this.renderer.text(`}`);
|
|
1528
|
+
}
|
|
1529
|
+
visitContainedNodes(nodes) {
|
|
1530
|
+
this.renderer.startContainer();
|
|
1531
|
+
visitAll(this, nodes);
|
|
1532
|
+
this.renderer.closeContainer();
|
|
1533
|
+
}
|
|
1534
|
+
visitPlaceholder(name, body) {
|
|
1535
|
+
this.renderer.placeholder(name, body);
|
|
1536
|
+
}
|
|
1537
|
+
visitPlaceholderContainer(startName, children, closeName) {
|
|
1538
|
+
this.renderer.startPlaceholder(startName);
|
|
1539
|
+
this.visitContainedNodes(children);
|
|
1540
|
+
this.renderer.closePlaceholder(closeName);
|
|
1541
|
+
}
|
|
1542
|
+
isPlaceholderContainer(node) {
|
|
1543
|
+
return node instanceof Element2 && node.name === this.config.placeholderContainer.elementName;
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1547
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/message_serialization/target_message_renderer.mjs
|
|
1548
|
+
import { \u0275makeParsedTranslation } from "@angular/localize";
|
|
1549
|
+
var TargetMessageRenderer = class {
|
|
1550
|
+
constructor() {
|
|
1551
|
+
this.current = { messageParts: [], placeholderNames: [], text: "" };
|
|
1552
|
+
this.icuDepth = 0;
|
|
1553
|
+
}
|
|
1554
|
+
get message() {
|
|
1555
|
+
const { messageParts, placeholderNames } = this.current;
|
|
1556
|
+
return \u0275makeParsedTranslation(messageParts, placeholderNames);
|
|
1557
|
+
}
|
|
1558
|
+
startRender() {
|
|
1559
|
+
}
|
|
1560
|
+
endRender() {
|
|
1561
|
+
this.storeMessagePart();
|
|
1562
|
+
}
|
|
1563
|
+
text(text) {
|
|
1564
|
+
this.current.text += text;
|
|
1565
|
+
}
|
|
1566
|
+
placeholder(name, body) {
|
|
1567
|
+
this.renderPlaceholder(name);
|
|
1568
|
+
}
|
|
1569
|
+
startPlaceholder(name) {
|
|
1570
|
+
this.renderPlaceholder(name);
|
|
1571
|
+
}
|
|
1572
|
+
closePlaceholder(name) {
|
|
1573
|
+
this.renderPlaceholder(name);
|
|
1574
|
+
}
|
|
1575
|
+
startContainer() {
|
|
1576
|
+
}
|
|
1577
|
+
closeContainer() {
|
|
1578
|
+
}
|
|
1579
|
+
startIcu() {
|
|
1580
|
+
this.icuDepth++;
|
|
1581
|
+
this.text("{");
|
|
1582
|
+
}
|
|
1583
|
+
endIcu() {
|
|
1584
|
+
this.icuDepth--;
|
|
1585
|
+
this.text("}");
|
|
1586
|
+
}
|
|
1587
|
+
normalizePlaceholderName(name) {
|
|
1588
|
+
return name.replace(/-/g, "_");
|
|
1589
|
+
}
|
|
1590
|
+
renderPlaceholder(name) {
|
|
1591
|
+
name = this.normalizePlaceholderName(name);
|
|
1592
|
+
if (this.icuDepth > 0) {
|
|
1593
|
+
this.text(`{${name}}`);
|
|
1594
|
+
} else {
|
|
1595
|
+
this.storeMessagePart();
|
|
1596
|
+
this.current.placeholderNames.push(name);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
storeMessagePart() {
|
|
1600
|
+
this.current.messageParts.push(this.current.text);
|
|
1601
|
+
this.current.text = "";
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/serialize_translation_message.mjs
|
|
1606
|
+
function serializeTranslationMessage(element, config) {
|
|
1607
|
+
const { rootNodes, errors: parseErrors } = parseInnerRange(element);
|
|
1608
|
+
try {
|
|
1609
|
+
const serializer = new MessageSerializer(new TargetMessageRenderer(), config);
|
|
1610
|
+
const translation = serializer.serialize(rootNodes);
|
|
1611
|
+
return { translation, parseErrors, serializeErrors: [] };
|
|
1612
|
+
} catch (e) {
|
|
1613
|
+
return { translation: null, parseErrors, serializeErrors: [e] };
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser.mjs
|
|
1618
|
+
var Xliff1TranslationParser = class {
|
|
1619
|
+
canParse(filePath, contents) {
|
|
1620
|
+
const result = this.analyze(filePath, contents);
|
|
1621
|
+
return result.canParse && result.hint;
|
|
1622
|
+
}
|
|
1623
|
+
analyze(filePath, contents) {
|
|
1624
|
+
return canParseXml(filePath, contents, "xliff", { version: "1.2" });
|
|
1625
|
+
}
|
|
1626
|
+
parse(filePath, contents, hint) {
|
|
1627
|
+
if (hint) {
|
|
1628
|
+
return this.extractBundle(hint);
|
|
1629
|
+
} else {
|
|
1630
|
+
return this.extractBundleDeprecated(filePath, contents);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
extractBundle({ element, errors }) {
|
|
1634
|
+
const diagnostics = new Diagnostics();
|
|
1635
|
+
errors.forEach((e) => addParseError(diagnostics, e));
|
|
1636
|
+
if (element.children.length === 0) {
|
|
1637
|
+
addParseDiagnostic(diagnostics, element.sourceSpan, "Missing expected <file> element", ParseErrorLevel3.WARNING);
|
|
1638
|
+
return { locale: void 0, translations: {}, diagnostics };
|
|
1639
|
+
}
|
|
1640
|
+
const files = element.children.filter(isNamedElement("file"));
|
|
1641
|
+
if (files.length === 0) {
|
|
1642
|
+
addParseDiagnostic(diagnostics, element.sourceSpan, "No <file> elements found in <xliff>", ParseErrorLevel3.WARNING);
|
|
1643
|
+
} else if (files.length > 1) {
|
|
1644
|
+
addParseDiagnostic(diagnostics, files[1].sourceSpan, "More than one <file> element found in <xliff>", ParseErrorLevel3.WARNING);
|
|
1645
|
+
}
|
|
1646
|
+
const bundle = { locale: void 0, translations: {}, diagnostics };
|
|
1647
|
+
const translationVisitor = new XliffTranslationVisitor();
|
|
1648
|
+
const localesFound = new Set();
|
|
1649
|
+
for (const file of files) {
|
|
1650
|
+
const locale = getAttribute(file, "target-language");
|
|
1651
|
+
if (locale !== void 0) {
|
|
1652
|
+
localesFound.add(locale);
|
|
1653
|
+
bundle.locale = locale;
|
|
1654
|
+
}
|
|
1655
|
+
visitAll2(translationVisitor, file.children, bundle);
|
|
1656
|
+
}
|
|
1657
|
+
if (localesFound.size > 1) {
|
|
1658
|
+
addParseDiagnostic(diagnostics, element.sourceSpan, `More than one locale found in translation file: ${JSON.stringify(Array.from(localesFound))}. Using "${bundle.locale}"`, ParseErrorLevel3.WARNING);
|
|
1659
|
+
}
|
|
1660
|
+
return bundle;
|
|
1661
|
+
}
|
|
1662
|
+
extractBundleDeprecated(filePath, contents) {
|
|
1663
|
+
const hint = this.canParse(filePath, contents);
|
|
1664
|
+
if (!hint) {
|
|
1665
|
+
throw new Error(`Unable to parse "${filePath}" as XLIFF 1.2 format.`);
|
|
1666
|
+
}
|
|
1667
|
+
const bundle = this.extractBundle(hint);
|
|
1668
|
+
if (bundle.diagnostics.hasErrors) {
|
|
1669
|
+
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XLIFF 1.2 format`);
|
|
1670
|
+
throw new Error(message);
|
|
1671
|
+
}
|
|
1672
|
+
return bundle;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
var XliffTranslationVisitor = class extends BaseVisitor {
|
|
1676
|
+
visitElement(element, bundle) {
|
|
1677
|
+
if (element.name === "trans-unit") {
|
|
1678
|
+
this.visitTransUnitElement(element, bundle);
|
|
1679
|
+
} else {
|
|
1680
|
+
visitAll2(this, element.children, bundle);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
visitTransUnitElement(element, bundle) {
|
|
1684
|
+
const id = getAttribute(element, "id");
|
|
1685
|
+
if (id === void 0) {
|
|
1686
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <trans-unit> element.`, ParseErrorLevel3.ERROR);
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
if (bundle.translations[id] !== void 0) {
|
|
1690
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${id}"`, ParseErrorLevel3.ERROR);
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
let targetMessage = element.children.find(isNamedElement("target"));
|
|
1694
|
+
if (targetMessage === void 0) {
|
|
1695
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing <target> element", ParseErrorLevel3.WARNING);
|
|
1696
|
+
targetMessage = element.children.find(isNamedElement("source"));
|
|
1697
|
+
if (targetMessage === void 0) {
|
|
1698
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing required element: one of <target> or <source> is required", ParseErrorLevel3.ERROR);
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(targetMessage, {
|
|
1703
|
+
inlineElements: ["g", "bx", "ex", "bpt", "ept", "ph", "it", "mrk"],
|
|
1704
|
+
placeholder: { elementName: "x", nameAttribute: "id" }
|
|
1705
|
+
});
|
|
1706
|
+
if (translation !== null) {
|
|
1707
|
+
bundle.translations[id] = translation;
|
|
1708
|
+
}
|
|
1709
|
+
addErrorsToBundle(bundle, parseErrors);
|
|
1710
|
+
addErrorsToBundle(bundle, serializeErrors);
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1714
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser.mjs
|
|
1715
|
+
import { Element as Element3, ParseErrorLevel as ParseErrorLevel4, visitAll as visitAll3 } from "@angular/compiler";
|
|
1716
|
+
var Xliff2TranslationParser = class {
|
|
1717
|
+
canParse(filePath, contents) {
|
|
1718
|
+
const result = this.analyze(filePath, contents);
|
|
1719
|
+
return result.canParse && result.hint;
|
|
1720
|
+
}
|
|
1721
|
+
analyze(filePath, contents) {
|
|
1722
|
+
return canParseXml(filePath, contents, "xliff", { version: "2.0" });
|
|
1723
|
+
}
|
|
1724
|
+
parse(filePath, contents, hint) {
|
|
1725
|
+
if (hint) {
|
|
1726
|
+
return this.extractBundle(hint);
|
|
1727
|
+
} else {
|
|
1728
|
+
return this.extractBundleDeprecated(filePath, contents);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
extractBundle({ element, errors }) {
|
|
1732
|
+
const diagnostics = new Diagnostics();
|
|
1733
|
+
errors.forEach((e) => addParseError(diagnostics, e));
|
|
1734
|
+
const locale = getAttribute(element, "trgLang");
|
|
1735
|
+
const files = element.children.filter(isFileElement);
|
|
1736
|
+
if (files.length === 0) {
|
|
1737
|
+
addParseDiagnostic(diagnostics, element.sourceSpan, "No <file> elements found in <xliff>", ParseErrorLevel4.WARNING);
|
|
1738
|
+
} else if (files.length > 1) {
|
|
1739
|
+
addParseDiagnostic(diagnostics, files[1].sourceSpan, "More than one <file> element found in <xliff>", ParseErrorLevel4.WARNING);
|
|
1740
|
+
}
|
|
1741
|
+
const bundle = { locale, translations: {}, diagnostics };
|
|
1742
|
+
const translationVisitor = new Xliff2TranslationVisitor();
|
|
1743
|
+
for (const file of files) {
|
|
1744
|
+
visitAll3(translationVisitor, file.children, { bundle });
|
|
1745
|
+
}
|
|
1746
|
+
return bundle;
|
|
1747
|
+
}
|
|
1748
|
+
extractBundleDeprecated(filePath, contents) {
|
|
1749
|
+
const hint = this.canParse(filePath, contents);
|
|
1750
|
+
if (!hint) {
|
|
1751
|
+
throw new Error(`Unable to parse "${filePath}" as XLIFF 2.0 format.`);
|
|
1752
|
+
}
|
|
1753
|
+
const bundle = this.extractBundle(hint);
|
|
1754
|
+
if (bundle.diagnostics.hasErrors) {
|
|
1755
|
+
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XLIFF 2.0 format`);
|
|
1756
|
+
throw new Error(message);
|
|
1757
|
+
}
|
|
1758
|
+
return bundle;
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
var Xliff2TranslationVisitor = class extends BaseVisitor {
|
|
1762
|
+
visitElement(element, { bundle, unit }) {
|
|
1763
|
+
if (element.name === "unit") {
|
|
1764
|
+
this.visitUnitElement(element, bundle);
|
|
1765
|
+
} else if (element.name === "segment") {
|
|
1766
|
+
this.visitSegmentElement(element, bundle, unit);
|
|
1767
|
+
} else {
|
|
1768
|
+
visitAll3(this, element.children, { bundle, unit });
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
visitUnitElement(element, bundle) {
|
|
1772
|
+
const externalId = getAttribute(element, "id");
|
|
1773
|
+
if (externalId === void 0) {
|
|
1774
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <trans-unit> element.`, ParseErrorLevel4.ERROR);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
if (bundle.translations[externalId] !== void 0) {
|
|
1778
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${externalId}"`, ParseErrorLevel4.ERROR);
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
visitAll3(this, element.children, { bundle, unit: externalId });
|
|
1782
|
+
}
|
|
1783
|
+
visitSegmentElement(element, bundle, unit) {
|
|
1784
|
+
if (unit === void 0) {
|
|
1785
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Invalid <segment> element: should be a child of a <unit> element.", ParseErrorLevel4.ERROR);
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
let targetMessage = element.children.find(isNamedElement("target"));
|
|
1789
|
+
if (targetMessage === void 0) {
|
|
1790
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing <target> element", ParseErrorLevel4.WARNING);
|
|
1791
|
+
targetMessage = element.children.find(isNamedElement("source"));
|
|
1792
|
+
if (targetMessage === void 0) {
|
|
1793
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, "Missing required element: one of <target> or <source> is required", ParseErrorLevel4.ERROR);
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(targetMessage, {
|
|
1798
|
+
inlineElements: ["cp", "sc", "ec", "mrk", "sm", "em"],
|
|
1799
|
+
placeholder: { elementName: "ph", nameAttribute: "equiv", bodyAttribute: "disp" },
|
|
1800
|
+
placeholderContainer: { elementName: "pc", startAttribute: "equivStart", endAttribute: "equivEnd" }
|
|
1801
|
+
});
|
|
1802
|
+
if (translation !== null) {
|
|
1803
|
+
bundle.translations[unit] = translation;
|
|
1804
|
+
}
|
|
1805
|
+
addErrorsToBundle(bundle, parseErrors);
|
|
1806
|
+
addErrorsToBundle(bundle, serializeErrors);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
function isFileElement(node) {
|
|
1810
|
+
return node instanceof Element3 && node.name === "file";
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser.mjs
|
|
1814
|
+
import { ParseErrorLevel as ParseErrorLevel5, visitAll as visitAll4 } from "@angular/compiler";
|
|
1815
|
+
import { extname as extname2 } from "path";
|
|
1816
|
+
var XtbTranslationParser = class {
|
|
1817
|
+
canParse(filePath, contents) {
|
|
1818
|
+
const result = this.analyze(filePath, contents);
|
|
1819
|
+
return result.canParse && result.hint;
|
|
1820
|
+
}
|
|
1821
|
+
analyze(filePath, contents) {
|
|
1822
|
+
const extension = extname2(filePath);
|
|
1823
|
+
if (extension !== ".xtb" && extension !== ".xmb") {
|
|
1824
|
+
const diagnostics = new Diagnostics();
|
|
1825
|
+
diagnostics.warn("Must have xtb or xmb extension.");
|
|
1826
|
+
return { canParse: false, diagnostics };
|
|
1827
|
+
}
|
|
1828
|
+
return canParseXml(filePath, contents, "translationbundle", {});
|
|
1829
|
+
}
|
|
1830
|
+
parse(filePath, contents, hint) {
|
|
1831
|
+
if (hint) {
|
|
1832
|
+
return this.extractBundle(hint);
|
|
1833
|
+
} else {
|
|
1834
|
+
return this.extractBundleDeprecated(filePath, contents);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
extractBundle({ element, errors }) {
|
|
1838
|
+
const langAttr = element.attrs.find((attr) => attr.name === "lang");
|
|
1839
|
+
const bundle = {
|
|
1840
|
+
locale: langAttr && langAttr.value,
|
|
1841
|
+
translations: {},
|
|
1842
|
+
diagnostics: new Diagnostics()
|
|
1843
|
+
};
|
|
1844
|
+
errors.forEach((e) => addParseError(bundle.diagnostics, e));
|
|
1845
|
+
const bundleVisitor = new XtbVisitor();
|
|
1846
|
+
visitAll4(bundleVisitor, element.children, bundle);
|
|
1847
|
+
return bundle;
|
|
1848
|
+
}
|
|
1849
|
+
extractBundleDeprecated(filePath, contents) {
|
|
1850
|
+
const hint = this.canParse(filePath, contents);
|
|
1851
|
+
if (!hint) {
|
|
1852
|
+
throw new Error(`Unable to parse "${filePath}" as XMB/XTB format.`);
|
|
1853
|
+
}
|
|
1854
|
+
const bundle = this.extractBundle(hint);
|
|
1855
|
+
if (bundle.diagnostics.hasErrors) {
|
|
1856
|
+
const message = bundle.diagnostics.formatDiagnostics(`Failed to parse "${filePath}" as XMB/XTB format`);
|
|
1857
|
+
throw new Error(message);
|
|
1858
|
+
}
|
|
1859
|
+
return bundle;
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
var XtbVisitor = class extends BaseVisitor {
|
|
1863
|
+
visitElement(element, bundle) {
|
|
1864
|
+
switch (element.name) {
|
|
1865
|
+
case "translation":
|
|
1866
|
+
const id = getAttribute(element, "id");
|
|
1867
|
+
if (id === void 0) {
|
|
1868
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Missing required "id" attribute on <translation> element.`, ParseErrorLevel5.ERROR);
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
if (bundle.translations[id] !== void 0) {
|
|
1872
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Duplicated translations for message "${id}"`, ParseErrorLevel5.ERROR);
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
const { translation, parseErrors, serializeErrors } = serializeTranslationMessage(element, { inlineElements: [], placeholder: { elementName: "ph", nameAttribute: "name" } });
|
|
1876
|
+
if (parseErrors.length) {
|
|
1877
|
+
bundle.diagnostics.warn(computeParseWarning(id, parseErrors));
|
|
1878
|
+
} else if (translation !== null) {
|
|
1879
|
+
bundle.translations[id] = translation;
|
|
1880
|
+
}
|
|
1881
|
+
addErrorsToBundle(bundle, serializeErrors);
|
|
1882
|
+
break;
|
|
1883
|
+
default:
|
|
1884
|
+
addParseDiagnostic(bundle.diagnostics, element.sourceSpan, `Unexpected <${element.name}> tag.`, ParseErrorLevel5.ERROR);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
function computeParseWarning(id, errors) {
|
|
1889
|
+
const msg = errors.map((e) => e.toString()).join("\n");
|
|
1890
|
+
return `Could not parse message with id "${id}" - perhaps it has an unrecognised ICU format?
|
|
1891
|
+
` + msg;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// bazel-out/darwin-fastbuild/bin/packages/localize/tools/index.mjs
|
|
1895
|
+
setFileSystem(new NodeJSFileSystem());
|
|
1896
|
+
export {
|
|
1897
|
+
ArbTranslationParser,
|
|
1898
|
+
ArbTranslationSerializer,
|
|
1899
|
+
Diagnostics,
|
|
1900
|
+
LegacyMessageIdMigrationSerializer,
|
|
1901
|
+
MessageExtractor,
|
|
1902
|
+
SimpleJsonTranslationParser,
|
|
1903
|
+
SimpleJsonTranslationSerializer,
|
|
1904
|
+
Xliff1TranslationParser,
|
|
1905
|
+
Xliff1TranslationSerializer,
|
|
1906
|
+
Xliff2TranslationParser,
|
|
1907
|
+
Xliff2TranslationSerializer,
|
|
1908
|
+
XmbTranslationSerializer,
|
|
1909
|
+
XtbTranslationParser,
|
|
1910
|
+
buildLocalizeReplacement,
|
|
1911
|
+
checkDuplicateMessages,
|
|
1912
|
+
isGlobalIdentifier,
|
|
1913
|
+
makeEs2015TranslatePlugin,
|
|
1914
|
+
makeEs5TranslatePlugin,
|
|
1915
|
+
makeLocalePlugin,
|
|
1916
|
+
translate,
|
|
1917
|
+
unwrapExpressionsFromTemplateLiteral,
|
|
1918
|
+
unwrapMessagePartsFromLocalizeCall,
|
|
1919
|
+
unwrapMessagePartsFromTemplateLiteral,
|
|
1920
|
+
unwrapSubstitutionsFromLocalizeCall
|
|
1921
|
+
};
|
|
1922
|
+
/**
|
|
1923
|
+
* @license
|
|
1924
|
+
* Copyright Google LLC All Rights Reserved.
|
|
1925
|
+
*
|
|
1926
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
1927
|
+
* found in the LICENSE file at https://angular.io/license
|
|
1928
|
+
*/
|
|
1929
|
+
//# sourceMappingURL=index.js.map
|