Skip to content

Unit and currency formatting should be supported #838

Closed
@eemeli

Description

@eemeli

During the February meetings, we ended up leaving out the :number style values currency and unit, and their related options: currency, currencyDisplay, currencySign, unit, unitDisplay.

Furthermore, we also include this direction in the spec:

Implementations SHOULD avoid creating options that conflict with these, but are encouraged to track development of these options during Tech Preview.

We should work towards supporting currency and unit formatting in MF2; hence this issue. Looking back to the discussions (also #621) on this topic, it would be good to get input on the parameters of an acceptable solution. To that end, I'm adding assignees here who have been vocal on the topic previously; also CC @ryzokuken.


To get us started, I propose that we re-add all the options currently left out of the tech preview, except for currency and unit. This would mean that in order to use currency or unit formatting, the operand of the :number function would need to include the appropriate currency or unit in addition to its value, and that supporting this would be left to each implementation.

For example, in the JS implementation this could work like this:

const mf = new MessageFormat('en', 'Your total is {$cost :number style=currency}')
const cost = { valueOf: () => 42, options: { currency: 'EUR' } }
mf.format({ cost }) // → 'Your total is €42.00'

With this approach, the placeholder that the translator sees would show that it's a formatted currency, but they would not be able to set the currency; that is provided in the operand.

As we do not specify the formatted results, a conformant implementation could choose to not support currency or unit formatting, and to ignore the relevant options.

We may also want to consider enforcing exact selection when style is not decimal, as plural or ordinal selection on currency or unit values does not really make sense. Edit: I was wrong, see discussion below.

Metadata

Metadata

Labels

LDML46.1MF2.0 Draft Candidateblocker-candidateThe submitter thinks this might be a block for the next releasefunctionsIssue pertains to the default function setresolve-candidateThis issue appears to have been answered or resolved, and may be closed soon.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions