Test and patch errors with unknown languages #1562

Closed
wants to merge 2 commits into
from

2 participants

@beck

Test for two edge cases:

If an issued occurred on the filesystem and the .po files are no longer accessible, instead of raising an IOError, fails with ambiguous:

AttributeError: 'NoneType' object has no attribute '_info'

Related:
https://code.djangoproject.com/ticket/18192
https://groups.google.com/forum/#!msg/django-users/tc0asF6iFBo/u3cBN0SlUl0J

Second case: if trying to implement a language that django does not recognize (eg Inuktitut) translations fail with same error. Ticket: https://code.djangoproject.com/ticket/21055

beck added some commits Sep 6, 2013
@beck beck Test for i18n bugs when language not found
Test for two edge cases:

If an issued occurred on the filesystem and the .po files are no longer accessible, instead of raising an IOError, fails with ambiguous:

 > AttributeError: 'NoneType' object has no attribute '_info'

Second case: if trying to implement a language that django does not recognize (eg Inuktitut) translations fail with same error.

Related:
https://code.djangoproject.com/ticket/18192
https://groups.google.com/forum/#!msg/django-users/tc0asF6iFBo/u3cBN0SlUl0J
abed38a
@beck beck Fixed #21055 #18192 -- Fix errors with unknown languages 11fc39b
@kelvin-wong

I am using 1.5.4.
After I look through the code, I found that the problem is about it's probably caused by inconsistency.

When the translation is searched in globalpath which is the path that contains all languages that django supported.
https://github.com/django/django/blob/1.5.4/django/utils/translation/trans_real.py#L113
https://github.com/django/django/blob/1.5.4/django/utils/translation/trans_real.py#L127

But in the check_for_language utils function, the translation is searched in all path that could contain locale files.
https://github.com/django/django/blob/1.5.4/django/utils/translation/trans_real.py#L351

So even I check the language is available by using check_for_language, I still got the error.
Does it make sense?

@beck

I found that the problem is about it's probably caused by inconsistency

Which problem? The pull addresses two issues:

  1. ambiguous error with IOError (a real issue seen by users)
  2. unknown language (less of a concern but should still be fixed for completeness)

Does it make sense?

Not completely, a code example would for sure help. If this pull is incomplete, I'm willing to add a test & fix.

@kelvin-wong

I just suggested that the root cause of django cannot find the translation files may be django have found them in the wrong places.

In the check_for_language function, it find the translation files in both global path and the user-defined paths using all_locale_paths.

def all_locale_paths():
    """
    Returns a list of paths to user-provides languages files.
    """
    from django.conf import settings
    globalpath = os.path.join(
        os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
    return [globalpath] + list(settings.LOCALE_PATHS)

But when it really try to get the translation files, django only find the global path.
So even we have defined the locale paths in settings and using check_for_language to identify the presence of the language, we still get this IOError.

@beck

After reviewing this pull once more (it's been several months), the real issue it not about unknown languages but the masked IOError when parsing translation mo files.

trans_real. translation() is very cryptic is difficult to review when changing. Since I've taken the time to untake how it all works, am closing this pull in favor of a rewrite: #2237

@beck beck closed this Feb 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment