eversport / intl-codegen

generate code and type definitions from translations
MIT License
15 stars 1 forks source link

Add nice currency formatting support #14

Closed Swatinem closed 5 years ago

Swatinem commented 5 years ago

The support for currency formatting in messageformat is lacking :-( https://formatjs.io/guides/message-syntax/#custom-formats

I propose the following special custom formats (assuming locale de):

All permutations of these should be supported, for example currencycode0:$code

Examples:

Swatinem commented 5 years ago

Now that I thought more about this, and also looked at how fluent does currency formatting, I think it would be a good idea to just introduce a proper currency type, which is defined as {value: number, code: ISO4217 | string} and always define the currency via code instead of via the translation.

So what is left would be:

declare const price: { value: number, code: string }
const translations = [
  "{price, number, currency}",
  "{price, number, currency0}",
  "{price, number, currencycode}",
]