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

Is it possible to use the short number formats from CLDR? #908

Closed
DenverCoder1 opened this issue Oct 16, 2022 · 0 comments · Fixed by #909
Closed

Is it possible to use the short number formats from CLDR? #908

DenverCoder1 opened this issue Oct 16, 2022 · 0 comments · Fixed by #909

Comments

@DenverCoder1
Copy link
Contributor

DenverCoder1 commented Oct 16, 2022

CLDR contains some short number formats, for example in English

1,000 can become 1K, 12,100,000 can become 12.1M.

https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-numbers-modern/main/en/numbers.json#L61-L88

Similarly, other languages can use this with their own characters

eg. 32,500,000 = 3250万

https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-numbers-modern/main/ja/numbers.json#L51-L66

Is there a method in Babel that allows us to use these formats for decimal numbers?


It seems that the data is loaded under "compact_decimal_formats" although there are no utility functions for using them.

As per comment @ https://github.com/python-babel/babel/blob/v2.10.3/scripts/import_cldr.py#L768-L774

>>>Locale('en', 'US')._data["compact_decimal_formats"]["short"]["one"]["1000"]
<NumberPattern '0K'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants