Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add en_GB and en_US #210

Open
2br-2b opened this issue Oct 5, 2024 · 5 comments · May be fixed by #222 or #230
Open

Add en_GB and en_US #210

2br-2b opened this issue Oct 5, 2024 · 5 comments · May be fixed by #222 or #230

Comments

@2br-2b
Copy link

2br-2b commented Oct 5, 2024

What did you do?

Hello! Thank you so much for making this library!!!

I'm using this to bot to translate some strings for my python discord bot. To do that, I am mapping discord locales to Humanize strings, like so:

HUMANIZE_LOCALE_STRINGS = {
    Locale.taiwan_chinese : "zh_HK",
    Locale.german : "de_DE",
    Locale.latin_american_spanish : "es_ES",
    etc.
]

I wish I could also map British English and American English to en_US and en_GB instead of setting them to None, then doing a None check whenever I get the locale.

Especially since en_GB is listed as an example locale at the bottom of the Readme, I wish this was an option


Please include code that reproduces the issue.

>>> import humanize
>>> humanize.i18n.activate("en_US")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/homer/StoryBot-Testing/.venv/lib/python3.10/site-packages/humanize/i18n.py", line 76, in activate
    translation = gettext_module.translation("humanize", path, [locale])
  File "/usr/lib/python3.10/gettext.py", line 607, in translation
    raise FileNotFoundError(ENOENT,
FileNotFoundError: [Errno 2] No translation file found for domain: 'humanize'
@hugovk
Copy link
Member

hugovk commented Oct 5, 2024

Would something like this work for you?

diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py
index 42447b0..c4ca274 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 and locale.startswith("en"):
+        locale = None
+
     if path is None:
         path = _get_default_locale_path()

@2br-2b
Copy link
Author

2br-2b commented Oct 6, 2024

Yes, this seems to fix the issue for me! Thank you so much!

@hugovk
Copy link
Member

hugovk commented Oct 6, 2024

Great, would you like to put together a PR?

@2br-2b
Copy link
Author

2br-2b commented Oct 6, 2024

Sure thing! I'll have to do that after the weekend though - I've been working on this while procrastinating on my Ludum Dare game 😅

@hugovk
Copy link
Member

hugovk commented Oct 6, 2024

No rush at all :) Have fun with Ludum Dare!

2br-2b added a commit to 2br-2b/humanize that referenced this issue Dec 14, 2024
@2br-2b 2br-2b linked a pull request Dec 14, 2024 that will close this issue
dangillet pushed a commit to dangillet/humanize that referenced this issue Feb 2, 2025
dangillet pushed a commit to dangillet/humanize that referenced this issue Feb 2, 2025
@dangillet dangillet linked a pull request Feb 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants