From ff09f684e232cc5273571a643928f410456856cf Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Wed, 22 Apr 2020 00:36:43 +0300 Subject: [PATCH] feat: add a mock localization pipe --- .../core/src/lib/pipes/localization.pipe.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts index 06fc5d5f02..79fa5a81ec 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/localization.pipe.ts @@ -1,4 +1,4 @@ -import { Pipe, PipeTransform, Injectable } from '@angular/core'; +import { Injectable, Pipe, PipeTransform } from '@angular/core'; import { Store } from '@ngxs/store'; import { Config } from '../models'; import { ConfigState } from '../states'; @@ -10,12 +10,28 @@ import { ConfigState } from '../states'; export class LocalizationPipe implements PipeTransform { constructor(private store: Store) {} - transform(value: string | Config.LocalizationWithDefault = '', ...interpolateParams: string[]): string { + transform( + value: string | Config.LocalizationWithDefault = '', + ...interpolateParams: string[] + ): string { return this.store.selectSnapshot( ConfigState.getLocalization( value, - ...interpolateParams.reduce((acc, val) => (Array.isArray(val) ? [...acc, ...val] : [...acc, val]), []), + ...interpolateParams.reduce( + (acc, val) => (Array.isArray(val) ? [...acc, ...val] : [...acc, val]), + [], + ), ), ); } } + +@Injectable() +@Pipe({ + name: 'abpLocalization', +}) +export class MockLocalizationPipe implements PipeTransform { + transform(value: string | Config.LocalizationWithDefault = '', ..._: string[]) { + return typeof value === 'string' ? value : value.defaultValue; + } +}