-
Notifications
You must be signed in to change notification settings - Fork 451
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
feat: Support for short compact currency formats #926
Conversation
…babel into compact-currency
Codecov Report
@@ Coverage Diff @@
## master #926 +/- ##
==========================================
+ Coverage 91.55% 91.59% +0.04%
==========================================
Files 21 21
Lines 4215 4238 +23
==========================================
+ Hits 3859 3882 +23
Misses 356 356
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
As far as I can tell, CLDR doesn't provide a format for formatting currency in short form for numbers less than 1000. As a fallback, maybe it would make sense to take the smallest magnitude and remove characters not related to the ordering of the currency symbol and spacing. Here is what I currently think could be a good fallback: # find first format that has a currency symbol
for magnitude in compact_format['other']:
format = compact_format['other'][magnitude].pattern
if '¤' not in format:
continue
# remove characters that are not the currency symbol, 0's or spaces
format = re.sub(r'[^0\s\¤]', '', format)
# compress adjacent spaces into one
format = re.sub(r'(\s)\s+', r'\1', format).strip()
break Example:
I've made a gist to show the results this produces for all locales: https://gist.github.com/DenverCoder1/e4a1ab9ac94e576a34ad7371f3573e0b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, thanks @DenverCoder1 and @jun66j5!
Added a way to format currency with standard "short" currency formats from the CLDR data.
Closes #923
"short"
is currently the only length type that seems to appear in the data.Note:
"standard:short"
no longer appears inlocale.currency_formats
(see #923). This was never documented or tested and did not format things properly in the first place, so I don't think this should be considered a breaking change.