mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #18149 -- Changed language codes for Chinese
Language codes for Chinese are zh_Hans (Simplified) and zh_Hant (Traditional). Added support for browsers that still send the deprecated language codes. Thanks to Olli Wang for the report.
This commit is contained in:
parent
cb2c3ce154
commit
c0a2388a1c
@ -127,6 +127,8 @@ LANGUAGES = (
|
||||
('ur', gettext_noop('Urdu')),
|
||||
('vi', gettext_noop('Vietnamese')),
|
||||
('zh-cn', gettext_noop('Simplified Chinese')),
|
||||
('zh-hans', gettext_noop('Simplified Chinese')),
|
||||
('zh-hant', gettext_noop('Traditional Chinese')),
|
||||
('zh-tw', gettext_noop('Traditional Chinese')),
|
||||
)
|
||||
|
||||
|
@ -485,6 +485,18 @@ LANG_INFO = {
|
||||
'name': 'Simplified Chinese',
|
||||
'name_local': '简体中文',
|
||||
},
|
||||
'zh-hans': {
|
||||
'bidi': False,
|
||||
'code': 'zh-hans',
|
||||
'name': 'Simplified Chinese',
|
||||
'name_local': '简体中文',
|
||||
},
|
||||
'zh-hant': {
|
||||
'bidi': False,
|
||||
'code': 'zh-hant',
|
||||
'name': 'Traditional Chinese',
|
||||
'name_local': '繁體中文',
|
||||
},
|
||||
'zh-tw': {
|
||||
'bidi': False,
|
||||
'code': 'zh-tw',
|
||||
|
@ -1,5 +1,8 @@
|
||||
# This file is distributed under the same license as the Django package.
|
||||
#
|
||||
# This is the *old* Simplified Chinese translation of Django
|
||||
# For future updates please use the translation in the "zh_Hans" directory.
|
||||
#
|
||||
# Translators:
|
||||
# Jannis Leidel <jannis@leidel.info>, 2011.
|
||||
# Kevin Shi <leiarix@gmail.com>, 2012.
|
||||
|
BIN
django/conf/locale/zh_Hans/LC_MESSAGES/django.mo
Normal file
BIN
django/conf/locale/zh_Hans/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1224
django/conf/locale/zh_Hans/LC_MESSAGES/django.po
Normal file
1224
django/conf/locale/zh_Hans/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
0
django/conf/locale/zh_Hans/__init__.py
Normal file
0
django/conf/locale/zh_Hans/__init__.py
Normal file
24
django/conf/locale/zh_Hans/formats.py
Normal file
24
django/conf/locale/zh_Hans/formats.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# This file is distributed under the same license as the Django package.
|
||||
#
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# The *_FORMAT strings use the Django date format syntax,
|
||||
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
|
||||
# DATE_FORMAT =
|
||||
# TIME_FORMAT =
|
||||
# DATETIME_FORMAT =
|
||||
# YEAR_MONTH_FORMAT =
|
||||
# MONTH_DAY_FORMAT =
|
||||
# SHORT_DATE_FORMAT =
|
||||
# SHORT_DATETIME_FORMAT =
|
||||
# FIRST_DAY_OF_WEEK =
|
||||
|
||||
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
|
||||
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
|
||||
# DATE_INPUT_FORMATS =
|
||||
# TIME_INPUT_FORMATS =
|
||||
# DATETIME_INPUT_FORMATS =
|
||||
# DECIMAL_SEPARATOR =
|
||||
# THOUSAND_SEPARATOR =
|
||||
# NUMBER_GROUPING =
|
BIN
django/conf/locale/zh_Hant/LC_MESSAGES/django.mo
Normal file
BIN
django/conf/locale/zh_Hant/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1227
django/conf/locale/zh_Hant/LC_MESSAGES/django.po
Normal file
1227
django/conf/locale/zh_Hant/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
0
django/conf/locale/zh_Hant/__init__.py
Normal file
0
django/conf/locale/zh_Hant/__init__.py
Normal file
24
django/conf/locale/zh_Hant/formats.py
Normal file
24
django/conf/locale/zh_Hant/formats.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# This file is distributed under the same license as the Django package.
|
||||
#
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# The *_FORMAT strings use the Django date format syntax,
|
||||
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
|
||||
# DATE_FORMAT =
|
||||
# TIME_FORMAT =
|
||||
# DATETIME_FORMAT =
|
||||
# YEAR_MONTH_FORMAT =
|
||||
# MONTH_DAY_FORMAT =
|
||||
# SHORT_DATE_FORMAT =
|
||||
# SHORT_DATETIME_FORMAT =
|
||||
# FIRST_DAY_OF_WEEK =
|
||||
|
||||
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
|
||||
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
|
||||
# DATE_INPUT_FORMATS =
|
||||
# TIME_INPUT_FORMATS =
|
||||
# DATETIME_INPUT_FORMATS =
|
||||
# DECIMAL_SEPARATOR =
|
||||
# THOUSAND_SEPARATOR =
|
||||
# NUMBER_GROUPING =
|
@ -1,5 +1,8 @@
|
||||
# This file is distributed under the same license as the Django package.
|
||||
#
|
||||
# This is the *old* Traditional Chinese translation of Django
|
||||
# For future updates please use the translation in the "zh_Hant" directory.
|
||||
#
|
||||
# Translators:
|
||||
# <ilay@ilay.tw>, 2012.
|
||||
# Jannis Leidel <jannis@leidel.info>, 2011.
|
||||
|
@ -202,6 +202,17 @@ def activate(language):
|
||||
language and installs it as the current translation object for the current
|
||||
thread.
|
||||
"""
|
||||
if isinstance(language, basestring):
|
||||
if language == 'zh-cn':
|
||||
warnings.warn(
|
||||
"The use of the language code 'zh-cn' is deprecated. "
|
||||
"Please use the 'zh-hans' translation instead.",
|
||||
PendingDeprecationWarning, stacklevel=2)
|
||||
elif language == 'zh-tw':
|
||||
warnings.warn(
|
||||
"The use of the language code 'zh-tw' is deprecated. "
|
||||
"Please use the 'zh-hant' translation instead.",
|
||||
PendingDeprecationWarning, stacklevel=2)
|
||||
_active.value = translation(language)
|
||||
|
||||
|
||||
@ -399,6 +410,12 @@ def get_supported_language_variant(lang_code, supported=None, strict=False):
|
||||
If `strict` is False (the default), the function will look for an alternative
|
||||
country-specific variant when the currently checked is not found.
|
||||
"""
|
||||
# some browsers use deprecated language codes -- #18419
|
||||
if lang_code == 'zh-cn' and 'zh-hans' in supported:
|
||||
return 'zh-hans'
|
||||
elif lang_code == 'zh-tw' and 'zh-hant' in supported:
|
||||
return 'zh-hant'
|
||||
|
||||
if supported is None:
|
||||
from django.conf import settings
|
||||
supported = OrderedDict(settings.LANGUAGES)
|
||||
|
@ -476,6 +476,9 @@ these changes.
|
||||
|
||||
* The class ``django.utils.datastructures.MergeDict`` will be removed.
|
||||
|
||||
* The ``zh_CN`` and ``zh_TW`` language codes will be removed and have been
|
||||
replaced by the ``zh_Hans`` and ``zh_Hant`` language code respectively.
|
||||
|
||||
2.0
|
||||
---
|
||||
|
||||
|
@ -697,3 +697,11 @@ deprecated and will be removed in Django 1.9.
|
||||
arguments into a ``REQUEST`` property on ``WSGIRequest``. To merge
|
||||
dictionaries, use ``dict.update()`` instead. The class ``MergeDict`` is
|
||||
deprecated and will be removed in Django 1.9.
|
||||
|
||||
Language codes ``zh_CN`` and ``zh_TW``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The currently used language codes for Simplified Chinese ``zh_CN`` and
|
||||
Traditional Chinese ``zh_TW`` are deprecated and should be replaced by the
|
||||
recently introduced language codes ``zh_Hans`` and ``zh_Hant`` respectively.
|
||||
The deprecated language codes will be removed in Django 1.9.
|
||||
|
@ -1,8 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
import warnings
|
||||
|
||||
from django.test import SimpleTestCase, RequestFactory
|
||||
from django.utils import six
|
||||
from django.test import SimpleTestCase, RequestFactory, override_settings
|
||||
from django.utils import six, translation
|
||||
from django.utils.deprecation import RenameMethodsBase
|
||||
|
||||
|
||||
@ -186,3 +186,22 @@ class DeprecatingRequestMergeDictTest(SimpleTestCase):
|
||||
'`request.POST` instead.',
|
||||
'`MergeDict` is deprecated, use `dict.update()` instead.',
|
||||
])
|
||||
|
||||
|
||||
@override_settings(USE_I18N=True)
|
||||
class DeprecatedChineseLanguageCodes(SimpleTestCase):
|
||||
def test_deprecation_warning(self):
|
||||
warnings.simplefilter('always')
|
||||
|
||||
with warnings.catch_warnings(record=True) as recorded:
|
||||
with translation.override('zh-cn'):
|
||||
pass
|
||||
with translation.override('zh-tw'):
|
||||
pass
|
||||
msgs = [str(warning.message) for warning in recorded]
|
||||
self.assertEqual(msgs, [
|
||||
"The use of the language code 'zh-cn' is deprecated. "
|
||||
"Please use the 'zh-hans' translation instead.",
|
||||
"The use of the language code 'zh-tw' is deprecated. "
|
||||
"Please use the 'zh-hant' translation instead.",
|
||||
])
|
||||
|
@ -871,6 +871,31 @@ class MiscTests(TransRealMixin, TestCase):
|
||||
r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'}
|
||||
self.assertEqual(g(r), 'zh-cn')
|
||||
|
||||
@override_settings(
|
||||
LANGUAGES=(
|
||||
('en', 'English'),
|
||||
('zh-hans', 'Simplified Chinese'),
|
||||
('zh-hant', 'Traditional Chinese'),
|
||||
)
|
||||
)
|
||||
def test_support_for_deprecated_chinese_language_codes(self):
|
||||
"""
|
||||
Some browsers (Firefox, IE etc) use deprecated language codes. As these
|
||||
language codes will be removed in Django 1.9, these will be incorrectly
|
||||
matched. For example zh-tw (traditional) will be interpreted as zh-hans
|
||||
(simplified), which is wrong. So we should also accept these deprecated
|
||||
language codes.
|
||||
|
||||
refs #18419 -- this is explicitly for browser compatibility
|
||||
"""
|
||||
g = get_language_from_request
|
||||
r = self.rf.get('/')
|
||||
r.COOKIES = {}
|
||||
r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,en'}
|
||||
self.assertEqual(g(r), 'zh-hans')
|
||||
r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-tw,en'}
|
||||
self.assertEqual(g(r), 'zh-hant')
|
||||
|
||||
def test_parse_language_cookie(self):
|
||||
"""
|
||||
Now test that we parse language preferences stored in a cookie correctly.
|
||||
|
Loading…
Reference in New Issue
Block a user