diff --git a/README.md b/README.md index e14dec69..ce55185f 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,17 @@ How to change locale at runtime: '3 seconds ago' ``` +Number formatting also uses the locale's configured numeric separators: + +```pycon +>>> _t = humanize.i18n.activate("tr_TR") +>>> humanize.intcomma(1_234_567.89) +'1.234.567,89' +>>> humanize.intword(1_200_000) +'1,2 milyon' +>>> humanize.i18n.deactivate() +``` + You can pass additional parameter `path` to `activate` to specify a path to search locales in. diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py index 0bf73de5..672dddc5 100644 --- a/src/humanize/i18n.py +++ b/src/humanize/i18n.py @@ -26,6 +26,7 @@ "pt_BR": ".", "hu_HU": " ", "lv": " ", + "tr_TR": ".", } # Mapping of locale to decimal separator @@ -36,6 +37,7 @@ "pt_BR": ",", "hu_HU": ",", "lv": ",", + "tr_TR": ",", } diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 683fe3ce..d75ed1ef 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -124,6 +124,12 @@ def test_intcomma() -> None: humanize.i18n.activate("pt_BR") assert humanize.intcomma(number) == "10.000.000" + humanize.i18n.activate("tr_TR") + assert humanize.intcomma(number) == "10.000.000" + assert humanize.intcomma(1_234_567.89) == "1.234.567,89" + assert humanize.intcomma("1234567,89") == "1.234.567,89" + assert humanize.intcomma("1.234.567,89") == "1.234.567,89" + except FileNotFoundError: pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh") @@ -159,6 +165,9 @@ def test_naturaldelta() -> None: ("it_IT", 1_200_000, "1,2 milioni"), ("it_IT", 1_000_000_000, "1,0 miliardo"), ("it_IT", 3_500_000_000, "3,5 miliardi"), + # Turkish uses comma as decimal separator + ("tr_TR", 1_000_000, "1,0 milyon"), + ("tr_TR", 1_200_000, "1,2 milyon"), # Sinhala uses borrowed scale words with a dot decimal separator ("si_LK", 1_000_000, "1.0 මිලියන"), ("si_LK", 1_200_000, "1.2 මිලියන"),