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.
* 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.
[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:1>
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>
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>
* 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.
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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25223#comment:5>
* 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>