(translations: Record<MessageId, TargetMessage>)
| 62 | * @publicApi |
| 63 | */ |
| 64 | export 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. |
no test coverage detected