Add support for ordinals in `MessageFormat`
Reprevise opened this issue · 3 comments
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
There appears to be parsing for selectordinal
already, but it only works for "one" and I guess "other".
import 'package:intl/message_format.dart';
void main() {
final msg = MessageFormat('{count, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}');
print(msg.format({"count": 1})); // 1st
print(msg.format({"count": 2})); // 2th
print(msg.format({"count": 3})); // 3th
print(msg.format({"count": 4})); // 4th
}
Describe alternatives you've considered
I could maintain my own ordinal method however it would be difficult to localize myself.
The following works though. I'm confused as to why the text I posted originally doesn't. It also works without the =
sign in front of it, where on sites like this, it requires the =
sign prefix.
import 'package:intl/message_format.dart';
void main() {
final msg = MessageFormat('{count, selectordinal, =1{#st} =2{#nd} =3{#rd} other {#th}}');
print(msg.format({"count": 1})); // 1st
print(msg.format({"count": 2})); // 2nd
print(msg.format({"count": 3})); // 3rd
print(msg.format({"count": 4})); // 4th
}
Just a quick note without having taken a deeper look: The implementation is derived from the Closure one and should be based on the ICU MessageFormat, so that should be the reference to look at.
But this class does not have ordinal support in general, see
i18n/pkgs/intl/lib/message_format.dart
Line 770 in 316929f