An implementation of MF2 with column-first selection #369
Replies: 3 comments 2 replies
-
Good idea to use ordinals in English (quite similar to Slavic cardinals) |
Beta Was this translation helpful? Give feedback.
-
I've merged the Java implementation for best match selection. It is a copy of the existing ICU4J implementation, with the classes moved to a different package to avoid conflicts. It is maven, so all you need to do is I've added a dedicated test file ( And has an ordinal example:
The commits are cleanly separated to show the progress, from an empty maven project to the final version. The changes needed are really minimal. |
Beta Was this translation helpful? Give feedback.
-
Following #372, I've merged this into the JS polyfill in messageformat/messageformat#395. |
Beta Was this translation helpful? Give feedback.
-
Following yesterday's discussion, I've updated my JS
Intl.MessageFormat
polyfill to provide two up-to-date implementations with the following selection method alternatives:The change in getting from the former to the latter is effectively commit
f5d1bba
, which changes the message value selection method frommatchSelectKey(key: string): boolean
toselectKey(keys: Set<string>): string | null
. The actual selection algorithm is found in thegetPattern()
function inmessage-value/resolved-message.ts
.To play around with this locally, run one of the above shell commands and then create a new file
test.mjs
with these contents:then run
node test.mjs
to observe the results. With4.0.0-3
, thewhen one 1
variant will be selected, while4.0.0-3.cf
will selectwhen 1 1
. You may run the correspondingnpm install
command to switch from one to another.To experiment with more complex rules while staying in English, the
:number
function supports thetype=ordinal
option to perform ordinal rather than cardinal selection.CC @aphillips, @stasm, @mihnita
Beta Was this translation helpful? Give feedback.
All reactions