Skip to content

Commit

Permalink
fix: get and instant adjustet to actual interface
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeF0x committed Dec 13, 2022
1 parent d0a73f2 commit f848dc8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export class TranslateServiceMock {

languages: string[] = ['de'];

get(content: string): Observable<string> {
return of(TRANSLATED_STRING + content);
get(content: string | Array<string>, interpolateParams?: Object): Observable<string | any> {
return typeof content === 'string'
? of(TRANSLATED_STRING + content)
: of(this._translateArray(content));
}

use(lang: string): void {
Expand All @@ -50,11 +52,20 @@ export class TranslateServiceMock {
return of({});
}

instant(key: string | string[], interpolateParams?: object): string {
return TRANSLATED_STRING + key.toString();
}
instant(content: string | Array<string>, interpolateParams?: Object): string | any {
return typeof content === 'string'
? TRANSLATED_STRING + content
: this._translateArray(content);
}

setDefaultLang(lang: string): void {
this.onDefaultLangChangeSubject.next(lang);
}

private _translateArray(content: string[]): Record<string, string> {
return content.reduce((result, item) => {
result[item] = TRANSLATED_STRING + item;
return result;
}, {} as Record<string, string>);
}
}

0 comments on commit f848dc8

Please sign in to comment.