Opened 2 years ago

Closed 17 months ago

#21055 closed Bug (fixed)

Error when implementing unknown language

Reported by: beck Owned by: nobody
Component: Translations Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When trying to implement a language unknown to django (say Inuktitut, ISO 639-1 lang code "iu") an error is encountered.

Discovered while trying to answer:!msg/django-users/tc0asF6iFBo/u3cBN0SlUl0J

Tests to and patch in comments.

Change History (9)

comment:1 Changed 2 years ago by beck

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 23 months ago by bouke

How can I reproduce the problem? I've tried with the example below, but that seems to be working allright.

from django.conf import settings
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',

from django.utils.translation.trans_real import activate, gettext
print(gettext('Hello, world.'))

comment:3 Changed 20 months ago by fernando.gutierrez@…

I think it is not related to one unknown language, probably related to two unknown languages and the way django tries to avoid sharing the translation object? This script fails for me in the third activate, it basically replicates what I am trying to do for a language chooser, were in one template I try to show the language name in it's own language:

from django.conf import settings
gettext = lambda s: s
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        ('en', gettext('English')),
        ('zh-sg', gettext('Traditional Chinese (Singapore)')),
        ('zh-hk', gettext('Traditional Chinese (Hong Kong)')),

from django.utils.translation.trans_real import activate, gettext
print(gettext('Hello, world.'))
print(gettext('Hello, world.'))
print(gettext('Hello, world.'))

Fails with:

$ python 
Hello, world.
Hello, world.
Traceback (most recent call last):
  File "", line 21, in <module>
  File "/Users/***/.virtualenvs/cumutmp/lib/python2.7/site-packages/django/utils/translation/", line 194, in activate
    _active.value = translation(language)
  File "/Users/***/.virtualenvs/cumutmp/lib/python2.7/site-packages/django/utils/translation/", line 184, in translation
    current_translation = _fetch(language, fallback=default_translation)
  File "/Users/***/.virtualenvs/cumutmp/lib/python2.7/site-packages/django/utils/translation/", line 147, in _fetch
    res._info = res._info.copy()
AttributeError: 'NoneType' object has no attribute '_info'

This is django 1.4.10 btw. (I've replaced my username with *)

comment:4 follow-up: Changed 20 months ago by anonymous

Looks about right. The core issue is that an inappropriate IOError exception in trans_real.translation() that results in downstream failure.

This section of code is difficult to debug and write fixes for. I've closed my old pull in favor of a rewrite:

Some of this code hasn't been touched in ages.
I hope this pull is reviewed and merged so core django translations dev can happen without hours of trying to untangle what is happening.

comment:5 in reply to: ↑ 4 Changed 20 months ago by beck

Replying to anonymous:

Errr... didn't mean to post as anon

comment:6 Changed 20 months ago by timo

  • Easy pickings unset

comment:7 Changed 18 months ago by timo

#22409 was a duplicate.

comment:8 Changed 17 months ago by timo

Is #18192 a duplicate?

comment:9 Changed 17 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45:

Refactored DjangoTranslation class

Also fixes #18192 and #21055.

Note: See TracTickets for help on using tickets.
Back to Top