Skip to content

Match expressions should be re-usable in placeholders #736

Closed
@eemeli

Description

@eemeli

While preparing yet another presentation on MF2, I needed to write a simple example that got me thinking:

.input {$count :number}
.match {$count}
one {{You have {$count} apple}}
* {{You have {$count} apples}}

It's not necessarily obvious that the above is what we expect, when this looks like it'll work just as well:

.match {$count :number}
one {{You have {$count} apple}}
* {{You have {$count} apples}}

However, that doesn't format the $count explicitly as a number; we just presume it does, because "count" sounds numeric.

So the thought I had here is that this is pretty much exactly why & how MF1 ended up with # being special in plural selectors, and that the solution we're providing is much less obvious and requires writing a whole new .input statement.

Could we consider making the .match expressions also act as implicit declarations, and make them usable in placeholders? The somewhat obvious way to address them is by index position:

.match {$count :number}
one {{You have {$0} apple}}
* {{You have {$0} apples}}

Assigning values to $0, $1, ... would not conflict with any input values, as numbers are invalid name-start characters. That's by design so that we encourage at least some name for each variable; here that's effectively provided by the .match expressions.

I suspect that adding this shorthand would provide a more ergonomic solution for most .input use cases, and would enable the representation of many messages without any declarations, which currently would require one to avoid significant repetition.

The syntax change required by this would probably look something like this:

-variable = "$" name
+variable = "$" (name / %x30-39)

with accompanying spec language making numeric variables resolve to the .match selectors in placeholders, and a data model error otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Preview-FeedbackFeedback gathered during the technical previewsyntaxIssues related with syntax or ABNF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions