[Django] #25223: Getting DjangoTranslation that doesn't exist should return None

146 views
Skip to first unread message

Django

unread,
Aug 4, 2015, 12:04:17 PM8/4/15
to django-...@googlegroups.com
#25223: Getting DjangoTranslation that doesn't exist should return None
--------------------------------------+--------------------
Reporter: svleeuwen | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Getting a DjangoTranslation that doesn't exist used to return None.

Since
[https://github.com/django/django/commit/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45
#diff-5682903b7aed1649cdb7095331e90d0d this commit] it raises an IOError
when using an unavailable language.

[https://github.com/django/django/blob/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45/tests/i18n/tests.py#L1344
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'`

--
Ticket URL: <https://code.djangoproject.com/ticket/25223>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 5, 2015, 3:46:47 AM8/5/15
to django-...@googlegroups.com
#25223: Setting LANGUAGE_CODE to a language that doesn't exist in
django/conf/locale raises IOError
-------------------------------------+-------------------------------------

Reporter: svleeuwen | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by svleeuwen):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> Getting a DjangoTranslation that doesn't exist used to return None.
>
> Since
> [https://github.com/django/django/commit/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45
> #diff-5682903b7aed1649cdb7095331e90d0d this commit] it raises an IOError
> when using an unavailable language.
>
> [https://github.com/django/django/blob/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45/tests/i18n/tests.py#L1344
> 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'`

New description:

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

Since
[https://github.com/django/django/commit/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45
#diff-5682903b7aed1649cdb7095331e90d0d this commit] it raises an IOError

when using a language that's not available in django.

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'`

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:1>

Django

unread,
Aug 7, 2015, 3:15:56 PM8/7/15
to django-...@googlegroups.com
#25223: Setting LANGUAGE_CODE to a language that doesn't exist in
django/conf/locale raises IOError
-------------------------------------+-------------------------------------
Reporter: svleeuwen | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by beck):

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 "پوپَٽُ"
}}}

2. In settings.py add the locale and use a default language found in
[https://github.com/django/django/tree/master/django/conf/locale
django/conf]:
{{{
LANGUAGE_CODE = 'en'
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
}}}

3. Compile messages:
{{{
$ python manage.py compilemessages
processing file django.po in
/Users/doug/Desktop/project/locale/sd/LC_MESSAGES
}}}

4. 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 :)

--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:2>

Django

unread,
Aug 7, 2015, 3:30:00 PM8/7/15
to django-...@googlegroups.com
#25223: Setting LANGUAGE_CODE to a language that doesn't exist in
django/conf/locale raises IOError
-------------------------------------+-------------------------------------
Reporter: svleeuwen | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by beck):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:3>

Django

unread,
Aug 8, 2015, 10:15:53 AM8/8/15
to django-...@googlegroups.com
#25223: Allow default language to be one unsupported by django if the local project

has the required translation catalog
-------------------------------------+-------------------------------------
Reporter: svleeuwen | Owner: nobody
Type: New feature | Status: new

Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by svleeuwen):

* type: Bug => New feature


Old description:

> Getting a DjangoTranslation that doesn't exist used to return None.
>
> Since
> [https://github.com/django/django/commit/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45
> #diff-5682903b7aed1649cdb7095331e90d0d this commit] it raises an IOError

> when using a language that's not available in django.
>

> [https://github.com/django/django/blob/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45/tests/i18n/tests.py#L1344
> 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'`

New description:

Update:

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

---

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

Since
[https://github.com/django/django/commit/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45
#diff-5682903b7aed1649cdb7095331e90d0d this commit] it raises an IOError

when using a language that's not available in django.

[https://github.com/django/django/blob/a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45/tests/i18n/tests.py#L1344


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'`

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:4>

Django

unread,
Aug 10, 2015, 1:40:26 PM8/10/15
to django-...@googlegroups.com
#25223: Allow default language to be one unsupported by django if the local project
has the required translation catalog
--------------------------------------+------------------------------------
Reporter: svleeuwen | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:5>

Django

unread,
Jan 17, 2017, 1:40:10 PM1/17/17
to django-...@googlegroups.com
#25223: Allow default language to be one unsupported by django if the local project
has the required translation catalog
-------------------------------------+-------------------------------------
Reporter: Sander van Leeuwen | Owner: nobody
Type: New feature | Status: closed
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anton Samarchyan):

* cc: desecho@… (added)
* status: new => closed
* resolution: => duplicate


Comment:

This is a duplicate of #25915.

--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:6>

Reply all
Reply to author
Forward
0 new messages