MCPcopy Create free account
hub / github.com/angular/angular / loadTranslations

Function loadTranslations

packages/localize/src/translate.ts:64–79  ·  view source on GitHub ↗
(translations: Record<MessageId, TargetMessage>)

Source from the content-addressed store, hash-verified

62 * @publicApi
63 */
64export function loadTranslations(translations: Record<MessageId, TargetMessage>) {
65 // Ensure the translate function exists
66 if (!$localize.translate) {
67 $localize.translate = translate;
68 }
69 if (!$localize.TRANSLATIONS) {
70 // Keyed by message ID, which is taken verbatim from the `translations` map (e.g. parsed from a
71 // translation file), so it can be `__proto__`. Indexing a plain object with that key assigns
72 // through the inherited `__proto__` setter, reparenting the map instead of storing the entry
73 // (and throwing under `--disable-proto=throw`). A null-prototype map makes it an ordinary key.
74 $localize.TRANSLATIONS = Object.create(null);
75 }
76 Object.keys(translations).forEach((key) => {
77 $localize.TRANSLATIONS[key] = parseTranslation(translations[key]);
78 });
79}
80
81/**
82 * Remove all translations for `$localize`, if doing runtime translation.

Callers 7

i18n_spec.tsFile · 0.90
hmr_spec.tsFile · 0.90
content_spec.tsFile · 0.90
translate_spec.tsFile · 0.85

Calls 4

parseTranslationFunction · 0.90
createMethod · 0.65
keysMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected