SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
736 stars 380 forks source link

Use async translations in TS code - parent components of CardComponent #2192

Closed Platonn closed 5 years ago

Platonn commented 5 years ago

Example:

getCardContent({
    defaultPayment,
    accountHolderName,
    expiryMonth,
    expiryYear,
    cardNumber,
  }: PaymentDetails): Observable<Card> {
    return combineLatest([
      this.translation.translate('common.setAsDefault'),
      this.translation.translate('common.delete'),
      this.translation.translate('paymentMethods.deleteConfirmation'),
      this.translation.translate('paymentForm.expires', {
        month: expiryMonth,
        year: expiryYear,
      }),
    ]).pipe(
      map(
        ([
          textSetAsDefault,
          textDelete,
          textDeleteConfirmation,
          textExpires,
        ]) => {
          .....

          return card;
        }
      )
    );
  }

Note: add async pipe in the template:

<cx-card
              [border]="true"
              [fitToContainer]="true"
              [content]="getCardContent(paymentMethod) | async"   <===================
              (deleteCard)="deletePaymentMethod(paymentMethod)"
              (setDefaultCard)="setDefaultPaymentMethod(paymentMethod)"
              (editCard)="setEdit(paymentMethod)"
              [editMode]="editCard === paymentMethod.id"
              (cancelCard)="cancelCard()"
            ></cx-card>
mirkosoft commented 5 years ago

This ticket is for unblocking #1809