@angular/localize 19.2.0 → 19.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,479 +0,0 @@
1
- /**
2
- * Declares a copy of the `AbsoluteFsPath` branded type in `@angular/compiler-cli` to avoid an
3
- * import into `@angular/compiler-cli`. The compiler-cli's declaration files are not necessarily
4
- * compatible with web environments that use `@angular/localize`, and would inadvertently include
5
- * `typescript` declaration files in any compilation unit that uses `@angular/localize` (which
6
- * increases parsing time and memory usage during builds) using a default import that only
7
- * type-checks when `allowSyntheticDefaultImports` is enabled.
8
- *
9
- * @see https://github.com/angular/angular/issues/45179
10
- */
11
- declare type AbsoluteFsPathLocalizeCopy = string & {
12
- _brand: 'AbsoluteFsPath';
13
- };
14
-
15
- /**
16
- * Remove all translations for `$localize`, if doing runtime translation.
17
- *
18
- * All translations that had been loading into memory using `loadTranslations()` will be removed.
19
- *
20
- * @see {@link loadTranslations} for loading translations at runtime.
21
- * @see {@link $localize} for tagging messages as needing to be translated.
22
- *
23
- * @publicApi
24
- */
25
- export declare function clearTranslations(): void;
26
-
27
- /**
28
- * Load translations for use by `$localize`, if doing runtime translation.
29
- *
30
- * If the `$localize` tagged strings are not going to be replaced at compiled time, it is possible
31
- * to load a set of translations that will be applied to the `$localize` tagged strings at runtime,
32
- * in the browser.
33
- *
34
- * Loading a new translation will overwrite a previous translation if it has the same `MessageId`.
35
- *
36
- * Note that `$localize` messages are only processed once, when the tagged string is first
37
- * encountered, and does not provide dynamic language changing without refreshing the browser.
38
- * Loading new translations later in the application life-cycle will not change the translated text
39
- * of messages that have already been translated.
40
- *
41
- * The message IDs and translations are in the same format as that rendered to "simple JSON"
42
- * translation files when extracting messages. In particular, placeholders in messages are rendered
43
- * using the `{$PLACEHOLDER_NAME}` syntax. For example the message from the following template:
44
- *
45
- * ```html
46
- * <div i18n>pre<span>inner-pre<b>bold</b>inner-post</span>post</div>
47
- * ```
48
- *
49
- * would have the following form in the `translations` map:
50
- *
51
- * ```ts
52
- * {
53
- * "2932901491976224757":
54
- * "pre{$START_TAG_SPAN}inner-pre{$START_BOLD_TEXT}bold{$CLOSE_BOLD_TEXT}inner-post{$CLOSE_TAG_SPAN}post"
55
- * }
56
- * ```
57
- *
58
- * @param translations A map from message ID to translated message.
59
- *
60
- * These messages are processed and added to a lookup based on their `MessageId`.
61
- *
62
- * @see {@link clearTranslations} for removing translations loaded using this function.
63
- * @see {@link $localize} for tagging messages as needing to be translated.
64
- * @publicApi
65
- */
66
- export declare function loadTranslations(translations: Record<MessageId, TargetMessage>): void;
67
-
68
- /**
69
- * A string that uniquely identifies a message, to be used for matching translations.
70
- *
71
- * @publicApi
72
- */
73
- export declare type MessageId = string;
74
-
75
- /**
76
- * Additional information that can be associated with a message.
77
- */
78
- declare interface MessageMetadata {
79
- /**
80
- * A human readable rendering of the message
81
- */
82
- text: string;
83
- /**
84
- * Legacy message ids, if provided.
85
- *
86
- * In legacy message formats the message id can only be computed directly from the original
87
- * template source.
88
- *
89
- * Since this information is not available in `$localize` calls, the legacy message ids may be
90
- * attached by the compiler to the `$localize` metablock so it can be used if needed at the point
91
- * of translation if the translations are encoded using the legacy message id.
92
- */
93
- legacyIds?: string[];
94
- /**
95
- * The id of the `message` if a custom one was specified explicitly.
96
- *
97
- * This id overrides any computed or legacy ids.
98
- */
99
- customId?: string;
100
- /**
101
- * The meaning of the `message`, used to distinguish identical `messageString`s.
102
- */
103
- meaning?: string;
104
- /**
105
- * The description of the `message`, used to aid translation.
106
- */
107
- description?: string;
108
- /**
109
- * The location of the message in the source.
110
- */
111
- location?: ɵSourceLocation;
112
- }
113
-
114
- /**
115
- * A string containing a translation target message.
116
- *
117
- * I.E. the message that indicates what will be translated to.
118
- *
119
- * Uses `{$placeholder-name}` to indicate a placeholder.
120
- *
121
- * @publicApi
122
- */
123
- export declare type TargetMessage = string;
124
-
125
- /**
126
- * Tag a template literal string for localization.
127
- *
128
- * For example:
129
- *
130
- * ```ts
131
- * $localize `some string to localize`
132
- * ```
133
- *
134
- * **Providing meaning, description and id**
135
- *
136
- * You can optionally specify one or more of `meaning`, `description` and `id` for a localized
137
- * string by pre-pending it with a colon delimited block of the form:
138
- *
139
- * ```ts
140
- * $localize`:meaning|description@@id:source message text`;
141
- *
142
- * $localize`:meaning|:source message text`;
143
- * $localize`:description:source message text`;
144
- * $localize`:@@id:source message text`;
145
- * ```
146
- *
147
- * This format is the same as that used for `i18n` markers in Angular templates. See the
148
- * [Angular i18n guide](guide/i18n/prepare#mark-text-in-component-template).
149
- *
150
- * **Naming placeholders**
151
- *
152
- * If the template literal string contains expressions, then the expressions will be automatically
153
- * associated with placeholder names for you.
154
- *
155
- * For example:
156
- *
157
- * ```ts
158
- * $localize `Hi ${name}! There are ${items.length} items.`;
159
- * ```
160
- *
161
- * will generate a message-source of `Hi {$PH}! There are {$PH_1} items`.
162
- *
163
- * The recommended practice is to name the placeholder associated with each expression though.
164
- *
165
- * Do this by providing the placeholder name wrapped in `:` characters directly after the
166
- * expression. These placeholder names are stripped out of the rendered localized string.
167
- *
168
- * For example, to name the `items.length` expression placeholder `itemCount` you write:
169
- *
170
- * ```ts
171
- * $localize `There are ${items.length}:itemCount: items`;
172
- * ```
173
- *
174
- * **Escaping colon markers**
175
- *
176
- * If you need to use a `:` character directly at the start of a tagged string that has no
177
- * metadata block, or directly after a substitution expression that has no name you must escape
178
- * the `:` by preceding it with a backslash:
179
- *
180
- * For example:
181
- *
182
- * ```ts
183
- * // message has a metadata block so no need to escape colon
184
- * $localize `:some description::this message starts with a colon (:)`;
185
- * // no metadata block so the colon must be escaped
186
- * $localize `\:this message starts with a colon (:)`;
187
- * ```
188
- *
189
- * ```ts
190
- * // named substitution so no need to escape colon
191
- * $localize `${label}:label:: ${}`
192
- * // anonymous substitution so colon must be escaped
193
- * $localize `${label}\: ${}`
194
- * ```
195
- *
196
- * **Processing localized strings:**
197
- *
198
- * There are three scenarios:
199
- *
200
- * * **compile-time inlining**: the `$localize` tag is transformed at compile time by a
201
- * transpiler, removing the tag and replacing the template literal string with a translated
202
- * literal string from a collection of translations provided to the transpilation tool.
203
- *
204
- * * **run-time evaluation**: the `$localize` tag is a run-time function that replaces and
205
- * reorders the parts (static strings and expressions) of the template literal string with strings
206
- * from a collection of translations loaded at run-time.
207
- *
208
- * * **pass-through evaluation**: the `$localize` tag is a run-time function that simply evaluates
209
- * the original template literal string without applying any translations to the parts. This
210
- * version is used during development or where there is no need to translate the localized
211
- * template literals.
212
- *
213
- * @param messageParts a collection of the static parts of the template string.
214
- * @param expressions a collection of the values of each placeholder in the template string.
215
- * @returns the translated string, with the `messageParts` and `expressions` interleaved together.
216
- *
217
- * @publicApi
218
- */
219
- export declare const ɵ$localize: ɵLocalizeFn;
220
-
221
- export declare function ɵcomputeMsgId(msg: string, meaning?: string): string;
222
-
223
- /**
224
- * Find the end of a "marked block" indicated by the first non-escaped colon.
225
- *
226
- * @param cooked The cooked string (where escaped chars have been processed)
227
- * @param raw The raw string (where escape sequences are still in place)
228
- *
229
- * @returns the index of the end of block marker
230
- * @throws an error if the block is unterminated
231
- */
232
- export declare function ɵfindEndOfBlock(cooked: string, raw: string): number;
233
-
234
- export declare function ɵisMissingTranslationError(e: any): e is ɵMissingTranslationError;
235
-
236
-
237
- /** @nodoc */
238
- export declare interface ɵLocalizeFn {
239
- (messageParts: TemplateStringsArray, ...expressions: readonly any[]): string;
240
- /**
241
- * A function that converts an input "message with expressions" into a translated "message with
242
- * expressions".
243
- *
244
- * The conversion may be done in place, modifying the array passed to the function, so
245
- * don't assume that this has no side-effects.
246
- *
247
- * The expressions must be passed in since it might be they need to be reordered for
248
- * different translations.
249
- */
250
- translate?: ɵTranslateFn;
251
- /**
252
- * The current locale of the translated messages.
253
- *
254
- * The compile-time translation inliner is able to replace the following code:
255
- *
256
- * ```ts
257
- * typeof $localize !== "undefined" && $localize.locale
258
- * ```
259
- *
260
- * with a string literal of the current locale. E.g.
261
- *
262
- * ```
263
- * "fr"
264
- * ```
265
- */
266
- locale?: string;
267
- }
268
-
269
- /**
270
- * Create a `ParsedTranslation` from a set of `messageParts` and `placeholderNames`.
271
- *
272
- * @param messageParts The message parts to appear in the ParsedTranslation.
273
- * @param placeholderNames The names of the placeholders to intersperse between the `messageParts`.
274
- */
275
- export declare function ɵmakeParsedTranslation(messageParts: string[], placeholderNames?: string[]): ɵParsedTranslation;
276
-
277
- /**
278
- * Create the specialized array that is passed to tagged-string tag functions.
279
- *
280
- * @param cooked The message parts with their escape codes processed.
281
- * @param raw The message parts with their escaped codes as-is.
282
- */
283
- export declare function ɵmakeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray;
284
-
285
- export declare class ɵMissingTranslationError extends Error {
286
- readonly parsedMessage: ɵParsedMessage;
287
- private readonly type;
288
- constructor(parsedMessage: ɵParsedMessage);
289
- }
290
-
291
- /**
292
- * Information parsed from a `$localize` tagged string that is used to translate it.
293
- *
294
- * For example:
295
- *
296
- * ```ts
297
- * const name = 'Jo Bloggs';
298
- * $localize`Hello ${name}:title@@ID:!`;
299
- * ```
300
- *
301
- * May be parsed into:
302
- *
303
- * ```ts
304
- * {
305
- * id: '6998194507597730591',
306
- * substitutions: { title: 'Jo Bloggs' },
307
- * messageString: 'Hello {$title}!',
308
- * placeholderNames: ['title'],
309
- * associatedMessageIds: { title: 'ID' },
310
- * }
311
- * ```
312
- */
313
- export declare interface ɵParsedMessage extends MessageMetadata {
314
- /**
315
- * The key used to look up the appropriate translation target.
316
- */
317
- id: MessageId;
318
- /**
319
- * A mapping of placeholder names to substitution values.
320
- */
321
- substitutions: Record<string, any>;
322
- /**
323
- * An optional mapping of placeholder names to associated MessageIds.
324
- * This can be used to match ICU placeholders to the message that contains the ICU.
325
- */
326
- associatedMessageIds?: Record<string, MessageId>;
327
- /**
328
- * An optional mapping of placeholder names to source locations
329
- */
330
- substitutionLocations?: Record<string, ɵSourceLocation | undefined>;
331
- /**
332
- * The static parts of the message.
333
- */
334
- messageParts: string[];
335
- /**
336
- * An optional mapping of message parts to source locations
337
- */
338
- messagePartLocations?: (ɵSourceLocation | undefined)[];
339
- /**
340
- * The names of the placeholders that will be replaced with substitutions.
341
- */
342
- placeholderNames: string[];
343
- }
344
-
345
- /**
346
- * A translation message that has been processed to extract the message parts and placeholders.
347
- */
348
- export declare interface ɵParsedTranslation extends MessageMetadata {
349
- messageParts: TemplateStringsArray;
350
- placeholderNames: string[];
351
- }
352
-
353
- /**
354
- * The internal structure used by the runtime localization to translate messages.
355
- */
356
- export declare type ɵParsedTranslations = Record<MessageId, ɵParsedTranslation>;
357
-
358
- /**
359
- * Parse a `$localize` tagged string into a structure that can be used for translation or
360
- * extraction.
361
- *
362
- * See `ParsedMessage` for an example.
363
- */
364
- export declare function ɵparseMessage(messageParts: TemplateStringsArray, expressions?: readonly any[], location?: ɵSourceLocation, messagePartLocations?: (ɵSourceLocation | undefined)[], expressionLocations?: (ɵSourceLocation | undefined)[]): ɵParsedMessage;
365
-
366
- /**
367
- * Parse the given message part (`cooked` + `raw`) to extract the message metadata from the text.
368
- *
369
- * If the message part has a metadata block this function will extract the `meaning`,
370
- * `description`, `customId` and `legacyId` (if provided) from the block. These metadata properties
371
- * are serialized in the string delimited by `|`, `@@` and `␟` respectively.
372
- *
373
- * (Note that `␟` is the `LEGACY_ID_INDICATOR` - see `constants.ts`.)
374
- *
375
- * For example:
376
- *
377
- * ```ts
378
- * `:meaning|description@@custom-id:`
379
- * `:meaning|@@custom-id:`
380
- * `:meaning|description:`
381
- * `:description@@custom-id:`
382
- * `:meaning|:`
383
- * `:description:`
384
- * `:@@custom-id:`
385
- * `:meaning|description@@custom-id␟legacy-id-1␟legacy-id-2:`
386
- * ```
387
- *
388
- * @param cooked The cooked version of the message part to parse.
389
- * @param raw The raw version of the message part to parse.
390
- * @returns A object containing any metadata that was parsed from the message part.
391
- */
392
- export declare function ɵparseMetadata(cooked: string, raw: string): MessageMetadata;
393
-
394
- /**
395
- * Parse the `messageParts` and `placeholderNames` out of a target `message`.
396
- *
397
- * Used by `loadTranslations()` to convert target message strings into a structure that is more
398
- * appropriate for doing translation.
399
- *
400
- * @param message the message to be parsed.
401
- */
402
- export declare function ɵparseTranslation(messageString: TargetMessage): ɵParsedTranslation;
403
-
404
- /**
405
- * The location of the message in the source file.
406
- *
407
- * The `line` and `column` values for the `start` and `end` properties are zero-based.
408
- */
409
- export declare interface ɵSourceLocation {
410
- start: {
411
- line: number;
412
- column: number;
413
- };
414
- end: {
415
- line: number;
416
- column: number;
417
- };
418
- file: AbsoluteFsPathLocalizeCopy;
419
- text?: string;
420
- }
421
-
422
- /**
423
- * A string containing a translation source message.
424
- *
425
- * I.E. the message that indicates what will be translated from.
426
- *
427
- * Uses `{$placeholder-name}` to indicate a placeholder.
428
- */
429
- export declare type ɵSourceMessage = string;
430
-
431
- /**
432
- * Split a message part (`cooked` + `raw`) into an optional delimited "block" off the front and the
433
- * rest of the text of the message part.
434
- *
435
- * Blocks appear at the start of message parts. They are delimited by a colon `:` character at the
436
- * start and end of the block.
437
- *
438
- * If the block is in the first message part then it will be metadata about the whole message:
439
- * meaning, description, id. Otherwise it will be metadata about the immediately preceding
440
- * substitution: placeholder name.
441
- *
442
- * Since blocks are optional, it is possible that the content of a message block actually starts
443
- * with a block marker. In this case the marker must be escaped `\:`.
444
- *
445
- * @param cooked The cooked version of the message part to parse.
446
- * @param raw The raw version of the message part to parse.
447
- * @returns An object containing the `text` of the message part and the text of the `block`, if it
448
- * exists.
449
- * @throws an error if the `block` is unterminated
450
- */
451
- export declare function ɵsplitBlock(cooked: string, raw: string): {
452
- text: string;
453
- block?: string;
454
- };
455
-
456
- /**
457
- * Translate the text of the `$localize` tagged-string (i.e. `messageParts` and
458
- * `substitutions`) using the given `translations`.
459
- *
460
- * The tagged-string is parsed to extract its `messageId` which is used to find an appropriate
461
- * `ParsedTranslation`. If this doesn't match and there are legacy ids then try matching a
462
- * translation using those.
463
- *
464
- * If one is found then it is used to translate the message into a new set of `messageParts` and
465
- * `substitutions`.
466
- * The translation may reorder (or remove) substitutions as appropriate.
467
- *
468
- * If there is no translation with a matching message id then an error is thrown.
469
- * If a translation contains a placeholder that is not found in the message being translated then an
470
- * error is thrown.
471
- */
472
- export declare function ɵtranslate(translations: Record<string, ɵParsedTranslation>, messageParts: TemplateStringsArray, substitutions: readonly any[]): [TemplateStringsArray, readonly any[]];
473
-
474
- /** @nodoc */
475
- export declare interface ɵTranslateFn {
476
- (messageParts: TemplateStringsArray, expressions: readonly any[]): [TemplateStringsArray, readonly any[]];
477
- }
478
-
479
- export { }