From 101c8eb4c39d5330635cad1562e3e29dad40f6a2 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev <haiodo@users.noreply.github.com> Date: Mon, 28 Feb 2022 10:42:34 +0700 Subject: [PATCH] Load i18n on Start (#1069) Signed-off-by: Andrey Sobolev <haiodo@gmail.com> --- packages/platform/src/i18n.ts | 14 ++++++++++++++ packages/theme/src/Theme.svelte | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/platform/src/i18n.ts b/packages/platform/src/i18n.ts index a4d6ee73d5..5b5902a976 100644 --- a/packages/platform/src/i18n.ts +++ b/packages/platform/src/i18n.ts @@ -43,6 +43,20 @@ export function addStringsLoader (plugin: Plugin, loader: Loader): void { loaders.set(plugin, loader) } +/** + * Perform load of all internationalization sources for all plugins available. + * @public + */ +export async function loadPluginStrings (locale: string): Promise<void> { + for (const [plugin] of loaders) { + let messages = translations.get(plugin) + if (messages === undefined) { + messages = await loadTranslationsForComponent(plugin, locale) + translations.set(plugin, messages) + } + } +} + async function loadTranslationsForComponent (plugin: Plugin, locale: string): Promise<Messages | Status> { const loader = loaders.get(plugin) if (loader === undefined) { diff --git a/packages/theme/src/Theme.svelte b/packages/theme/src/Theme.svelte index bd7ce706e0..97f7fc9b56 100644 --- a/packages/theme/src/Theme.svelte +++ b/packages/theme/src/Theme.svelte @@ -15,7 +15,7 @@ <script lang="ts"> import { setContext, onMount } from 'svelte' - import platform, { setMetadata } from '@anticrm/platform' + import platform, { loadPluginStrings, setMetadata } from '@anticrm/platform' const getCurrentTheme = (): string => localStorage.getItem('theme') ?? 'theme-dark' const getCurrnetFontSize = (): string => localStorage.getItem('fontsize') ?? 'normal-font' @@ -58,6 +58,7 @@ setRootColors(currentTheme) setRootFontSize(currentFontSize) setMetadata(platform.metadata.locale, currentLanguage) + loadPluginStrings(currentLanguage) }) </script>