Opened 9 years ago

Closed 8 years ago

#25223 closed New feature (duplicate)

Allow default language to be one unsupported by django if the local project has the required translation catalog

Reported by: Sander van Leeuwen Owned by: nobody
Component: Internationalization Version: 1.8
Severity: Normal Keywords:
Cc: desecho@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Sander van Leeuwen)

Update:

Changed from bug to feature request.
See beck's comments below.

---

Getting a DjangoTranslation that doesn't exist used to return None.

Since this commit it raises an IOError when using a language that's not available in django.

This test suggests this is wanted behaviour.

But it should be possible to add a language that is not available in django/conf/locale/ right?

To reproduce, use a LANGUAGE_CODE unavailable in django/conf/locale/.

For instance:
LANGUAGE_CODE = 'sd-PK'

run python manage.py validate

This will raise:
IOError: [Errno 2] No translation file found for domain: u'django'

Change History (6)

comment:1 by Sander van Leeuwen, 9 years ago

Description: modified (diff)
Summary: Getting DjangoTranslation that doesn't exist should return NoneSetting LANGUAGE_CODE to a language that doesn't exist in django/conf/locale raises IOError

comment:2 by Doug Beck, 9 years ago

Indeed. This is by design.

The reason is to catch broken django installs. If trying to activate a supported language and the django translations are missing/unreadable (referencing #18192), the framework needs to blowup and make the user aware of the issue.

When trying to set the default language to one not supported by django, this action has the same side-effects as activating a common language with a broken install.

IMO catching a broken install is more critical and a more common use-case than setting the default language to one (not yet) supported.

However, django will let you use and activate a custom language (just not make it the default).

To exemplify:

  1. Add a translation catalog for the custom language. Add file projectdir/locale/sd/LC_MESSAGES/django.po:
    msgid ""
    msgstr ""
    "Content-Type: text/plain; charset=UTF-8\n"
    
    msgid "butterfly"
    msgstr "پوپَٽُ"
    
  1. In settings.py add the locale and use a default language found in django/conf:
    LANGUAGE_CODE = 'en'
    LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
    
  1. Compile messages:
    $ python manage.py compilemessages
    processing file django.po in /Users/doug/Desktop/project/locale/sd/LC_MESSAGES
    
  1. Test the translation. Create test.py:
    from django.utils.translation import activate, ugettext
    activate('sd-pk')
    print(ugettext('butterfly'))
    
    Run test.py through django shell:
    $ python manage.py shell < test.py
    (InteractiveConsole)
    >>> پوپَٽُ
    

As for this ticket, since all is working by design I do not believe it to be a bug.

This ticket could be reworded as a feature request:

Allow default language to be one unsupported by django if the local project has the required translation catalog

Or open a new pull on django adding Sindhi :)

Last edited 8 years ago by Anton Samarchyan (previous) (diff)

comment:3 by Doug Beck, 9 years ago

Note: the fix for #21055 added support for activating an unknown language

Version 0, edited 9 years ago by Doug Beck (next)

comment:4 by Sander van Leeuwen, 9 years ago

Description: modified (diff)
Summary: Setting LANGUAGE_CODE to a language that doesn't exist in django/conf/locale raises IOErrorAllow default language to be one unsupported by django if the local project has the required translation catalog
Type: BugNew feature

comment:5 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:6 by Anton Samarchyan, 8 years ago

Cc: desecho@… added
Resolution: duplicate
Status: newclosed

This is a duplicate of #25915.

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