镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add en_GB and en_US #210

Description

@2br-2b

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'

Activity

  1. hugovk commented on Oct 5, 2024

    @hugovk
    Member

    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()
  2. 2br-2b commented on Oct 6, 2024

    @2br-2b
    ContributorAuthor

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

  3. hugovk commented on Oct 6, 2024

    @hugovk
    Member

    Great, would you like to put together a PR?

  4. 2br-2b commented on Oct 6, 2024

    @2br-2b
    ContributorAuthor

    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 😅

  5. hugovk commented on Oct 6, 2024

    @hugovk
    Member

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

  6. added a commit that references this issue on Dec 14, 2024
    9754526
  7. added 2 commits that reference this issue on Feb 2, 2025
    769b523
    99ebff3
  8. added a commit that references this issue on Feb 12, 2025
    816f336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions