diff --git a/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts b/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts index 6c0865f..1705da6 100644 --- a/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts +++ b/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts @@ -24,8 +24,10 @@ export class TranslateServiceMock { languages: string[] = ['de']; - get(content: string): Observable { - return of(TRANSLATED_STRING + content); + get(content: string | Array, interpolateParams?: Object): Observable { + return typeof content === 'string' + ? of(TRANSLATED_STRING + content) + : of(this._translateArray(content)); } use(lang: string): void { @@ -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, 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 { + return content.reduce((result, item) => { + result[item] = TRANSLATED_STRING + item; + return result; + }, {} as Record); + } }