message-format-wg
message-format-wg copied to clipboard
Spec clarification: selection without a function
The current spec allows this:
match {$foo}
when 1 {...}
when one {...}
when male {...}
when foggy {...}
when * {...}
I would argue that this is both useless and dangerous.
First the utility.
As a translator if I see match {$foo} * {...} I have absolutely no idea what kind of options I can add.
Gender options? Plural options? Something else?
Danger This can't be linted, as the type is not available. And at runtime it might have unexpected side effects, especially in some languages. Imagine a plural where the $bar becomes a string by mistake. All of a sudden 1 does not match anymore.
I'm comfortable with removing support for it from the spec - it's a backward compatible extension and we can add it if we see a use case later on.
What if $foo here was defined by a local variable, such that its type was available? That could well make sense if the same value was being used both for selection and formatting.
To me, this sounds really rather similar to the question of whether values within a pattern without a formatting function should be allowed or not, such as {The {$foo} thing}. Having the rules be different for selectors and pattern values seems weird.
I would strongly prefer keeping unadorned selectors (and pattern values) allowed in the syntax and spec, but to leave it to each implementation to determine what to do with a function-less variable reference. This would allow each implementation to figure out whether the value's type is supported and handle it with one of its known formatters or matchers, or to complain about a type error.
Having the rules be different for selectors and pattern values seems weird.
I don't think I agree. Having them separate feels acceptable to me and tightening one (in a way that can be later relaxed) doesn't feel wrong.
I think once we start discussing what runtime types we recognize in MF2, we'll also come back to this question for scenario like Fluent's Partially Formatted Variables:
let source = `{
match {$floor}
when 1 {...}
when * {...}
}`;
let mf = new Intl.MessageFormat();
mf.formatToString(source, {
floor: Intl.MF2.PluralRule(floor, type: "ordinal")
});
Selectors now require an annotation. Reopen if needed.