{ "id": "api/localize/loadTranslations", "title": "loadTranslations", "contents": "\n\n
\n
\n
\n \n API > @angular/localize\n
\n \n
\n \n
\n

loadTranslationslink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

Load translations for use by $localize, if doing runtime translation.

\n\n

See more...

\n
\n \n \n \n\n
\n \n\n loadTranslations(translations: Record<string, string>)\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n translations\n Record\n

A map from message ID to translated message.

\n

These messages are processed and added to a lookup based on their MessageId.

\n\n
\n\n \n\n\n \n\n \n
\n\n\n \n
\n

See alsolink

\n
    \n \n
  • clearTranslations() for removing translations loaded using this function.

    \n
  • \n
  • $localize for tagging messages as needing to be translated.

    \n
  • \n
\n
\n\n\n \n\n
\n

Descriptionlink

\n

If the $localize tagged strings are not going to be replaced at compiled time, it is possible\nto load a set of translations that will be applied to the $localize tagged strings at runtime,\nin the browser.

\n

Loading a new translation will overwrite a previous translation if it has the same MessageId.

\n

Note that $localize messages are only processed once, when the tagged string is first\nencountered, and does not provide dynamic language changing without refreshing the browser.\nLoading new translations later in the application life-cycle will not change the translated text\nof messages that have already been translated.

\n

The message IDs and translations are in the same format as that rendered to \"simple JSON\"\ntranslation files when extracting messages. In particular, placeholders in messages are rendered\nusing the {$PLACEHOLDER_NAME} syntax. For example the message from the following template:

\n\n<div i18n>pre<span>inner-pre<b>bold</b>inner-post</span>post</div>\n\n

would have the following form in the translations map:

\n\n{\n \"2932901491976224757\":\n \"pre{$START_TAG_SPAN}inner-pre{$START_BOLD_TEXT}bold{$CLOSE_BOLD_TEXT}inner-post{$CLOSE_TAG_SPAN}post\"\n}\n\n\n \n
\n\n\n\n \n\n\n
\n
\n\n\n" }