0

I want to translate messages in my angular2 material snackbars. Problem is to show snackbar I need to pass message as parameter. To translate using i18n: https://angular.io/api/common/I18nSelectPipe . I can't use interpolation as parameter. So how I can transform my message in snackbar?

<button md-button (click)="openSnackBar(message, action)">Show snack-bar</button>

https://plnkr.co/edit/H6rrayAUhBuCx3JOuDCF?p=preview

kipris
  • 2,899
  • 3
  • 20
  • 28

1 Answers1

1

You can use it explicity by calling tranform method on new instance of pipe:

import { I18nSelectPipe } from '@angular/common';

const msg = new I18nSelectPipe().transform(message, this.inviteMap);

Plunker Example

yurzui
  • 205,937
  • 32
  • 433
  • 399
  • Ok, I tried to modify your example and create Injectable for Pipe https://plnkr.co/edit/qlcX8g4YX1IKSuktYfRc?p=preview It works good for DatePipe but I have problem with i18nSelectPipe. Can you explain me what's wrong? – kipris Oct 03 '17 at 08:53
  • 1
    You didn't provide services https://plnkr.co/edit/hWmmZt3ZpUD8tz92Ufqg?p=preview Can you show me example with DatePipe? – yurzui Oct 03 '17 at 08:55
  • Thanks, your answer helped me a lot! :) – kipris Oct 03 '17 at 09:32