super bird
super bird

Reputation: 19

ngxtranslate to translate popup from Javascript can't work

Onclick my request, the content Are you sure? is not changing to the required language.

list.component.html

<button type="button" (click)="myrequest(item.Id)">Request View</button>

list.component.ts

myrequest((Id: number));
{
  this.notificationService.smartMessageBox(
    {
      title: "Warning",
      content: "{{ 'Are you sure?' | translate }}",
      buttons: "[No][Yes]"
    },
    ButtonPressed => {
      if (ButtonPressed === "Yes") {
        this.loading = true;
        this.FurtherRequest(projectId).subscribe((data: any) => {
          this.loading = false;
          if (data.Success) {
            this.notificationService.successMessage("request submitted");
          } else {
            this.notificationService.errorMessage(data.Message);
          }
        });
      }
      if (ButtonPressed === "No") {
      }
    }
  );
}

list.module.ts

import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
    
imports: [
  TranslateModule],

exports: [
  TranslateModule],

Unable to translate things inside js

Upvotes: 0

Views: 580

Answers (2)

Jiri Kralovec
Jiri Kralovec

Reputation: 1627

Pipes do not work like this. You need to use translateService.get or translateService.instant to get a translation programatically.

Upvotes: 1

Surya Teja
Surya Teja

Reputation: 1526

You need to pass a parameter to translate pipe inside js file.

{{  'Are you sure?' | translate :param }}

Upvotes: 1

Related Questions