Opened 7 years ago

Closed 7 years ago

#29348 closed Cleanup/optimization (invalid)

"-" and "_" in language code should be consistent

Reported by: Shen Li Owned by: nobody
Component: Internationalization Version: 2.0
Severity: Normal Keywords: i18n, inconsistency
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Shen Li)

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?

Change History (2)

comment:1 by Shen Li, 7 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 7 years ago

Resolution: invalid
Status: newclosed

There are two different language code formats, the IETF language tag (e.g. zh-Hans, zh-Hant) used for example in browser Accept-Language headers, and the Posix locales (e.g. zh_Hans, zh_Hant) used by the gettext translation system. Django has the 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:

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