import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

@Pipe({
  name: 'dynamicTranslate'
})
export class DynamicTranslatePipe implements PipeTransform {

  constructor(private translateService: TranslateService) {

  }

  transform(value: any, ...args: any[]): any {
    let lang = this.translateService.currentLang ? this.translateService.currentLang : this.translateService.defaultLang;
    let traductions = JSON.parse(args[0].param);

    if (traductions[lang]) {
      return traductions[lang];
    } else {
      return value;

    }
  }

}
