diff options
author | Hernan <hernan.grecco@gmail.com> | 2021-10-27 20:36:40 -0300 |
---|---|---|
committer | Hernan <hernan.grecco@gmail.com> | 2021-10-27 20:36:40 -0300 |
commit | eb4e13428a3ede09148b76c71bc5b8cddb169176 (patch) | |
tree | 45d34a62b26ccfe84ab03d5da0c8c71a8aa6f873 | |
parent | 4ada9df8e2747086851595217df759fc3d9df5c7 (diff) | |
download | pint-develop.tar.gz |
Support for babel > 2.8develop
Close #1400, #1219 and #1296.
-rw-r--r-- | pint/formatting.py | 11 | ||||
-rw-r--r-- | pint/testsuite/test_issues.py | 8 |
2 files changed, 16 insertions, 3 deletions
diff --git a/pint/formatting.py b/pint/formatting.py index a04205d..528f4e0 100644 --- a/pint/formatting.py +++ b/pint/formatting.py @@ -333,9 +333,14 @@ def formatter( # Don't remove this positional! This is the format used in Babel key = pat.replace("{0}", "").strip() break - division_fmt = compound_unit_patterns.get("per", {}).get( - babel_length, division_fmt - ) + + tmp = compound_unit_patterns.get("per", {}).get(babel_length, division_fmt) + + try: + division_fmt = tmp.get("compound", division_fmt) + except AttributeError: + division_fmt = tmp + power_fmt = "{}{}" exp_call = _pretty_fmt_exponent if value == 1: diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index ed781b7..9d4167c 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -824,6 +824,14 @@ class TestIssues(QuantityTestCase): m = ureg.Measurement(1, 0.1, "meter") assert m.default_format == "~P" + def test_issue_1400(self, sess_registry): + q1 = 3 * sess_registry.W + q2 = 3 * sess_registry.W / sess_registry.cm + assert q1.format_babel("~", locale="es_Ar") == "3 W" + assert q1.format_babel("", locale="es_Ar") == "3 vatios" + assert q2.format_babel("~", locale="es_Ar") == "3.0 W / cm" + assert q2.format_babel("", locale="es_Ar") == "3.0 vatios por centÃmetros" + if np is not None: |