0

I've got my custom formats

{
  number: {
    USD: {
       style: 'currency',
       currency: 'USD',
    },
    EUR: {
       style: 'currency',
       currency: 'EUR',
    },
  },
}

and I want to create an ICU message so that I could pass currency as a parameter:

formatMessage(message, {amount: 40, currency: 'EUR'})

I would imagine something like this:

{amount, number, {currency}}

but it doesn't work.

lukasbalaz7
  • 360
  • 2
  • 11

1 Answers1

0

Embedding placeholders into the style argument doesn't seem to be supported by the DecimalFormat specification, so I can only assume not supported by the React implementation either.

ICU MessageFormat has a currency formatter built in which would use the locale data it has available, so for a Eurozone locale, you just need {amount,number,currency}.

If your "custom formats" data is available to the formatter, then perhaps that works? I've not tried it as I don't develop in React.

Tim
  • 8,036
  • 2
  • 36
  • 52