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 service configuration with isolate = true #531

Open
wants to merge 2 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
26 changes: 9 additions & 17 deletions src/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export class TranslateService {
private loadingTranslations: Observable<any>;
private pending: boolean = false;
private _onTranslationChange: EventEmitter<TranslationChangeEvent> = new EventEmitter<TranslationChangeEvent>();
private _onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
private _onDefaultLangChange: EventEmitter<DefaultLangChangeEvent> = new EventEmitter<DefaultLangChangeEvent>();
private _defaultLang: string;
private _currentLang: string;
private _langs: Array<string> = [];
private _translations: any = {};
Expand All @@ -68,7 +65,7 @@ export class TranslateService {
* @type {EventEmitter<LangChangeEvent>}
*/
get onLangChange(): EventEmitter<LangChangeEvent> {
return this.isolate ? this._onLangChange : this.store.onLangChange;
return this.store.onLangChange;
}

/**
Expand All @@ -79,38 +76,30 @@ export class TranslateService {
* @type {EventEmitter<DefaultLangChangeEvent>}
*/
get onDefaultLangChange() {
return this.isolate ? this._onDefaultLangChange : this.store.onDefaultLangChange;
return this.store.onDefaultLangChange;
}

/**
* The default lang to fallback when translations are missing on the current lang
*/
get defaultLang(): string {
return this.isolate ? this._defaultLang : this.store.defaultLang;
return this.store.defaultLang;
}

set defaultLang(defaultLang: string) {
if(this.isolate) {
this._defaultLang = defaultLang;
} else {
this.store.defaultLang = defaultLang;
}
this.store.defaultLang = defaultLang;
}

/**
* The lang currently used
* @type {string}
*/
get currentLang(): string {
return this.isolate ? this._currentLang : this.store.currentLang;
return this.store.currentLang;
}

set currentLang(currentLang: string) {
if(this.isolate) {
this._currentLang = currentLang;
} else {
this.store.currentLang = currentLang;
}
this.store.currentLang = currentLang;
}

/**
Expand Down Expand Up @@ -158,6 +147,9 @@ export class TranslateService {
public parser: TranslateParser,
public missingTranslationHandler: MissingTranslationHandler,
@Inject(USE_STORE) private isolate: boolean = false) {
if(this.currentLang) {
this.retrieveTranslations(this.currentLang);
}
}

/**
Expand Down