From c089f1ed862631ef4058a0889cb56ba3132d5f8c Mon Sep 17 00:00:00 2001 From: Said MARAR Date: Mon, 9 Nov 2020 16:31:06 +0100 Subject: [PATCH] feat(pipe): add option to pipe to accept an array of string --- .../ngx-translate/core/src/lib/translate.pipe.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/ngx-translate/core/src/lib/translate.pipe.ts b/projects/ngx-translate/core/src/lib/translate.pipe.ts index b1f4ea3c..148640be 100644 --- a/projects/ngx-translate/core/src/lib/translate.pipe.ts +++ b/projects/ngx-translate/core/src/lib/translate.pipe.ts @@ -37,11 +37,15 @@ export class TranslatePipe implements PipeTransform, OnDestroy { this.translate.get(key, interpolateParams).subscribe(onTranslation); } - transform(query: string, ...args: any[]): any { + transform(query: string|string[], ...args: any[]): any { if (!query || !query.length) { return query; } + if (Array.isArray(query)) { + return this.transformArray(query, args); + } + // if we ask another time for the same key, return the last value if (equals(query, this.lastKey) && equals(args, this.lastParams)) { return this.value; @@ -110,6 +114,12 @@ export class TranslatePipe implements PipeTransform, OnDestroy { return this.value; } + transformArray(queries: string[], ...args: any[]): any { + return queries + .map( query => this.transform(query, args)) + .join(''); + } + /** * Clean any existing subscription to change events */