@angular/localize 20.0.0-next.4 → 20.0.0-next.6
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/fesm2022/init.mjs +5 -4
- package/fesm2022/init.mjs.map +1 -1
- package/fesm2022/localize-CajB9YLv.mjs +496 -0
- package/fesm2022/localize-CajB9YLv.mjs.map +1 -0
- package/fesm2022/localize.mjs +5 -490
- package/fesm2022/localize.mjs.map +1 -1
- package/index.d.ts +3 -2
- package/init/index.d.ts +2 -2
- package/package.json +4 -4
- package/schematics/ng-add/ng_add_bundle.js +1 -1
- package/schematics/ng-add/ng_add_bundle.js.map +1 -1
- package/tools/bundles/{chunk-E4HORTOJ.js → chunk-GD7LT5WI.js} +5 -6
- package/tools/bundles/chunk-GD7LT5WI.js.map +6 -0
- package/tools/bundles/{chunk-7VEU2OGJ.js → chunk-IKAJEWLA.js} +11 -8
- package/tools/bundles/chunk-IKAJEWLA.js.map +6 -0
- package/tools/bundles/{chunk-7G4W4ZDI.js → chunk-KN2K4QZJ.js} +317 -9
- package/tools/bundles/chunk-KN2K4QZJ.js.map +6 -0
- package/tools/bundles/index.js +3 -3
- package/tools/bundles/src/extract/cli.js +2 -2
- package/tools/bundles/src/translate/cli.js +2 -2
- package/tools/bundles_metadata.json +1 -1
- package/tools/src/extract/duplicates.d.ts +1 -1
- package/tools/src/extract/extraction.d.ts +1 -1
- package/tools/src/extract/source_files/es2015_extract_plugin.d.ts +1 -1
- package/tools/src/extract/source_files/es5_extract_plugin.d.ts +1 -1
- package/tools/src/extract/translation_files/arb_translation_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/json_translation_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/legacy_message_id_migration_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/translation_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/utils.d.ts +1 -1
- package/tools/src/extract/translation_files/xliff1_translation_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/xliff2_translation_serializer.d.ts +1 -1
- package/tools/src/extract/translation_files/xmb_translation_serializer.d.ts +1 -1
- package/tools/src/source_file_utils.d.ts +1 -1
- package/tools/src/translate/source_files/es2015_translate_plugin.d.ts +1 -1
- package/tools/src/translate/source_files/es5_translate_plugin.d.ts +1 -1
- package/tools/src/translate/translation_files/base_visitor.d.ts +3 -1
- package/tools/src/translate/translation_files/message_serialization/target_message_renderer.d.ts +1 -1
- package/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.d.ts +1 -1
- package/tools/src/translate/translation_files/translation_parsers/serialize_translation_message.d.ts +1 -1
- package/tools/src/translate/translation_files/translation_parsers/translation_parser.d.ts +1 -1
- package/tools/src/translate/translator.d.ts +1 -1
- package/tools/bundles/chunk-7G4W4ZDI.js.map +0 -6
- package/tools/bundles/chunk-7VEU2OGJ.js.map +0 -6
- package/tools/bundles/chunk-E4HORTOJ.js.map +0 -6
package/fesm2022/localize.mjs
CHANGED
|
@@ -1,369 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v20.0.0-next.
|
|
2
|
+
* @license Angular v20.0.0-next.6
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* A block can indicate metadata about the message or specify a name of a placeholder for a
|
|
10
|
-
* substitution expressions.
|
|
11
|
-
*
|
|
12
|
-
* For example:
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* $localize`Hello, ${title}:title:!`;
|
|
16
|
-
* $localize`:meaning|description@@id:source message text`;
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
const BLOCK_MARKER$1 = ':';
|
|
20
|
-
/**
|
|
21
|
-
* The marker used to separate a message's "meaning" from its "description" in a metadata block.
|
|
22
|
-
*
|
|
23
|
-
* For example:
|
|
24
|
-
*
|
|
25
|
-
* ```ts
|
|
26
|
-
* $localize `:correct|Indicates that the user got the answer correct: Right!`;
|
|
27
|
-
* $localize `:movement|Button label for moving to the right: Right!`;
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const MEANING_SEPARATOR = '|';
|
|
31
|
-
/**
|
|
32
|
-
* The marker used to separate a message's custom "id" from its "description" in a metadata block.
|
|
33
|
-
*
|
|
34
|
-
* For example:
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* $localize `:A welcome message on the home page@@myApp-homepage-welcome: Welcome!`;
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
const ID_SEPARATOR = '@@';
|
|
41
|
-
/**
|
|
42
|
-
* The marker used to separate legacy message ids from the rest of a metadata block.
|
|
43
|
-
*
|
|
44
|
-
* For example:
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* $localize `:@@custom-id␟2df64767cd895a8fabe3e18b94b5b6b6f9e2e3f0: Welcome!`;
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* Note that this character is the "symbol for the unit separator" (␟) not the "unit separator
|
|
51
|
-
* character" itself, since that has no visual representation. See https://graphemica.com/%E2%90%9F.
|
|
52
|
-
*
|
|
53
|
-
* Here is some background for the original "unit separator character":
|
|
54
|
-
* https://stackoverflow.com/questions/8695118/whats-the-file-group-record-unit-separator-control-characters-and-its-usage
|
|
55
|
-
*/
|
|
56
|
-
const LEGACY_ID_INDICATOR = '\u241F';
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A lazily created TextEncoder instance for converting strings into UTF-8 bytes
|
|
60
|
-
*/
|
|
61
|
-
let textEncoder;
|
|
62
|
-
/**
|
|
63
|
-
* Compute the fingerprint of the given string
|
|
64
|
-
*
|
|
65
|
-
* The output is 64 bit number encoded as a decimal string
|
|
66
|
-
*
|
|
67
|
-
* based on:
|
|
68
|
-
* https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/GoogleJsMessageIdGenerator.java
|
|
69
|
-
*/
|
|
70
|
-
function fingerprint(str) {
|
|
71
|
-
textEncoder ??= new TextEncoder();
|
|
72
|
-
const utf8 = textEncoder.encode(str);
|
|
73
|
-
const view = new DataView(utf8.buffer, utf8.byteOffset, utf8.byteLength);
|
|
74
|
-
let hi = hash32(view, utf8.length, 0);
|
|
75
|
-
let lo = hash32(view, utf8.length, 102072);
|
|
76
|
-
if (hi == 0 && (lo == 0 || lo == 1)) {
|
|
77
|
-
hi = hi ^ 0x130f9bef;
|
|
78
|
-
lo = lo ^ -1801410264;
|
|
79
|
-
}
|
|
80
|
-
return (BigInt.asUintN(32, BigInt(hi)) << BigInt(32)) | BigInt.asUintN(32, BigInt(lo));
|
|
81
|
-
}
|
|
82
|
-
function computeMsgId(msg, meaning = '') {
|
|
83
|
-
let msgFingerprint = fingerprint(msg);
|
|
84
|
-
if (meaning) {
|
|
85
|
-
// Rotate the 64-bit message fingerprint one bit to the left and then add the meaning
|
|
86
|
-
// fingerprint.
|
|
87
|
-
msgFingerprint =
|
|
88
|
-
BigInt.asUintN(64, msgFingerprint << BigInt(1)) |
|
|
89
|
-
((msgFingerprint >> BigInt(63)) & BigInt(1));
|
|
90
|
-
msgFingerprint += fingerprint(meaning);
|
|
91
|
-
}
|
|
92
|
-
return BigInt.asUintN(63, msgFingerprint).toString();
|
|
93
|
-
}
|
|
94
|
-
function hash32(view, length, c) {
|
|
95
|
-
let a = 0x9e3779b9, b = 0x9e3779b9;
|
|
96
|
-
let index = 0;
|
|
97
|
-
const end = length - 12;
|
|
98
|
-
for (; index <= end; index += 12) {
|
|
99
|
-
a += view.getUint32(index, true);
|
|
100
|
-
b += view.getUint32(index + 4, true);
|
|
101
|
-
c += view.getUint32(index + 8, true);
|
|
102
|
-
const res = mix(a, b, c);
|
|
103
|
-
(a = res[0]), (b = res[1]), (c = res[2]);
|
|
104
|
-
}
|
|
105
|
-
const remainder = length - index;
|
|
106
|
-
// the first byte of c is reserved for the length
|
|
107
|
-
c += length;
|
|
108
|
-
if (remainder >= 4) {
|
|
109
|
-
a += view.getUint32(index, true);
|
|
110
|
-
index += 4;
|
|
111
|
-
if (remainder >= 8) {
|
|
112
|
-
b += view.getUint32(index, true);
|
|
113
|
-
index += 4;
|
|
114
|
-
// Partial 32-bit word for c
|
|
115
|
-
if (remainder >= 9) {
|
|
116
|
-
c += view.getUint8(index++) << 8;
|
|
117
|
-
}
|
|
118
|
-
if (remainder >= 10) {
|
|
119
|
-
c += view.getUint8(index++) << 16;
|
|
120
|
-
}
|
|
121
|
-
if (remainder === 11) {
|
|
122
|
-
c += view.getUint8(index++) << 24;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// Partial 32-bit word for b
|
|
127
|
-
if (remainder >= 5) {
|
|
128
|
-
b += view.getUint8(index++);
|
|
129
|
-
}
|
|
130
|
-
if (remainder >= 6) {
|
|
131
|
-
b += view.getUint8(index++) << 8;
|
|
132
|
-
}
|
|
133
|
-
if (remainder === 7) {
|
|
134
|
-
b += view.getUint8(index++) << 16;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
// Partial 32-bit word for a
|
|
140
|
-
if (remainder >= 1) {
|
|
141
|
-
a += view.getUint8(index++);
|
|
142
|
-
}
|
|
143
|
-
if (remainder >= 2) {
|
|
144
|
-
a += view.getUint8(index++) << 8;
|
|
145
|
-
}
|
|
146
|
-
if (remainder === 3) {
|
|
147
|
-
a += view.getUint8(index++) << 16;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return mix(a, b, c)[2];
|
|
151
|
-
}
|
|
152
|
-
function mix(a, b, c) {
|
|
153
|
-
a -= b;
|
|
154
|
-
a -= c;
|
|
155
|
-
a ^= c >>> 13;
|
|
156
|
-
b -= c;
|
|
157
|
-
b -= a;
|
|
158
|
-
b ^= a << 8;
|
|
159
|
-
c -= a;
|
|
160
|
-
c -= b;
|
|
161
|
-
c ^= b >>> 13;
|
|
162
|
-
a -= b;
|
|
163
|
-
a -= c;
|
|
164
|
-
a ^= c >>> 12;
|
|
165
|
-
b -= c;
|
|
166
|
-
b -= a;
|
|
167
|
-
b ^= a << 16;
|
|
168
|
-
c -= a;
|
|
169
|
-
c -= b;
|
|
170
|
-
c ^= b >>> 5;
|
|
171
|
-
a -= b;
|
|
172
|
-
a -= c;
|
|
173
|
-
a ^= c >>> 3;
|
|
174
|
-
b -= c;
|
|
175
|
-
b -= a;
|
|
176
|
-
b ^= a << 10;
|
|
177
|
-
c -= a;
|
|
178
|
-
c -= b;
|
|
179
|
-
c ^= b >>> 15;
|
|
180
|
-
return [a, b, c];
|
|
181
|
-
}
|
|
182
|
-
// Utils
|
|
183
|
-
var Endian;
|
|
184
|
-
(function (Endian) {
|
|
185
|
-
Endian[Endian["Little"] = 0] = "Little";
|
|
186
|
-
Endian[Endian["Big"] = 1] = "Big";
|
|
187
|
-
})(Endian || (Endian = {}));
|
|
188
|
-
|
|
189
|
-
// This module specifier is intentionally a relative path to allow bundling the code directly
|
|
190
|
-
// into the package.
|
|
191
|
-
// @ng_package: ignore-cross-repo-import
|
|
192
|
-
/**
|
|
193
|
-
* Parse a `$localize` tagged string into a structure that can be used for translation or
|
|
194
|
-
* extraction.
|
|
195
|
-
*
|
|
196
|
-
* See `ParsedMessage` for an example.
|
|
197
|
-
*/
|
|
198
|
-
function parseMessage(messageParts, expressions, location, messagePartLocations, expressionLocations = []) {
|
|
199
|
-
const substitutions = {};
|
|
200
|
-
const substitutionLocations = {};
|
|
201
|
-
const associatedMessageIds = {};
|
|
202
|
-
const metadata = parseMetadata(messageParts[0], messageParts.raw[0]);
|
|
203
|
-
const cleanedMessageParts = [metadata.text];
|
|
204
|
-
const placeholderNames = [];
|
|
205
|
-
let messageString = metadata.text;
|
|
206
|
-
for (let i = 1; i < messageParts.length; i++) {
|
|
207
|
-
const { messagePart, placeholderName = computePlaceholderName(i), associatedMessageId, } = parsePlaceholder(messageParts[i], messageParts.raw[i]);
|
|
208
|
-
messageString += `{$${placeholderName}}${messagePart}`;
|
|
209
|
-
if (expressions !== undefined) {
|
|
210
|
-
substitutions[placeholderName] = expressions[i - 1];
|
|
211
|
-
substitutionLocations[placeholderName] = expressionLocations[i - 1];
|
|
212
|
-
}
|
|
213
|
-
placeholderNames.push(placeholderName);
|
|
214
|
-
if (associatedMessageId !== undefined) {
|
|
215
|
-
associatedMessageIds[placeholderName] = associatedMessageId;
|
|
216
|
-
}
|
|
217
|
-
cleanedMessageParts.push(messagePart);
|
|
218
|
-
}
|
|
219
|
-
const messageId = metadata.customId || computeMsgId(messageString, metadata.meaning || '');
|
|
220
|
-
const legacyIds = metadata.legacyIds ? metadata.legacyIds.filter((id) => id !== messageId) : [];
|
|
221
|
-
return {
|
|
222
|
-
id: messageId,
|
|
223
|
-
legacyIds,
|
|
224
|
-
substitutions,
|
|
225
|
-
substitutionLocations,
|
|
226
|
-
text: messageString,
|
|
227
|
-
customId: metadata.customId,
|
|
228
|
-
meaning: metadata.meaning || '',
|
|
229
|
-
description: metadata.description || '',
|
|
230
|
-
messageParts: cleanedMessageParts,
|
|
231
|
-
messagePartLocations,
|
|
232
|
-
placeholderNames,
|
|
233
|
-
associatedMessageIds,
|
|
234
|
-
location,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Parse the given message part (`cooked` + `raw`) to extract the message metadata from the text.
|
|
239
|
-
*
|
|
240
|
-
* If the message part has a metadata block this function will extract the `meaning`,
|
|
241
|
-
* `description`, `customId` and `legacyId` (if provided) from the block. These metadata properties
|
|
242
|
-
* are serialized in the string delimited by `|`, `@@` and `␟` respectively.
|
|
243
|
-
*
|
|
244
|
-
* (Note that `␟` is the `LEGACY_ID_INDICATOR` - see `constants.ts`.)
|
|
245
|
-
*
|
|
246
|
-
* For example:
|
|
247
|
-
*
|
|
248
|
-
* ```ts
|
|
249
|
-
* `:meaning|description@@custom-id:`
|
|
250
|
-
* `:meaning|@@custom-id:`
|
|
251
|
-
* `:meaning|description:`
|
|
252
|
-
* `:description@@custom-id:`
|
|
253
|
-
* `:meaning|:`
|
|
254
|
-
* `:description:`
|
|
255
|
-
* `:@@custom-id:`
|
|
256
|
-
* `:meaning|description@@custom-id␟legacy-id-1␟legacy-id-2:`
|
|
257
|
-
* ```
|
|
258
|
-
*
|
|
259
|
-
* @param cooked The cooked version of the message part to parse.
|
|
260
|
-
* @param raw The raw version of the message part to parse.
|
|
261
|
-
* @returns A object containing any metadata that was parsed from the message part.
|
|
262
|
-
*/
|
|
263
|
-
function parseMetadata(cooked, raw) {
|
|
264
|
-
const { text: messageString, block } = splitBlock(cooked, raw);
|
|
265
|
-
if (block === undefined) {
|
|
266
|
-
return { text: messageString };
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
const [meaningDescAndId, ...legacyIds] = block.split(LEGACY_ID_INDICATOR);
|
|
270
|
-
const [meaningAndDesc, customId] = meaningDescAndId.split(ID_SEPARATOR, 2);
|
|
271
|
-
let [meaning, description] = meaningAndDesc.split(MEANING_SEPARATOR, 2);
|
|
272
|
-
if (description === undefined) {
|
|
273
|
-
description = meaning;
|
|
274
|
-
meaning = undefined;
|
|
275
|
-
}
|
|
276
|
-
if (description === '') {
|
|
277
|
-
description = undefined;
|
|
278
|
-
}
|
|
279
|
-
return { text: messageString, meaning, description, customId, legacyIds };
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Parse the given message part (`cooked` + `raw`) to extract any placeholder metadata from the
|
|
284
|
-
* text.
|
|
285
|
-
*
|
|
286
|
-
* If the message part has a metadata block this function will extract the `placeholderName` and
|
|
287
|
-
* `associatedMessageId` (if provided) from the block.
|
|
288
|
-
*
|
|
289
|
-
* These metadata properties are serialized in the string delimited by `@@`.
|
|
290
|
-
*
|
|
291
|
-
* For example:
|
|
292
|
-
*
|
|
293
|
-
* ```ts
|
|
294
|
-
* `:placeholder-name@@associated-id:`
|
|
295
|
-
* ```
|
|
296
|
-
*
|
|
297
|
-
* @param cooked The cooked version of the message part to parse.
|
|
298
|
-
* @param raw The raw version of the message part to parse.
|
|
299
|
-
* @returns A object containing the metadata (`placeholderName` and `associatedMessageId`) of the
|
|
300
|
-
* preceding placeholder, along with the static text that follows.
|
|
301
|
-
*/
|
|
302
|
-
function parsePlaceholder(cooked, raw) {
|
|
303
|
-
const { text: messagePart, block } = splitBlock(cooked, raw);
|
|
304
|
-
if (block === undefined) {
|
|
305
|
-
return { messagePart };
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
const [placeholderName, associatedMessageId] = block.split(ID_SEPARATOR);
|
|
309
|
-
return { messagePart, placeholderName, associatedMessageId };
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Split a message part (`cooked` + `raw`) into an optional delimited "block" off the front and the
|
|
314
|
-
* rest of the text of the message part.
|
|
315
|
-
*
|
|
316
|
-
* Blocks appear at the start of message parts. They are delimited by a colon `:` character at the
|
|
317
|
-
* start and end of the block.
|
|
318
|
-
*
|
|
319
|
-
* If the block is in the first message part then it will be metadata about the whole message:
|
|
320
|
-
* meaning, description, id. Otherwise it will be metadata about the immediately preceding
|
|
321
|
-
* substitution: placeholder name.
|
|
322
|
-
*
|
|
323
|
-
* Since blocks are optional, it is possible that the content of a message block actually starts
|
|
324
|
-
* with a block marker. In this case the marker must be escaped `\:`.
|
|
325
|
-
*
|
|
326
|
-
* @param cooked The cooked version of the message part to parse.
|
|
327
|
-
* @param raw The raw version of the message part to parse.
|
|
328
|
-
* @returns An object containing the `text` of the message part and the text of the `block`, if it
|
|
329
|
-
* exists.
|
|
330
|
-
* @throws an error if the `block` is unterminated
|
|
331
|
-
*/
|
|
332
|
-
function splitBlock(cooked, raw) {
|
|
333
|
-
if (raw.charAt(0) !== BLOCK_MARKER$1) {
|
|
334
|
-
return { text: cooked };
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
const endOfBlock = findEndOfBlock(cooked, raw);
|
|
338
|
-
return {
|
|
339
|
-
block: cooked.substring(1, endOfBlock),
|
|
340
|
-
text: cooked.substring(endOfBlock + 1),
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
function computePlaceholderName(index) {
|
|
345
|
-
return index === 1 ? 'PH' : `PH_${index - 1}`;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Find the end of a "marked block" indicated by the first non-escaped colon.
|
|
349
|
-
*
|
|
350
|
-
* @param cooked The cooked string (where escaped chars have been processed)
|
|
351
|
-
* @param raw The raw string (where escape sequences are still in place)
|
|
352
|
-
*
|
|
353
|
-
* @returns the index of the end of block marker
|
|
354
|
-
* @throws an error if the block is unterminated
|
|
355
|
-
*/
|
|
356
|
-
function findEndOfBlock(cooked, raw) {
|
|
357
|
-
for (let cookedIndex = 1, rawIndex = 1; cookedIndex < cooked.length; cookedIndex++, rawIndex++) {
|
|
358
|
-
if (raw[rawIndex] === '\\') {
|
|
359
|
-
rawIndex++;
|
|
360
|
-
}
|
|
361
|
-
else if (cooked[cookedIndex] === BLOCK_MARKER$1) {
|
|
362
|
-
return cookedIndex;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
throw new Error(`Unterminated $localize metadata block in "${raw}".`);
|
|
366
|
-
}
|
|
7
|
+
import { BLOCK_MARKER, parseMessage } from './localize-CajB9YLv.mjs';
|
|
8
|
+
export { $localize as ɵ$localize, computeMsgId as ɵcomputeMsgId, findEndOfBlock as ɵfindEndOfBlock, parseMetadata as ɵparseMetadata, splitBlock as ɵsplitBlock } from './localize-CajB9YLv.mjs';
|
|
367
9
|
|
|
368
10
|
class MissingTranslationError extends Error {
|
|
369
11
|
parsedMessage;
|
|
@@ -434,7 +76,7 @@ function parseTranslation(messageString) {
|
|
|
434
76
|
placeholderNames.push(parts[i]);
|
|
435
77
|
messageParts.push(`${parts[i + 1]}`);
|
|
436
78
|
}
|
|
437
|
-
const rawMessageParts = messageParts.map((part) => part.charAt(0) === BLOCK_MARKER
|
|
79
|
+
const rawMessageParts = messageParts.map((part) => part.charAt(0) === BLOCK_MARKER ? '\\' + part : part);
|
|
438
80
|
return {
|
|
439
81
|
text: messageString,
|
|
440
82
|
messageParts: makeTemplateObject(messageParts, rawMessageParts),
|
|
@@ -556,132 +198,5 @@ function translate(messageParts, substitutions) {
|
|
|
556
198
|
}
|
|
557
199
|
}
|
|
558
200
|
|
|
559
|
-
|
|
560
|
-
* Tag a template literal string for localization.
|
|
561
|
-
*
|
|
562
|
-
* For example:
|
|
563
|
-
*
|
|
564
|
-
* ```ts
|
|
565
|
-
* $localize `some string to localize`
|
|
566
|
-
* ```
|
|
567
|
-
*
|
|
568
|
-
* **Providing meaning, description and id**
|
|
569
|
-
*
|
|
570
|
-
* You can optionally specify one or more of `meaning`, `description` and `id` for a localized
|
|
571
|
-
* string by pre-pending it with a colon delimited block of the form:
|
|
572
|
-
*
|
|
573
|
-
* ```ts
|
|
574
|
-
* $localize`:meaning|description@@id:source message text`;
|
|
575
|
-
*
|
|
576
|
-
* $localize`:meaning|:source message text`;
|
|
577
|
-
* $localize`:description:source message text`;
|
|
578
|
-
* $localize`:@@id:source message text`;
|
|
579
|
-
* ```
|
|
580
|
-
*
|
|
581
|
-
* This format is the same as that used for `i18n` markers in Angular templates. See the
|
|
582
|
-
* [Angular i18n guide](guide/i18n/prepare#mark-text-in-component-template).
|
|
583
|
-
*
|
|
584
|
-
* **Naming placeholders**
|
|
585
|
-
*
|
|
586
|
-
* If the template literal string contains expressions, then the expressions will be automatically
|
|
587
|
-
* associated with placeholder names for you.
|
|
588
|
-
*
|
|
589
|
-
* For example:
|
|
590
|
-
*
|
|
591
|
-
* ```ts
|
|
592
|
-
* $localize `Hi ${name}! There are ${items.length} items.`;
|
|
593
|
-
* ```
|
|
594
|
-
*
|
|
595
|
-
* will generate a message-source of `Hi {$PH}! There are {$PH_1} items`.
|
|
596
|
-
*
|
|
597
|
-
* The recommended practice is to name the placeholder associated with each expression though.
|
|
598
|
-
*
|
|
599
|
-
* Do this by providing the placeholder name wrapped in `:` characters directly after the
|
|
600
|
-
* expression. These placeholder names are stripped out of the rendered localized string.
|
|
601
|
-
*
|
|
602
|
-
* For example, to name the `items.length` expression placeholder `itemCount` you write:
|
|
603
|
-
*
|
|
604
|
-
* ```ts
|
|
605
|
-
* $localize `There are ${items.length}:itemCount: items`;
|
|
606
|
-
* ```
|
|
607
|
-
*
|
|
608
|
-
* **Escaping colon markers**
|
|
609
|
-
*
|
|
610
|
-
* If you need to use a `:` character directly at the start of a tagged string that has no
|
|
611
|
-
* metadata block, or directly after a substitution expression that has no name you must escape
|
|
612
|
-
* the `:` by preceding it with a backslash:
|
|
613
|
-
*
|
|
614
|
-
* For example:
|
|
615
|
-
*
|
|
616
|
-
* ```ts
|
|
617
|
-
* // message has a metadata block so no need to escape colon
|
|
618
|
-
* $localize `:some description::this message starts with a colon (:)`;
|
|
619
|
-
* // no metadata block so the colon must be escaped
|
|
620
|
-
* $localize `\:this message starts with a colon (:)`;
|
|
621
|
-
* ```
|
|
622
|
-
*
|
|
623
|
-
* ```ts
|
|
624
|
-
* // named substitution so no need to escape colon
|
|
625
|
-
* $localize `${label}:label:: ${}`
|
|
626
|
-
* // anonymous substitution so colon must be escaped
|
|
627
|
-
* $localize `${label}\: ${}`
|
|
628
|
-
* ```
|
|
629
|
-
*
|
|
630
|
-
* **Processing localized strings:**
|
|
631
|
-
*
|
|
632
|
-
* There are three scenarios:
|
|
633
|
-
*
|
|
634
|
-
* * **compile-time inlining**: the `$localize` tag is transformed at compile time by a
|
|
635
|
-
* transpiler, removing the tag and replacing the template literal string with a translated
|
|
636
|
-
* literal string from a collection of translations provided to the transpilation tool.
|
|
637
|
-
*
|
|
638
|
-
* * **run-time evaluation**: the `$localize` tag is a run-time function that replaces and
|
|
639
|
-
* reorders the parts (static strings and expressions) of the template literal string with strings
|
|
640
|
-
* from a collection of translations loaded at run-time.
|
|
641
|
-
*
|
|
642
|
-
* * **pass-through evaluation**: the `$localize` tag is a run-time function that simply evaluates
|
|
643
|
-
* the original template literal string without applying any translations to the parts. This
|
|
644
|
-
* version is used during development or where there is no need to translate the localized
|
|
645
|
-
* template literals.
|
|
646
|
-
*
|
|
647
|
-
* @param messageParts a collection of the static parts of the template string.
|
|
648
|
-
* @param expressions a collection of the values of each placeholder in the template string.
|
|
649
|
-
* @returns the translated string, with the `messageParts` and `expressions` interleaved together.
|
|
650
|
-
*
|
|
651
|
-
* @publicApi
|
|
652
|
-
*/
|
|
653
|
-
const $localize$1 = function (messageParts, ...expressions) {
|
|
654
|
-
if ($localize$1.translate) {
|
|
655
|
-
// Don't use array expansion here to avoid the compiler adding `__read()` helper unnecessarily.
|
|
656
|
-
const translation = $localize$1.translate(messageParts, expressions);
|
|
657
|
-
messageParts = translation[0];
|
|
658
|
-
expressions = translation[1];
|
|
659
|
-
}
|
|
660
|
-
let message = stripBlock(messageParts[0], messageParts.raw[0]);
|
|
661
|
-
for (let i = 1; i < messageParts.length; i++) {
|
|
662
|
-
message += expressions[i - 1] + stripBlock(messageParts[i], messageParts.raw[i]);
|
|
663
|
-
}
|
|
664
|
-
return message;
|
|
665
|
-
};
|
|
666
|
-
const BLOCK_MARKER = ':';
|
|
667
|
-
/**
|
|
668
|
-
* Strip a delimited "block" from the start of the `messagePart`, if it is found.
|
|
669
|
-
*
|
|
670
|
-
* If a marker character (:) actually appears in the content at the start of a tagged string or
|
|
671
|
-
* after a substitution expression, where a block has not been provided the character must be
|
|
672
|
-
* escaped with a backslash, `\:`. This function checks for this by looking at the `raw`
|
|
673
|
-
* messagePart, which should still contain the backslash.
|
|
674
|
-
*
|
|
675
|
-
* @param messagePart The cooked message part to process.
|
|
676
|
-
* @param rawMessagePart The raw message part to check.
|
|
677
|
-
* @returns the message part with the placeholder name stripped, if found.
|
|
678
|
-
* @throws an error if the block is unterminated
|
|
679
|
-
*/
|
|
680
|
-
function stripBlock(messagePart, rawMessagePart) {
|
|
681
|
-
return rawMessagePart.charAt(0) === BLOCK_MARKER
|
|
682
|
-
? messagePart.substring(findEndOfBlock(messagePart, rawMessagePart) + 1)
|
|
683
|
-
: messagePart;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
export { clearTranslations, loadTranslations, $localize$1 as ɵ$localize, MissingTranslationError as ɵMissingTranslationError, computeMsgId as ɵcomputeMsgId, findEndOfBlock as ɵfindEndOfBlock, isMissingTranslationError as ɵisMissingTranslationError, makeParsedTranslation as ɵmakeParsedTranslation, makeTemplateObject as ɵmakeTemplateObject, parseMessage as ɵparseMessage, parseMetadata as ɵparseMetadata, parseTranslation as ɵparseTranslation, splitBlock as ɵsplitBlock, translate$1 as ɵtranslate };
|
|
201
|
+
export { clearTranslations, loadTranslations, MissingTranslationError as ɵMissingTranslationError, isMissingTranslationError as ɵisMissingTranslationError, makeParsedTranslation as ɵmakeParsedTranslation, makeTemplateObject as ɵmakeTemplateObject, parseMessage as ɵparseMessage, parseTranslation as ɵparseTranslation, translate$1 as ɵtranslate };
|
|
687
202
|
//# sourceMappingURL=localize.mjs.map
|