Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extend module load #1428

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions packages/core/lib/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,27 @@ 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, true);
}
}

/**
* Sets the default language to use as a fallback
*/
public setDefaultLang(lang: string): void {
if (lang === this.defaultLang) {
this._setDefaultLang(lang);
}

protected _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
Expand Down Expand Up @@ -201,12 +209,16 @@ export class TranslateService {
* Changes the lang currently used
*/
public use(lang: string): Observable<any> {
return this._use(lang);
}

protected _use(lang: string, forceLoad: boolean = false): Observable<any> {
// 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
Expand All @@ -230,7 +242,11 @@ export class TranslateService {
/**
* Retrieves the given translations
*/
private retrieveTranslations(lang: string): Observable<any> | undefined {
private retrieveTranslations(lang: string, forceLoad: boolean = false): Observable<any> | undefined {
if (forceLoad) {
return this.getTranslation(lang);
}

let pending: Observable<any> | undefined;

// if this language is unavailable or extend is true, ask for it
Expand Down