@angular/localize 15.2.0-next.1 → 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 +3 -3
- package/schematics/ng-add/ng_add_bundle.js +1 -1
- package/schematics/ng-add/ng_add_bundle.js.map +1 -1
- package/localize.d.ts +0 -10
- package/private.d.ts +0 -9
- 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,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
/** @nodoc */
|
|
9
|
-
export interface LocalizeFn {
|
|
10
|
-
(messageParts: TemplateStringsArray, ...expressions: readonly any[]): string;
|
|
11
|
-
/**
|
|
12
|
-
* A function that converts an input "message with expressions" into a translated "message with
|
|
13
|
-
* expressions".
|
|
14
|
-
*
|
|
15
|
-
* The conversion may be done in place, modifying the array passed to the function, so
|
|
16
|
-
* don't assume that this has no side-effects.
|
|
17
|
-
*
|
|
18
|
-
* The expressions must be passed in since it might be they need to be reordered for
|
|
19
|
-
* different translations.
|
|
20
|
-
*/
|
|
21
|
-
translate?: TranslateFn;
|
|
22
|
-
/**
|
|
23
|
-
* The current locale of the translated messages.
|
|
24
|
-
*
|
|
25
|
-
* The compile-time translation inliner is able to replace the following code:
|
|
26
|
-
*
|
|
27
|
-
* ```
|
|
28
|
-
* typeof $localize !== "undefined" && $localize.locale
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* with a string literal of the current locale. E.g.
|
|
32
|
-
*
|
|
33
|
-
* ```
|
|
34
|
-
* "fr"
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
locale?: string;
|
|
38
|
-
}
|
|
39
|
-
/** @nodoc */
|
|
40
|
-
export interface TranslateFn {
|
|
41
|
-
(messageParts: TemplateStringsArray, expressions: readonly any[]): [TemplateStringsArray, readonly any[]];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Tag a template literal string for localization.
|
|
45
|
-
*
|
|
46
|
-
* For example:
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* $localize `some string to localize`
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* **Providing meaning, description and id**
|
|
53
|
-
*
|
|
54
|
-
* You can optionally specify one or more of `meaning`, `description` and `id` for a localized
|
|
55
|
-
* string by pre-pending it with a colon delimited block of the form:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* $localize`:meaning|description@@id:source message text`;
|
|
59
|
-
*
|
|
60
|
-
* $localize`:meaning|:source message text`;
|
|
61
|
-
* $localize`:description:source message text`;
|
|
62
|
-
* $localize`:@@id:source message text`;
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* This format is the same as that used for `i18n` markers in Angular templates. See the
|
|
66
|
-
* [Angular i18n guide](guide/i18n-common-prepare#mark-text-in-component-template).
|
|
67
|
-
*
|
|
68
|
-
* **Naming placeholders**
|
|
69
|
-
*
|
|
70
|
-
* If the template literal string contains expressions, then the expressions will be automatically
|
|
71
|
-
* associated with placeholder names for you.
|
|
72
|
-
*
|
|
73
|
-
* For example:
|
|
74
|
-
*
|
|
75
|
-
* ```ts
|
|
76
|
-
* $localize `Hi ${name}! There are ${items.length} items.`;
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* will generate a message-source of `Hi {$PH}! There are {$PH_1} items`.
|
|
80
|
-
*
|
|
81
|
-
* The recommended practice is to name the placeholder associated with each expression though.
|
|
82
|
-
*
|
|
83
|
-
* Do this by providing the placeholder name wrapped in `:` characters directly after the
|
|
84
|
-
* expression. These placeholder names are stripped out of the rendered localized string.
|
|
85
|
-
*
|
|
86
|
-
* For example, to name the `items.length` expression placeholder `itemCount` you write:
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* $localize `There are ${items.length}:itemCount: items`;
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* **Escaping colon markers**
|
|
93
|
-
*
|
|
94
|
-
* If you need to use a `:` character directly at the start of a tagged string that has no
|
|
95
|
-
* metadata block, or directly after a substitution expression that has no name you must escape
|
|
96
|
-
* the `:` by preceding it with a backslash:
|
|
97
|
-
*
|
|
98
|
-
* For example:
|
|
99
|
-
*
|
|
100
|
-
* ```ts
|
|
101
|
-
* // message has a metadata block so no need to escape colon
|
|
102
|
-
* $localize `:some description::this message starts with a colon (:)`;
|
|
103
|
-
* // no metadata block so the colon must be escaped
|
|
104
|
-
* $localize `\:this message starts with a colon (:)`;
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* ```ts
|
|
108
|
-
* // named substitution so no need to escape colon
|
|
109
|
-
* $localize `${label}:label:: ${}`
|
|
110
|
-
* // anonymous substitution so colon must be escaped
|
|
111
|
-
* $localize `${label}\: ${}`
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* **Processing localized strings:**
|
|
115
|
-
*
|
|
116
|
-
* There are three scenarios:
|
|
117
|
-
*
|
|
118
|
-
* * **compile-time inlining**: the `$localize` tag is transformed at compile time by a
|
|
119
|
-
* transpiler, removing the tag and replacing the template literal string with a translated
|
|
120
|
-
* literal string from a collection of translations provided to the transpilation tool.
|
|
121
|
-
*
|
|
122
|
-
* * **run-time evaluation**: the `$localize` tag is a run-time function that replaces and
|
|
123
|
-
* reorders the parts (static strings and expressions) of the template literal string with strings
|
|
124
|
-
* from a collection of translations loaded at run-time.
|
|
125
|
-
*
|
|
126
|
-
* * **pass-through evaluation**: the `$localize` tag is a run-time function that simply evaluates
|
|
127
|
-
* the original template literal string without applying any translations to the parts. This
|
|
128
|
-
* version is used during development or where there is no need to translate the localized
|
|
129
|
-
* template literals.
|
|
130
|
-
*
|
|
131
|
-
* @param messageParts a collection of the static parts of the template string.
|
|
132
|
-
* @param expressions a collection of the values of each placeholder in the template string.
|
|
133
|
-
* @returns the translated string, with the `messageParts` and `expressions` interleaved together.
|
|
134
|
-
*
|
|
135
|
-
* @globalApi
|
|
136
|
-
* @publicApi
|
|
137
|
-
*/
|
|
138
|
-
export declare const $localize: LocalizeFn;
|
package/src/translate.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { MessageId, TargetMessage } from './utils';
|
|
2
|
-
/**
|
|
3
|
-
* Load translations for use by `$localize`, if doing runtime translation.
|
|
4
|
-
*
|
|
5
|
-
* If the `$localize` tagged strings are not going to be replaced at compiled time, it is possible
|
|
6
|
-
* to load a set of translations that will be applied to the `$localize` tagged strings at runtime,
|
|
7
|
-
* in the browser.
|
|
8
|
-
*
|
|
9
|
-
* Loading a new translation will overwrite a previous translation if it has the same `MessageId`.
|
|
10
|
-
*
|
|
11
|
-
* Note that `$localize` messages are only processed once, when the tagged string is first
|
|
12
|
-
* encountered, and does not provide dynamic language changing without refreshing the browser.
|
|
13
|
-
* Loading new translations later in the application life-cycle will not change the translated text
|
|
14
|
-
* of messages that have already been translated.
|
|
15
|
-
*
|
|
16
|
-
* The message IDs and translations are in the same format as that rendered to "simple JSON"
|
|
17
|
-
* translation files when extracting messages. In particular, placeholders in messages are rendered
|
|
18
|
-
* using the `{$PLACEHOLDER_NAME}` syntax. For example the message from the following template:
|
|
19
|
-
*
|
|
20
|
-
* ```html
|
|
21
|
-
* <div i18n>pre<span>inner-pre<b>bold</b>inner-post</span>post</div>
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* would have the following form in the `translations` map:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* {
|
|
28
|
-
* "2932901491976224757":
|
|
29
|
-
* "pre{$START_TAG_SPAN}inner-pre{$START_BOLD_TEXT}bold{$CLOSE_BOLD_TEXT}inner-post{$CLOSE_TAG_SPAN}post"
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param translations A map from message ID to translated message.
|
|
34
|
-
*
|
|
35
|
-
* These messages are processed and added to a lookup based on their `MessageId`.
|
|
36
|
-
*
|
|
37
|
-
* @see `clearTranslations()` for removing translations loaded using this function.
|
|
38
|
-
* @see `$localize` for tagging messages as needing to be translated.
|
|
39
|
-
* @publicApi
|
|
40
|
-
*/
|
|
41
|
-
export declare function loadTranslations(translations: Record<MessageId, TargetMessage>): void;
|
|
42
|
-
/**
|
|
43
|
-
* Remove all translations for `$localize`, if doing runtime translation.
|
|
44
|
-
*
|
|
45
|
-
* All translations that had been loading into memory using `loadTranslations()` will be removed.
|
|
46
|
-
*
|
|
47
|
-
* @see `loadTranslations()` for loading translations at runtime.
|
|
48
|
-
* @see `$localize` for tagging messages as needing to be translated.
|
|
49
|
-
*
|
|
50
|
-
* @publicApi
|
|
51
|
-
*/
|
|
52
|
-
export declare function clearTranslations(): void;
|
|
53
|
-
/**
|
|
54
|
-
* Translate the text of the given message, using the loaded translations.
|
|
55
|
-
*
|
|
56
|
-
* This function may reorder (or remove) substitutions as indicated in the matching translation.
|
|
57
|
-
*/
|
|
58
|
-
export declare function translate(messageParts: TemplateStringsArray, substitutions: readonly any[]): [
|
|
59
|
-
TemplateStringsArray,
|
|
60
|
-
readonly any[]
|
|
61
|
-
];
|
package/src/utils/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
export * from './src/constants';
|
|
9
|
-
export * from './src/messages';
|
|
10
|
-
export * from './src/translations';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* The character used to mark the start and end of a "block" in a `$localize` tagged string.
|
|
10
|
-
* A block can indicate metadata about the message or specify a name of a placeholder for a
|
|
11
|
-
* substitution expressions.
|
|
12
|
-
*
|
|
13
|
-
* For example:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* $localize`Hello, ${title}:title:!`;
|
|
17
|
-
* $localize`:meaning|description@@id:source message text`;
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare const BLOCK_MARKER = ":";
|
|
21
|
-
/**
|
|
22
|
-
* The marker used to separate a message's "meaning" from its "description" in a metadata block.
|
|
23
|
-
*
|
|
24
|
-
* For example:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* $localize `:correct|Indicates that the user got the answer correct: Right!`;
|
|
28
|
-
* $localize `:movement|Button label for moving to the right: Right!`;
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare const MEANING_SEPARATOR = "|";
|
|
32
|
-
/**
|
|
33
|
-
* The marker used to separate a message's custom "id" from its "description" in a metadata block.
|
|
34
|
-
*
|
|
35
|
-
* For example:
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* $localize `:A welcome message on the home page@@myApp-homepage-welcome: Welcome!`;
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const ID_SEPARATOR = "@@";
|
|
42
|
-
/**
|
|
43
|
-
* The marker used to separate legacy message ids from the rest of a metadata block.
|
|
44
|
-
*
|
|
45
|
-
* For example:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* $localize `:@@custom-id␟2df64767cd895a8fabe3e18b94b5b6b6f9e2e3f0: Welcome!`;
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* Note that this character is the "symbol for the unit separator" (␟) not the "unit separator
|
|
52
|
-
* character" itself, since that has no visual representation. See https://graphemica.com/%E2%90%9F.
|
|
53
|
-
*
|
|
54
|
-
* Here is some background for the original "unit separator character":
|
|
55
|
-
* https://stackoverflow.com/questions/8695118/whats-the-file-group-record-unit-separator-control-characters-and-its-usage
|
|
56
|
-
*/
|
|
57
|
-
export declare const LEGACY_ID_INDICATOR = "\u241F";
|
|
@@ -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;
|