Conversation
|
Ping @jantimon, I think this would also fix #328? // input
const pluralCodeFromKey = key => key === '0' ? 'en' : key === '1' ? 'de' : null
const mf = new MessageFormat(['en', 'de'], { pluralCodeFromKey })
compileModule(mf, ['{count, plural, other{EN}}', '{count, plural, other{DE}}'])// output
import { de, en } from "@messageformat/runtime/lib/cardinals";
import { plural } from "@messageformat/runtime";
export default {
"0": (d) => plural(d.count, 0, en, { other: "EN" }),
"1": (d) => plural(d.count, 0, de, { other: "DE" })
} |
|
Changes look good! I like this more explicit arbitrary mapping strategy as opposed to assuming normalization. Thanks! |
cdaringe
left a comment
There was a problem hiding this comment.
Thanks @eemeli! Technically I agree this would fix our issue! 🎉 I do have a suggestion on the interface name/semantics.
I'd be happy to even send the patch. I think your solution--putting the user in control--is good and elegant.
|
Been punting this until "later" for a while, but ultimately I agree with the option rename suggested by @cdaringe. It wasn't so much the shape of the change that was tricky here, but the scope of what it doesn't do. Specifically, this PR doesn't actually fix the exact issue that was originally reported in #359, which used the const localeCodeFromKey = (key) => key === 'es-MX' ? 'es' : nulland then you'd get However, the issue is fixed for language+region locale codes if the input list of locales is explicit, i.e. something like If someone's interested in improving the former without breaking the API, then I'd be willing to consider a PR on it. But for now, I'm going to add the option as |
Fixes #359
See also #360
Ping @cdaringe, @dpchamps, would this approach work for you?