Skip to content

"Cannot load translation for ..." error messages #2954

Closed

Description

@spaceone

I am providing a service with only some languages. When my translations lie in the regular directory /usr/share/locale/ every time starting the service 217 error messages are logged:

…
Cannot load translation for 'ps': [Errno 2] No such file or directory: '/usr/share/locale/ps/LC_MESSAGES/foo.mo'
Cannot load translation for 'is': [Errno 2] No such file or directory: '/usr/share/locale/is/LC_MESSAGES/foo.mo'
Cannot load translation for 'az': [Errno 2] No such file or directory: '/usr/share/locale/az/LC_MESSAGES/foo.mo'
Cannot load translation for 'an': [Errno 2] No such file or directory: '/usr/share/locale/an/LC_MESSAGES/foo.mo'
Cannot load translation for 'fa': [Errno 2] No such file or directory: '/usr/share/locale/fa/LC_MESSAGES/foo.mo'
Cannot load translation for 'ta': [Errno 2] No such file or directory: '/usr/share/locale/ta/LC_MESSAGES/foo.mo'
Cannot load translation for 'en_GB': [Errno 2] No such file or directory: '/usr/share/locale/en_GB/LC_MESSAGES/foo.mo'

There is no way to suppress them or specify a list of languages to load.

Activity

  1. spaceone commented on Nov 13, 2020

    @spaceone
    ContributorAuthor

    Maybe consider this patch, which only finds existing files?:

    diff --git tornado/locale.py tornado/locale.py
    index adb1f774..30f92f90 100644
    --- tornado/locale.py
    +++ tornado/locale.py
    @@ -198,13 +198,11 @@ def load_gettext_translations(directory: str, domain: str) -> None:
         global _supported_locales
         global _use_gettext
         _translations = {}
    -    for lang in os.listdir(directory):
    -        if lang.startswith("."):
    -            continue  # skip .svn, etc
    -        if os.path.isfile(os.path.join(directory, lang)):
    -            continue
    +
    +    import glob  # move to top
    +    for filename in glob.glob(os.path.join(directory, '*', 'LC_MESSAGES', domain + '.mo')):
    +        lang = filename.split('/LC_MESSAGES/', 1)[0].split(directory, 1)[1].strip('/')
             try:
    -            os.stat(os.path.join(directory, lang, "LC_MESSAGES", domain + ".mo"))
                 _translations[lang] = gettext.translation(
                     domain, directory, languages=[lang]
                 )
  2. bdarnell commented on Nov 19, 2020

    @bdarnell
    Member

    Yeah, that makes sense. The gettext support was implemented with the assumption that you'd use an application-specific directory with only your languages, but it should be able to work in shared directories by skipping ones where the expected file is missing.

  3. spaceone commented on Nov 19, 2020

    @spaceone
    ContributorAuthor

    OK. I can create a PR with that patch then.

  4. added a commit that references this issue on Nov 19, 2020
  5. spaceone commented on Nov 19, 2020

    @spaceone
    ContributorAuthor
  6. added 2 commits that reference this issue on Nov 19, 2020
  7. added a commit that references this issue on Apr 10, 2021
  8. added a commit that references this issue on Aug 25, 2021
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