From 9754526bf322e96663fd55193bbec816b6181bb8 Mon Sep 17 00:00:00 2001 From: John Wuller <847785bd-d466-47cd-a536-eae4096d241d@anonaddy.me> Date: Sat, 14 Dec 2024 07:24:40 -0500 Subject: [PATCH 1/6] Add en_GB and en_US Fixes #210 --- src/humanize/i18n.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py index 42447b0..e5c9e52 100644 --- a/src/humanize/i18n.py +++ b/src/humanize/i18n.py @@ -71,6 +71,9 @@ def activate( Raises: Exception: If humanize cannot find the locale folder. """ + if locale == "en_GB" or locale == "en_US": + locale = None + if path is None: path = _get_default_locale_path() From 5a02c5978fb40daf1063dfb4dd3bf3b9af20d864 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:25:50 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/humanize/i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py index e5c9e52..38307ea 100644 --- a/src/humanize/i18n.py +++ b/src/humanize/i18n.py @@ -73,7 +73,7 @@ def activate( """ if locale == "en_GB" or locale == "en_US": locale = None - + if path is None: path = _get_default_locale_path() From b15582a827daef34018cb0290cbb2a09302bccb5 Mon Sep 17 00:00:00 2001 From: John Wuller <847785bd-d466-47cd-a536-eae4096d241d@anonaddy.me> Date: Sat, 14 Dec 2024 08:11:16 -0500 Subject: [PATCH 3/6] Add tests for en languages --- tests/test_i18n.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_i18n.py b/tests/test_i18n.py index f3721c9..f57c0fa 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -38,6 +38,19 @@ def test_i18n() -> None: assert humanize.ordinal(5) == "5th" assert humanize.precisedelta(one_min_three_seconds) == "1 minute and 7 seconds" +def test_en_locale() -> None: + three_seconds = NOW - dt.timedelta(seconds=3) + + humanize.i18n.activate(None) + test_str = humanize.naturaltime(three_seconds) + + humanize.i18n.activate("en_US") + assert test_str = humanize.naturaltime(three_seconds) + + humanize.i18n.activate("en_GB") + assert test_str = humanize.naturaltime(three_seconds) + + humanize.i18n.deactivate() def test_intcomma() -> None: number = 10_000_000 From 88778a436f95f0d0ccb0c90adf2e22aa1ebd70ae Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:11:25 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_i18n.py b/tests/test_i18n.py index f57c0fa..0ce1d5a 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -40,7 +40,7 @@ def test_i18n() -> None: def test_en_locale() -> None: three_seconds = NOW - dt.timedelta(seconds=3) - + humanize.i18n.activate(None) test_str = humanize.naturaltime(three_seconds) From bb4c736c8339bfdff57de005579676046dc8b4c5 Mon Sep 17 00:00:00 2001 From: John Wuller <847785bd-d466-47cd-a536-eae4096d241d@anonaddy.me> Date: Sat, 14 Dec 2024 08:13:04 -0500 Subject: [PATCH 5/6] Add == instead of = --- tests/test_i18n.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 0ce1d5a..85d6957 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -45,10 +45,10 @@ def test_en_locale() -> None: test_str = humanize.naturaltime(three_seconds) humanize.i18n.activate("en_US") - assert test_str = humanize.naturaltime(three_seconds) + assert test_str == humanize.naturaltime(three_seconds) humanize.i18n.activate("en_GB") - assert test_str = humanize.naturaltime(three_seconds) + assert test_str == humanize.naturaltime(three_seconds) humanize.i18n.deactivate() From 628a76b9d202380e35c1fcf0e616b17dfb16719e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:13:13 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_i18n.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 85d6957..908c8fc 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -38,6 +38,7 @@ def test_i18n() -> None: assert humanize.ordinal(5) == "5th" assert humanize.precisedelta(one_min_three_seconds) == "1 minute and 7 seconds" + def test_en_locale() -> None: three_seconds = NOW - dt.timedelta(seconds=3) @@ -52,6 +53,7 @@ def test_en_locale() -> None: humanize.i18n.deactivate() + def test_intcomma() -> None: number = 10_000_000