From e2acbb823d159cdeb9bffe844d9942f18fd4c45e Mon Sep 17 00:00:00 2001 From: Peter Laske <37439758+laske185@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:19:41 +0100 Subject: [PATCH] feat: i18nextService uses namespace "KoliBri" Closes: #5572 --- packages/components/src/core/i18n.ts | 17 ++++++++++++----- packages/components/src/core/index.ts | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/components/src/core/i18n.ts b/packages/components/src/core/i18n.ts index 056bb6b6f0..1b3b8194ce 100644 --- a/packages/components/src/core/i18n.ts +++ b/packages/components/src/core/i18n.ts @@ -32,10 +32,11 @@ export interface II18nService { export class I18nextService implements II18nService { private static instance: II18nService; + private static namespace = 'KoliBri'; private constructor() {} - public static async getInstance( + public static async createInstance( lng: Generic.I18n.Locale.ISO_639_1, translations?: | Generic.I18n.RegisterPatch @@ -50,9 +51,14 @@ export class I18nextService implements II18nService { I18nextService.instance = new I18nextService(); - await i18next.init({ - lng, - }); + if (!i18next.isInitialized) { + await i18next.init({ + ns: [I18nextService.namespace], + lng, + }); + } else { + await i18next.loadNamespaces(I18nextService.namespace); + } if (translations !== undefined) { translations.forEach((t) => @@ -67,7 +73,7 @@ export class I18nextService implements II18nService { } public static addResourceBundle(lng: Generic.I18n.Locale.ISO_639_1, translationMap: Generic.I18n.Map) { - i18next.addResourceBundle(lng, 'translation', translationMap, true); + i18next.addResourceBundle(lng, I18nextService.namespace, translationMap, true); } public addResourceBundle(lng: Generic.I18n.Locale.ISO_639_1, translationMap: Generic.I18n.Map) { @@ -76,6 +82,7 @@ export class I18nextService implements II18nService { public translate(key: string, options?: ITranslationOptions) { return i18next.t(key, { + ns: I18nextService.namespace, count: options?.count, ...options?.placeholders, }); diff --git a/packages/components/src/core/index.ts b/packages/components/src/core/index.ts index 74e7f8ccc5..db4a9d3a8e 100644 --- a/packages/components/src/core/index.ts +++ b/packages/components/src/core/index.ts @@ -12,7 +12,7 @@ export const register = async ( options?: RegisterOptions ): Promise => { if (STORE.I18n === undefined) { - const i18n = await I18nextService.getInstance(options?.translation?.name ?? 'de', options?.translations); + const i18n = await I18nextService.createInstance(options?.translation?.name ?? 'de', options?.translations); Object.defineProperty(STORE, 'I18n', { value: i18n, writable: false,