Merged in fix/SW-3021-vouchers (pull request #2719)
fix(SW-3021): add pluralization support for vouchers * fix(SW-3021): add pluralization support for vouchers Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { CurrencyEnum } from "../constants/currency"
|
||||
|
||||
import type { IntlShape } from "react-intl"
|
||||
|
||||
/**
|
||||
@@ -21,7 +23,7 @@ export function getSingleDecimal(n: Number | string) {
|
||||
export function formatPrice(
|
||||
intl: IntlShape,
|
||||
price: number,
|
||||
currency: string,
|
||||
currency: string | CurrencyEnum,
|
||||
additionalPrice?: number,
|
||||
additionalPriceCurrency?: string
|
||||
) {
|
||||
@@ -37,5 +39,18 @@ export function formatPrice(
|
||||
formattedAdditionalPrice = ` + ${localizedAdditionalPrice} ${additionalPriceCurrency}`
|
||||
}
|
||||
|
||||
return `${localizedPrice} ${currency}${formattedAdditionalPrice}`
|
||||
const currencyText =
|
||||
currency === CurrencyEnum.Voucher
|
||||
? intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
"{numberOfVouchers, plural, one {Voucher} other {Vouchers}}",
|
||||
},
|
||||
{
|
||||
numberOfVouchers: price,
|
||||
}
|
||||
)
|
||||
: currency
|
||||
|
||||
return `${localizedPrice} ${currencyText}${formattedAdditionalPrice}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user