@angular/localize 15.2.0-next.0 → 15.2.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/index.mjs +1 -1
- package/esm2020/src/utils/src/messages.mjs +5 -3
- package/fesm2015/init.mjs +1 -1
- package/fesm2015/localize.mjs +525 -5
- package/fesm2015/localize.mjs.map +1 -1
- package/fesm2020/init.mjs +1 -1
- package/fesm2020/localize.mjs +525 -5
- package/fesm2020/localize.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/init/index.d.ts +1 -1
- package/localize/index.d.ts +478 -0
- package/package.json +4 -4
- package/schematics/ng-add/ng_add_bundle.js +2 -2
- package/schematics/ng-add/ng_add_bundle.js.map +1 -1
- package/tools/bundles/{chunk-MIRZ3NBF.js → chunk-3TQ7D6V2.js} +18 -18
- package/tools/bundles/{chunk-MIRZ3NBF.js.map → chunk-3TQ7D6V2.js.map} +0 -0
- package/tools/bundles/{chunk-ICJ4LFWD.js → chunk-IHTOM4VK.js} +18 -18
- package/tools/bundles/{chunk-ICJ4LFWD.js.map → chunk-IHTOM4VK.js.map} +0 -0
- package/tools/bundles/{chunk-DTYQ3TT5.js → chunk-SOWE44E4.js} +3 -3
- package/tools/bundles/{chunk-DTYQ3TT5.js.map → chunk-SOWE44E4.js.map} +0 -0
- package/tools/bundles/index.js +4 -4
- package/tools/bundles/src/extract/cli.js +5 -5
- package/tools/bundles/src/migrate/cli.js +5 -5
- package/tools/bundles/src/translate/cli.js +11 -11
- package/tools/bundles_metadata.json +1 -1
- package/localize.d.ts +0 -10
- package/private.d.ts +0 -9
- package/schematics/ng-add/ng_add_bundle_metadata.json +0 -1
- package/src/localize/index.d.ts +0 -9
- package/src/localize/src/global.d.ts +0 -16
- package/src/localize/src/localize.d.ts +0 -138
- package/src/translate.d.ts +0 -61
- package/src/utils/index.d.ts +0 -10
- package/src/utils/src/constants.d.ts +0 -57
- package/src/utils/src/messages.d.ts +0 -239
- package/src/utils/src/translations.d.ts +0 -58
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Re-export this helper function so that users of `@angular/localize` don't need to actively import
|
|
3
|
-
* from `@angular/compiler`.
|
|
4
|
-
*/
|
|
5
|
-
export { computeMsgId } from '@angular/compiler';
|
|
6
|
-
/**
|
|
7
|
-
* A string containing a translation source message.
|
|
8
|
-
*
|
|
9
|
-
* I.E. the message that indicates what will be translated from.
|
|
10
|
-
*
|
|
11
|
-
* Uses `{$placeholder-name}` to indicate a placeholder.
|
|
12
|
-
*/
|
|
13
|
-
export type SourceMessage = string;
|
|
14
|
-
/**
|
|
15
|
-
* A string containing a translation target message.
|
|
16
|
-
*
|
|
17
|
-
* I.E. the message that indicates what will be translated to.
|
|
18
|
-
*
|
|
19
|
-
* Uses `{$placeholder-name}` to indicate a placeholder.
|
|
20
|
-
*/
|
|
21
|
-
export type TargetMessage = string;
|
|
22
|
-
/**
|
|
23
|
-
* A string that uniquely identifies a message, to be used for matching translations.
|
|
24
|
-
*/
|
|
25
|
-
export type MessageId = string;
|
|
26
|
-
/**
|
|
27
|
-
* Declares a copy of the `AbsoluteFsPath` branded type in `@angular/compiler-cli` to avoid an
|
|
28
|
-
* import into `@angular/compiler-cli`. The compiler-cli's declaration files are not necessarily
|
|
29
|
-
* compatible with web environments that use `@angular/localize`, and would inadvertently include
|
|
30
|
-
* `typescript` declaration files in any compilation unit that uses `@angular/localize` (which
|
|
31
|
-
* increases parsing time and memory usage during builds) using a default import that only
|
|
32
|
-
* type-checks when `allowSyntheticDefaultImports` is enabled.
|
|
33
|
-
*
|
|
34
|
-
* @see https://github.com/angular/angular/issues/45179
|
|
35
|
-
*/
|
|
36
|
-
type AbsoluteFsPathLocalizeCopy = string & {
|
|
37
|
-
_brand: 'AbsoluteFsPath';
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* The location of the message in the source file.
|
|
41
|
-
*
|
|
42
|
-
* The `line` and `column` values for the `start` and `end` properties are zero-based.
|
|
43
|
-
*/
|
|
44
|
-
export interface SourceLocation {
|
|
45
|
-
start: {
|
|
46
|
-
line: number;
|
|
47
|
-
column: number;
|
|
48
|
-
};
|
|
49
|
-
end: {
|
|
50
|
-
line: number;
|
|
51
|
-
column: number;
|
|
52
|
-
};
|
|
53
|
-
file: AbsoluteFsPathLocalizeCopy;
|
|
54
|
-
text?: string;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Additional information that can be associated with a message.
|
|
58
|
-
*/
|
|
59
|
-
export interface MessageMetadata {
|
|
60
|
-
/**
|
|
61
|
-
* A human readable rendering of the message
|
|
62
|
-
*/
|
|
63
|
-
text: string;
|
|
64
|
-
/**
|
|
65
|
-
* Legacy message ids, if provided.
|
|
66
|
-
*
|
|
67
|
-
* In legacy message formats the message id can only be computed directly from the original
|
|
68
|
-
* template source.
|
|
69
|
-
*
|
|
70
|
-
* Since this information is not available in `$localize` calls, the legacy message ids may be
|
|
71
|
-
* attached by the compiler to the `$localize` metablock so it can be used if needed at the point
|
|
72
|
-
* of translation if the translations are encoded using the legacy message id.
|
|
73
|
-
*/
|
|
74
|
-
legacyIds?: string[];
|
|
75
|
-
/**
|
|
76
|
-
* The id of the `message` if a custom one was specified explicitly.
|
|
77
|
-
*
|
|
78
|
-
* This id overrides any computed or legacy ids.
|
|
79
|
-
*/
|
|
80
|
-
customId?: string;
|
|
81
|
-
/**
|
|
82
|
-
* The meaning of the `message`, used to distinguish identical `messageString`s.
|
|
83
|
-
*/
|
|
84
|
-
meaning?: string;
|
|
85
|
-
/**
|
|
86
|
-
* The description of the `message`, used to aid translation.
|
|
87
|
-
*/
|
|
88
|
-
description?: string;
|
|
89
|
-
/**
|
|
90
|
-
* The location of the message in the source.
|
|
91
|
-
*/
|
|
92
|
-
location?: SourceLocation;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Information parsed from a `$localize` tagged string that is used to translate it.
|
|
96
|
-
*
|
|
97
|
-
* For example:
|
|
98
|
-
*
|
|
99
|
-
* ```
|
|
100
|
-
* const name = 'Jo Bloggs';
|
|
101
|
-
* $localize`Hello ${name}:title@@ID:!`;
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* May be parsed into:
|
|
105
|
-
*
|
|
106
|
-
* ```
|
|
107
|
-
* {
|
|
108
|
-
* id: '6998194507597730591',
|
|
109
|
-
* substitutions: { title: 'Jo Bloggs' },
|
|
110
|
-
* messageString: 'Hello {$title}!',
|
|
111
|
-
* placeholderNames: ['title'],
|
|
112
|
-
* associatedMessageIds: { title: 'ID' },
|
|
113
|
-
* }
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export interface ParsedMessage extends MessageMetadata {
|
|
117
|
-
/**
|
|
118
|
-
* The key used to look up the appropriate translation target.
|
|
119
|
-
*/
|
|
120
|
-
id: MessageId;
|
|
121
|
-
/**
|
|
122
|
-
* A mapping of placeholder names to substitution values.
|
|
123
|
-
*/
|
|
124
|
-
substitutions: Record<string, any>;
|
|
125
|
-
/**
|
|
126
|
-
* An optional mapping of placeholder names to associated MessageIds.
|
|
127
|
-
* This can be used to match ICU placeholders to the message that contains the ICU.
|
|
128
|
-
*/
|
|
129
|
-
associatedMessageIds?: Record<string, MessageId>;
|
|
130
|
-
/**
|
|
131
|
-
* An optional mapping of placeholder names to source locations
|
|
132
|
-
*/
|
|
133
|
-
substitutionLocations?: Record<string, SourceLocation | undefined>;
|
|
134
|
-
/**
|
|
135
|
-
* The static parts of the message.
|
|
136
|
-
*/
|
|
137
|
-
messageParts: string[];
|
|
138
|
-
/**
|
|
139
|
-
* An optional mapping of message parts to source locations
|
|
140
|
-
*/
|
|
141
|
-
messagePartLocations?: (SourceLocation | undefined)[];
|
|
142
|
-
/**
|
|
143
|
-
* The names of the placeholders that will be replaced with substitutions.
|
|
144
|
-
*/
|
|
145
|
-
placeholderNames: string[];
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Parse a `$localize` tagged string into a structure that can be used for translation or
|
|
149
|
-
* extraction.
|
|
150
|
-
*
|
|
151
|
-
* See `ParsedMessage` for an example.
|
|
152
|
-
*/
|
|
153
|
-
export declare function parseMessage(messageParts: TemplateStringsArray, expressions?: readonly any[], location?: SourceLocation, messagePartLocations?: (SourceLocation | undefined)[], expressionLocations?: (SourceLocation | undefined)[]): ParsedMessage;
|
|
154
|
-
/**
|
|
155
|
-
* Parse the given message part (`cooked` + `raw`) to extract the message metadata from the text.
|
|
156
|
-
*
|
|
157
|
-
* If the message part has a metadata block this function will extract the `meaning`,
|
|
158
|
-
* `description`, `customId` and `legacyId` (if provided) from the block. These metadata properties
|
|
159
|
-
* are serialized in the string delimited by `|`, `@@` and `␟` respectively.
|
|
160
|
-
*
|
|
161
|
-
* (Note that `␟` is the `LEGACY_ID_INDICATOR` - see `constants.ts`.)
|
|
162
|
-
*
|
|
163
|
-
* For example:
|
|
164
|
-
*
|
|
165
|
-
* ```ts
|
|
166
|
-
* `:meaning|description@@custom-id:`
|
|
167
|
-
* `:meaning|@@custom-id:`
|
|
168
|
-
* `:meaning|description:`
|
|
169
|
-
* `:description@@custom-id:`
|
|
170
|
-
* `:meaning|:`
|
|
171
|
-
* `:description:`
|
|
172
|
-
* `:@@custom-id:`
|
|
173
|
-
* `:meaning|description@@custom-id␟legacy-id-1␟legacy-id-2:`
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
* @param cooked The cooked version of the message part to parse.
|
|
177
|
-
* @param raw The raw version of the message part to parse.
|
|
178
|
-
* @returns A object containing any metadata that was parsed from the message part.
|
|
179
|
-
*/
|
|
180
|
-
export declare function parseMetadata(cooked: string, raw: string): MessageMetadata;
|
|
181
|
-
/**
|
|
182
|
-
* Parse the given message part (`cooked` + `raw`) to extract any placeholder metadata from the
|
|
183
|
-
* text.
|
|
184
|
-
*
|
|
185
|
-
* If the message part has a metadata block this function will extract the `placeholderName` and
|
|
186
|
-
* `associatedMessageId` (if provided) from the block.
|
|
187
|
-
*
|
|
188
|
-
* These metadata properties are serialized in the string delimited by `@@`.
|
|
189
|
-
*
|
|
190
|
-
* For example:
|
|
191
|
-
*
|
|
192
|
-
* ```ts
|
|
193
|
-
* `:placeholder-name@@associated-id:`
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* @param cooked The cooked version of the message part to parse.
|
|
197
|
-
* @param raw The raw version of the message part to parse.
|
|
198
|
-
* @returns A object containing the metadata (`placeholderName` and `associatedMessageId`) of the
|
|
199
|
-
* preceding placeholder, along with the static text that follows.
|
|
200
|
-
*/
|
|
201
|
-
export declare function parsePlaceholder(cooked: string, raw: string): {
|
|
202
|
-
messagePart: string;
|
|
203
|
-
placeholderName?: string;
|
|
204
|
-
associatedMessageId?: string;
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Split a message part (`cooked` + `raw`) into an optional delimited "block" off the front and the
|
|
208
|
-
* rest of the text of the message part.
|
|
209
|
-
*
|
|
210
|
-
* Blocks appear at the start of message parts. They are delimited by a colon `:` character at the
|
|
211
|
-
* start and end of the block.
|
|
212
|
-
*
|
|
213
|
-
* If the block is in the first message part then it will be metadata about the whole message:
|
|
214
|
-
* meaning, description, id. Otherwise it will be metadata about the immediately preceding
|
|
215
|
-
* substitution: placeholder name.
|
|
216
|
-
*
|
|
217
|
-
* Since blocks are optional, it is possible that the content of a message block actually starts
|
|
218
|
-
* with a block marker. In this case the marker must be escaped `\:`.
|
|
219
|
-
*
|
|
220
|
-
* @param cooked The cooked version of the message part to parse.
|
|
221
|
-
* @param raw The raw version of the message part to parse.
|
|
222
|
-
* @returns An object containing the `text` of the message part and the text of the `block`, if it
|
|
223
|
-
* exists.
|
|
224
|
-
* @throws an error if the `block` is unterminated
|
|
225
|
-
*/
|
|
226
|
-
export declare function splitBlock(cooked: string, raw: string): {
|
|
227
|
-
text: string;
|
|
228
|
-
block?: string;
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Find the end of a "marked block" indicated by the first non-escaped colon.
|
|
232
|
-
*
|
|
233
|
-
* @param cooked The cooked string (where escaped chars have been processed)
|
|
234
|
-
* @param raw The raw string (where escape sequences are still in place)
|
|
235
|
-
*
|
|
236
|
-
* @returns the index of the end of block marker
|
|
237
|
-
* @throws an error if the block is unterminated
|
|
238
|
-
*/
|
|
239
|
-
export declare function findEndOfBlock(cooked: string, raw: string): number;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { MessageId, MessageMetadata, ParsedMessage, TargetMessage } from './messages';
|
|
2
|
-
/**
|
|
3
|
-
* A translation message that has been processed to extract the message parts and placeholders.
|
|
4
|
-
*/
|
|
5
|
-
export interface ParsedTranslation extends MessageMetadata {
|
|
6
|
-
messageParts: TemplateStringsArray;
|
|
7
|
-
placeholderNames: string[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* The internal structure used by the runtime localization to translate messages.
|
|
11
|
-
*/
|
|
12
|
-
export type ParsedTranslations = Record<MessageId, ParsedTranslation>;
|
|
13
|
-
export declare class MissingTranslationError extends Error {
|
|
14
|
-
readonly parsedMessage: ParsedMessage;
|
|
15
|
-
private readonly type;
|
|
16
|
-
constructor(parsedMessage: ParsedMessage);
|
|
17
|
-
}
|
|
18
|
-
export declare function isMissingTranslationError(e: any): e is MissingTranslationError;
|
|
19
|
-
/**
|
|
20
|
-
* Translate the text of the `$localize` tagged-string (i.e. `messageParts` and
|
|
21
|
-
* `substitutions`) using the given `translations`.
|
|
22
|
-
*
|
|
23
|
-
* The tagged-string is parsed to extract its `messageId` which is used to find an appropriate
|
|
24
|
-
* `ParsedTranslation`. If this doesn't match and there are legacy ids then try matching a
|
|
25
|
-
* translation using those.
|
|
26
|
-
*
|
|
27
|
-
* If one is found then it is used to translate the message into a new set of `messageParts` and
|
|
28
|
-
* `substitutions`.
|
|
29
|
-
* The translation may reorder (or remove) substitutions as appropriate.
|
|
30
|
-
*
|
|
31
|
-
* If there is no translation with a matching message id then an error is thrown.
|
|
32
|
-
* If a translation contains a placeholder that is not found in the message being translated then an
|
|
33
|
-
* error is thrown.
|
|
34
|
-
*/
|
|
35
|
-
export declare function translate(translations: Record<string, ParsedTranslation>, messageParts: TemplateStringsArray, substitutions: readonly any[]): [TemplateStringsArray, readonly any[]];
|
|
36
|
-
/**
|
|
37
|
-
* Parse the `messageParts` and `placeholderNames` out of a target `message`.
|
|
38
|
-
*
|
|
39
|
-
* Used by `loadTranslations()` to convert target message strings into a structure that is more
|
|
40
|
-
* appropriate for doing translation.
|
|
41
|
-
*
|
|
42
|
-
* @param message the message to be parsed.
|
|
43
|
-
*/
|
|
44
|
-
export declare function parseTranslation(messageString: TargetMessage): ParsedTranslation;
|
|
45
|
-
/**
|
|
46
|
-
* Create a `ParsedTranslation` from a set of `messageParts` and `placeholderNames`.
|
|
47
|
-
*
|
|
48
|
-
* @param messageParts The message parts to appear in the ParsedTranslation.
|
|
49
|
-
* @param placeholderNames The names of the placeholders to intersperse between the `messageParts`.
|
|
50
|
-
*/
|
|
51
|
-
export declare function makeParsedTranslation(messageParts: string[], placeholderNames?: string[]): ParsedTranslation;
|
|
52
|
-
/**
|
|
53
|
-
* Create the specialized array that is passed to tagged-string tag functions.
|
|
54
|
-
*
|
|
55
|
-
* @param cooked The message parts with their escape codes processed.
|
|
56
|
-
* @param raw The message parts with their escaped codes as-is.
|
|
57
|
-
*/
|
|
58
|
-
export declare function makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray;
|