From cb3d49fb17748941250bb54f86b86a16dad83af9 Mon Sep 17 00:00:00 2001 From: Adjilino Date: Wed, 14 Jun 2023 17:14:26 +0000 Subject: [PATCH 1/3] Fix extend module load --- packages/core/lib/translate.service.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/core/lib/translate.service.ts b/packages/core/lib/translate.service.ts index 656689d..2e8b6c4 100644 --- a/packages/core/lib/translate.service.ts +++ b/packages/core/lib/translate.service.ts @@ -161,19 +161,23 @@ export class TranslateService { @Inject(DEFAULT_LANGUAGE) defaultLanguage: string) { /** set the default language from configuration */ if (defaultLanguage) { - this.setDefaultLang(defaultLanguage); + this.setDefaultLang(defaultLanguage, this.extend); + } + + if (this.extend) { + this.use(this.currentLang); } } /** * Sets the default language to use as a fallback */ - public setDefaultLang(lang: string): void { - if (lang === this.defaultLang) { + public setDefaultLang(lang: string, forceLoad: boolean = false): void { + if (lang === this.defaultLang && !forceLoad) { return; } - let pending = this.retrieveTranslations(lang); + let pending = this.retrieveTranslations(lang, forceLoad); if (typeof pending !== "undefined") { // on init set the defaultLang immediately @@ -200,13 +204,13 @@ export class TranslateService { /** * Changes the lang currently used */ - public use(lang: string): Observable { + public use(lang: string, forceLoad: boolean = false): Observable { // don't change the language if the language given is already selected - if (lang === this.currentLang) { + if (lang === this.currentLang && !forceLoad) { return of(this.translations[lang]); } - let pending = this.retrieveTranslations(lang); + let pending = this.retrieveTranslations(lang, forceLoad); if (typeof pending !== "undefined") { // on init set the currentLang immediately @@ -230,7 +234,11 @@ export class TranslateService { /** * Retrieves the given translations */ - private retrieveTranslations(lang: string): Observable | undefined { + private retrieveTranslations(lang: string, forceLoad: boolean = false): Observable | undefined { + if (forceLoad) { + return this.getTranslation(lang); + } + let pending: Observable | undefined; // if this language is unavailable or extend is true, ask for it From 2275b25d02bd1ed82bc1f4cbaf82bd51b7d00d7a Mon Sep 17 00:00:00 2001 From: Adjilino Date: Wed, 14 Jun 2023 18:12:04 +0000 Subject: [PATCH 2/3] fix: missing force for current language --- packages/core/lib/translate.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/lib/translate.service.ts b/packages/core/lib/translate.service.ts index 2e8b6c4..d15ff83 100644 --- a/packages/core/lib/translate.service.ts +++ b/packages/core/lib/translate.service.ts @@ -165,7 +165,7 @@ export class TranslateService { } if (this.extend) { - this.use(this.currentLang); + this.use(this.currentLang, true); } } From 7d82c84740d3330ec40cc03249679d20e51813f7 Mon Sep 17 00:00:00 2001 From: Adjilino Date: Thu, 15 Jun 2023 19:01:50 +0000 Subject: [PATCH 3/3] revert public method --- packages/core/lib/translate.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/lib/translate.service.ts b/packages/core/lib/translate.service.ts index d15ff83..8c0ff71 100644 --- a/packages/core/lib/translate.service.ts +++ b/packages/core/lib/translate.service.ts @@ -161,18 +161,22 @@ export class TranslateService { @Inject(DEFAULT_LANGUAGE) defaultLanguage: string) { /** set the default language from configuration */ if (defaultLanguage) { - this.setDefaultLang(defaultLanguage, this.extend); + this._setDefaultLang(defaultLanguage, this.extend); } if (this.extend) { - this.use(this.currentLang, true); + this._use(this.currentLang, true); } } /** * Sets the default language to use as a fallback */ - public setDefaultLang(lang: string, forceLoad: boolean = false): void { + public setDefaultLang(lang: string): void { + this._setDefaultLang(lang); + } + + protected _setDefaultLang(lang: string, forceLoad: boolean = false): void { if (lang === this.defaultLang && !forceLoad) { return; } @@ -204,7 +208,11 @@ export class TranslateService { /** * Changes the lang currently used */ - public use(lang: string, forceLoad: boolean = false): Observable { + public use(lang: string): Observable { + return this._use(lang); + } + + protected _use(lang: string, forceLoad: boolean = false): Observable { // don't change the language if the language given is already selected if (lang === this.currentLang && !forceLoad) { return of(this.translations[lang]);