summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pint/formatting.py11
-rw-r--r--pint/testsuite/test_issues.py8
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: