[Django] #29348: "-" and "_" in language code should be consistent

7 views
Skip to first unread message

Django

unread,
Apr 20, 2018, 11:26:44 PM4/20/18
to django-...@googlegroups.com
#29348: "-" and "_" in language code should be consistent
-------------------------------------+-------------------------------------
Reporter: Shen Li | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: 2.0
Internationalization |
Severity: Normal | Keywords: i18n, inconsistency
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
for some languages eg, en-us hyphen is used
but in zh_hans underscore is used.

If zh-hans is used, django would not show the translation. Here's some
tests and resutls

Language code: zh_hans, folder zh_hans -> works
Language code: zh_hans, folder zh-hans -> ` No translation files found
for default language zh_hans.`
Language code: zh-hans, folder zh-hans -> does not work. No errors, no
translations
Language code: zh-hans, folder zh_hans -> does not work. No erros, no
translations

looks like django does not treat zh-hans as a valid language code, which
is very very confusing because the default en-us is valid.
It look me a very long time to figure this out.

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

Django

unread,
Apr 20, 2018, 11:42:19 PM4/20/18
to django-...@googlegroups.com
#29348: "-" and "_" in language code should be consistent
-------------------------------------+-------------------------------------
Reporter: Shen Li | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: 2.0
Internationalization |
Severity: Normal | Resolution:

Keywords: i18n, inconsistency | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Shen Li:

Old description:

> for some languages eg, en-us hyphen is used
> but in zh_hans underscore is used.
>
> If zh-hans is used, django would not show the translation. Here's some
> tests and resutls
>
> Language code: zh_hans, folder zh_hans -> works
> Language code: zh_hans, folder zh-hans -> ` No translation files found
> for default language zh_hans.`
> Language code: zh-hans, folder zh-hans -> does not work. No errors, no
> translations
> Language code: zh-hans, folder zh_hans -> does not work. No erros, no
> translations
>
> looks like django does not treat zh-hans as a valid language code, which
> is very very confusing because the default en-us is valid.
> It look me a very long time to figure this out.

New description:

for some languages eg, en-us hyphen is used
but in zh_hans underscore is used.

If zh-hans is used, django would not show the translation. Here's some
tests and resutls

Language code: zh_hans, folder zh_hans -> works
Language code: zh_hans, folder zh-hans -> ` No translation files found
for default language zh_hans.`
Language code: zh-hans, folder zh-hans -> does not work. No errors, no
translations
Language code: zh-hans, folder zh_hans -> does not work. No erros, no
translations

looks like django does not treat zh-hans as a valid language code, which
is very very confusing because the default en-us is valid.
It look me a very long time to figure this out.


Edit: even zh_hans is not working with browser language detection, the
folder has to be named 'zh_Hans' even though request.LANGUAGE is 'zh-hans'

is there somether in the doc that pointed this out?

--

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

Django

unread,
Apr 21, 2018, 4:10:50 AM4/21/18
to django-...@googlegroups.com
#29348: "-" and "_" in language code should be consistent
-------------------------------------+-------------------------------------
Reporter: Shen Li | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: | Version: 2.0
Internationalization |
Severity: Normal | Resolution: invalid

Keywords: i18n, inconsistency | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => invalid


Comment:

There are two different language code formats, the
[https://en.wikipedia.org/wiki/IETF_language_tag IETF language tag] (e.g.
zh-Hans, zh-Hant) used for example in browser `Accept-Language` headers,
and the [https://en.wikipedia.org/wiki/Locale_(computer_software) Posix
locales] (e.g. zh_Hans, zh_Hant) used by the gettext translation system.
Django has the
[https://github.com/django/django/blob/21420096c4db78ccb8f549a29d662cff870d363c/django/utils/translation/trans_real.py#L76
to_locale and to_language] functions to convert between those formats.

So you should use the right format depending on the location of the
language code reference.
This is also explained in:
- https://docs.djangoproject.com/en/stable/topics/i18n/#term-language-
code
- https://docs.djangoproject.com/en/stable/topics/i18n/#term-locale-name

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

Reply all
Reply to author
Forward
0 new messages