@@ -17,21 +17,43 @@ import {MessageId, ParsedTranslation, parseTranslation, TargetMessage, translate
1717declare const $localize : LocalizeFn & { TRANSLATIONS : Record < MessageId , ParsedTranslation > } ;
1818
1919/**
20- * Load translations for `$localize`.
20+ * Load translations for use by `$localize`, if doing runtime translation .
2121 *
22- * The given `translations` are processed and added to a lookup based on their `MessageId`.
23- * A new translation will overwrite a previous translation if it has the same `MessageId`.
22+ * If the `$localize` tagged strings are not going to be replaced at compiled time, it is possible
23+ * to load a set of translations that will be applied to the `$localize` tagged strings at runtime,
24+ * in the browser.
2425 *
25- * * If a message is generated by the Angular compiler from an `i18n` marker in a template, the
26- * `MessageId` is passed through to the `$localize` call as a custom `MessageId`. The `MessageId`
27- * will match what is extracted into translation files.
26+ * Loading a new translation will overwrite a previous translation if it has the same `MessageId`.
2827 *
29- * * If the translation is from a call to `$localize` in application code, and no custom `MessageId`
30- * is provided, then the `MessageId` can be generated by passing the tagged string message-parts
31- * to the `parseMessage()` function (not currently public API).
28+ * Note that `$localize` messages are only processed once, when the tagged string is first
29+ * encountered, and does not provide dynamic language changing without refreshing the browser.
30+ * Loading new translations later in the application life-cycle will not change the translated text
31+ * of messages that have already been translated.
3232 *
33- * @publicApi
33+ * The message IDs and translations are in the same format as that rendered to "simple JSON"
34+ * translation files when extracting messages. In particular, placeholders in messages are rendered
35+ * using the `{$PLACEHOLDER_NAME}` syntax. For example the message from the following template:
36+ *
37+ * ```html
38+ * <div i18n>pre<span>inner-pre<b>bold</b>inner-post</span>post</div>
39+ * ```
40+ *
41+ * would have the following form in the `translations` map:
42+ *
43+ * ```ts
44+ * {
45+ * "2932901491976224757":
46+ * "pre{$START_TAG_SPAN}inner-pre{$START_BOLD_TEXT}bold{$CLOSE_BOLD_TEXT}inner-post{$CLOSE_TAG_SPAN}post"
47+ * }
48+ * ```
49+ *
50+ * @param translations A map from message ID to translated message.
3451 *
52+ * These messages are processed and added to a lookup based on their `MessageId`.
53+ *
54+ * @see `clearTranslations()` for removing translations loaded using this function.
55+ * @see `$localize` for tagging messages as needing to be translated.
56+ * @publicApi
3557 */
3658export function loadTranslations ( translations : Record < MessageId , TargetMessage > ) {
3759 // Ensure the translate function exists
@@ -47,7 +69,12 @@ export function loadTranslations(translations: Record<MessageId, TargetMessage>)
4769}
4870
4971/**
50- * Remove all translations for `$localize`.
72+ * Remove all translations for `$localize`, if doing runtime translation.
73+ *
74+ * All translations that had been loading into memory using `loadTranslations()` will be removed.
75+ *
76+ * @see `loadTranslations()` for loading translations at runtime.
77+ * @see `$localize` for tagging messages as needing to be translated.
5178 *
5279 * @publicApi
5380 */
0 commit comments