Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d44b117b
Commit
d44b117b
authored
Apr 02, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3148 from louyihua/localization-fix
Make new-style chinese language codes works for translation
parents
f5c91984
80e12705
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletions
+49
-1
common/djangoapps/dark_lang/middleware.py
+37
-1
common/djangoapps/dark_lang/tests.py
+12
-0
No files found.
common/djangoapps/dark_lang/middleware.py
View file @
d44b117b
...
...
@@ -16,6 +16,42 @@ from django.utils.translation.trans_real import parse_accept_lang_header
from
dark_lang.models
import
DarkLangConfig
def
dark_parse_accept_lang_header
(
accept
):
'''
The use of 'zh-cn' for 'Simplified Chinese' and 'zh-tw' for 'Traditional Chinese'
are now deprecated, as discussed here: https://code.djangoproject.com/ticket/18419.
The new language codes 'zh-hans' and 'zh-hant' are now used since django 1.7.
Although majority of browsers still use the old language codes, some new browsers
such as IE11 in Windows 8.1 start to use the new ones, which makes the current
chinese translations of edX don't work properly under these browsers.
This function can keep compatibility between the old and new language codes. If one
day edX uses django 1.7 or higher, this function can be modified to support the old
language codes until there are no browsers use them.
'''
browser_langs
=
parse_accept_lang_header
(
accept
)
django_langs
=
[]
for
lang
,
priority
in
browser_langs
:
lang
=
CHINESE_LANGUAGE_CODE_MAP
.
get
(
lang
.
lower
(),
lang
)
django_langs
.
append
((
lang
,
priority
))
return
django_langs
# If django 1.7 or higher is used, the right-side can be updated with new-style codes.
CHINESE_LANGUAGE_CODE_MAP
=
{
# The following are the new-style language codes for chinese language
'zh-hans'
:
'zh-CN'
,
# Chinese (Simplified),
'zh-hans-cn'
:
'zh-CN'
,
# Chinese (Simplified, China)
'zh-hans-sg'
:
'zh-CN'
,
# Chinese (Simplified, Singapore)
'zh-hant'
:
'zh-TW'
,
# Chinese (Traditional)
'zh-hant-hk'
:
'zh-TW'
,
# Chinese (Traditional, Hongkong)
'zh-hant-mo'
:
'zh-TW'
,
# Chinese (Traditional, Macau)
'zh-hant-tw'
:
'zh-TW'
,
# Chinese (Traditional, Taiwan)
# The following are the old-style language codes that django does not recognize
'zh-hk'
:
'zh-TW'
,
# Chinese (Traditional, Hongkong)
'zh-mo'
:
'zh-TW'
,
# Chinese (Traditional, Macau)
'zh-sg'
:
'zh-CN'
,
# Chinese (Simplified, Singapore)
}
class
DarkLangMiddleware
(
object
):
"""
Middleware for dark-launching languages.
...
...
@@ -65,7 +101,7 @@ class DarkLangMiddleware(object):
new_accept
=
", "
.
join
(
self
.
_format_accept_value
(
lang
,
priority
)
for
lang
,
priority
in
parse_accept_lang_header
(
accept
)
in
dark_
parse_accept_lang_header
(
accept
)
if
self
.
_is_released
(
lang
)
)
...
...
common/djangoapps/dark_lang/tests.py
View file @
d44b117b
...
...
@@ -208,3 +208,15 @@ class DarkLangMiddlewareTests(TestCase):
'rel'
,
self
.
process_request
(
preview_lang
=
'unrel'
,
django_language
=
'rel'
)
)
def
test_accept_chinese_language_codes
(
self
):
DarkLangConfig
(
released_languages
=
(
'zh-cn, zh-tw'
),
changed_by
=
self
.
user
,
enabled
=
True
)
.
save
()
self
.
assertAcceptEquals
(
'zh-CN;q=1.0, zh-TW;q=0.5, zh-TW;q=0.3'
,
self
.
process_request
(
accept
=
'zh-Hans;q=1.0, zh-Hant-TW;q=0.5, zh-hk;q=0.3'
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment