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

No support for DescriptiveNumberFormatConfiguration.Presentation in IntegerFormatStyle or DecimalFormatStyle #1037

Open
orj opened this issue Nov 6, 2024 · 2 comments

Comments

@orj
Copy link

orj commented Nov 6, 2024

There currently appears to be a gap in the implementation of the FormatStyle APIs and foundation's NumberFormatter.

Although DescriptiveNumberFormatConfiguration.Presentation defines ordinal and spellOut there doesn't appear to be any presentation() APIs on IntegerFormatStyle or DecimalFormatStyle that take this type.

What this means is that if we want to format numbers 1, 2, 3, etc. in the style of "1st, 2nd, 3rd" etc we have to use NumberFormatter instead of [1, 2, 3].map { $0.formatted(.number.presentation(.ordinal)) }.

@itingliu
Copy link
Contributor

itingliu commented Nov 7, 2024

It was intentional to leave them out for FormatStyle. Supporting ordinal and spell out numbers requires more context than what this API knows. For example, many languages have gendered ordinals, e.g. in Portuguese, "first" can be either "primeiro" or "primeira", and even in abbreviations ("1º", "1ª"). What we've seen in the past is that developers tend to use the formatted number as part of a localized string and caused grammatical errors. Not saying it's not doable, but it just requires more thought.

@kielgillard
Copy link

I bumped into this issue recently and used this gist to get me through. I didn't realise this had potential to be grammatically problematic. Hoping someone smarter than me can figure out how to solve this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants