New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nesting not supported with custom fortmatters #201
Comments
You're right, custom formatters arguments don't work like you'd expect them to. They're not as such a part of the MessageFormat spec, but a relaxation/extension of the
So I'm not really sure what the "right" thing to do here would be. At a minimum, the "All types" statement should be reworded. But to address your specific use case, a slight reformulation should get you the result you're looking for: const mf = new MessageFormat('en-GB');
mf.addFormatters({
error: (v, lc, p) => chalk.red(p.replace(/#/g, v))
});
const messages = mf.compile({
describe: 'There were {numErrors, error, # errors}'
}); Note that this slightly abuses the meaning of
|
Currently, this message does not even compile: const messages = mf.compile({
describe: 'There were {numErrors, error, {# errors}}'
}); This message, however, does: const messages = mf.compile({
describe: 'There were {numErrors, error, {# errors}'
}); The second string is invalid, since an ending curly bracket is missing.
It seems the parsing breaks whenever there is a new ending curly bracket, and the parsing doesn't accept any string containing an ending curly bracket. |
The Format Guide states this:
However, it doesn't work to nest anything within a custom formatter:
You could also imagine nesting a plural format in there, to get
'no error'
,'one error'
,'# errors'
, and so on, printed in red.The text was updated successfully, but these errors were encountered: