Sandeep Singh Saini
Sandeep Singh Saini

Reputation: 13

Translate sweet alert title and messages using ngx translate service in the Ts file

How to translate the title and text using translate service in the Ts file. The service name is translate

   // Delete Address Confirmation
  onDeleteConfirm(address) {
    swal.fire({
      title: 'Are you sure?',
      // title: "'are-you-sure' | translate",
      text: "You won't be able to revert this!",
      type: 'warning',
      showCancelButton: true,
      allowOutsideClick: false,
      confirmButtonColor: this.baseService.storeTheme,
      // cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, delete it!',
      customClass: {
        confirmButton: 'confirm-button-class',
        cancelButton: 'cancel-button-class'
      },
    }).then((result) => {
      if (result.value) {
        this.deleteAddress(address);
      }
    })
  }

Upvotes: 1

Views: 1292

Answers (1)

Aldin Bradaric
Aldin Bradaric

Reputation: 793

You import your servive first, ie

constructor(private translate: TranslateService) { ... }

And then you use the service by calling the instant method, ie

this.translate.instant('property-key');

See the official documentation for more on that.

Upvotes: 1

Related Questions