]> git.ipfire.org Git - thirdparty/babel.git/commit
Simplify format_currency code by pulling out/using helpers. 585/head
authorLuke Plant <L.Plant.98@cantab.net>
Thu, 7 Jun 2018 12:21:19 +0000 (15:21 +0300)
committerLuke Plant <L.Plant.98@cantab.net>
Thu, 7 Jun 2018 12:37:27 +0000 (15:37 +0300)
commit4c7e9b645cfec72672f836e04d8587ca66ba98c3
tree7be9d2495b8fc3799643299c0adcd070bca90a9e
parent4b5097f6064dda281ce7a1c5ef74e047cfdc558c
Simplify format_currency code by pulling out/using helpers.

In detail:

1. Use the already existing get_currency_name function which does
   the plural form logic already.

2. Create a similar `get_currency_unit_pattern` function.
   This function could be useful if someone wanted to write
   something very similar to the _format_currency_long_name
   functionality but with some different customizations,
   so it is now publicly documented.

3. Simplify the _format_currency_long_name function - it
   is now much flatter.

4. Add more tests to ensure certain cases are really covered.
   (e.g. different unit patterns depending on the count)

An upshot of the changes is that we have reduced (and made more consistent)
the number of places where we need to peek into `Locale._data` -
get_currency_name and get_currency_unit_pattern are the only places that
babel.numbers does this.
babel/numbers.py
docs/api/numbers.rst
tests/test_numbers.py