Navigation Menu

Skip to content
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

Allow passing a NumberFormat to Intl.plural which would be used to format the howMany argument #18882

Closed
alan-knight opened this issue May 19, 2014 · 2 comments
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@alan-knight
Copy link
Contributor

If you want to display the argument in the text of the message and format it in a particular way you would need to either explicitly put a formatter into the message text or else format it first and pass an extra argument. Either is cumbersome.

@alan-knight
Copy link
Contributor Author

I don't think we can reasonably do this. I spent some time looking at different options, but it's pretty painful.

One option would be to allow
    foo(num, format) => Intl.plural(foo, other: "${format.format(num)} left", format: format);
but that's fairly ugly in terms of parsing. We only allow simple references to arguments, except for something that is of the form {<name_of_the_format_argument>.format(<name_of_the_howMany_argument>} and we need to test to see if a format argument was passed. But multiple source messages with the same text get combined to one translation. So if a format is passed in one instance but not another, do we treat that as making them different? Or as an error? Finding out if a format was passed is also very painful. We can have plurals nested inside genders or selects, multiple plurals (discouraged, but not disallowed), and when we parse it back from the ARB file the format is lost so we'd have dive into the internals of the original message as parsed from the source.

Alternatively we could make the breaking change that we always have a format, and if one is not passed we default to new NumberFormat(). But we still have the problem that the parsed input doesn't tell us which variable is the format (and there could be more than one if there are multiple plurals). While the alternative is awkward, something like

foo(num, format) => foo2(num, format.format(num));
foo2(num, formatted) => Intl.plural(num, other: "$formatted left"...);

the cure is seeming worse.


Added WontFix label.

@alan-knight alan-knight added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Oct 29, 2014
@alan-knight alan-knight self-assigned this Oct 29, 2014
@DartBot
Copy link

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/i18n#310.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants