Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #19142 -- Language codes can include numbers (RFC 3066). #457

Merged
merged 1 commit into from Oct 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions django/utils/translation/trans_real.py
Expand Up @@ -30,9 +30,10 @@
# magic gettext number to separate context from message # magic gettext number to separate context from message
CONTEXT_SEPARATOR = "\x04" CONTEXT_SEPARATOR = "\x04"


# Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9. # Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9
# and RFC 3066, section 2.1
accept_language_re = re.compile(r''' accept_language_re = re.compile(r'''
([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*) # "en", "en-au", "x-y-z", "*" ([A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8})*|\*) # "en", "en-au", "x-y-z", "es-419", "*"
(?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))? # Optional "q=1.00", "q=0.8" (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))? # Optional "q=1.00", "q=0.8"
(?:\s*,\s*|$) # Multiple accepts per header. (?:\s*,\s*|$) # Multiple accepts per header.
''', re.VERBOSE) ''', re.VERBOSE)
Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/i18n/tests.py
Expand Up @@ -715,6 +715,7 @@ def test_parse_spec_http_header(self):
# Good headers. # Good headers.
self.assertEqual([('de', 1.0)], p('de')) self.assertEqual([('de', 1.0)], p('de'))
self.assertEqual([('en-AU', 1.0)], p('en-AU')) self.assertEqual([('en-AU', 1.0)], p('en-AU'))
self.assertEqual([('es-419', 1.0)], p('es-419'))
self.assertEqual([('*', 1.0)], p('*;q=1.00')) self.assertEqual([('*', 1.0)], p('*;q=1.00'))
self.assertEqual([('en-AU', 0.123)], p('en-AU;q=0.123')) self.assertEqual([('en-AU', 0.123)], p('en-AU;q=0.123'))
self.assertEqual([('en-au', 0.5)], p('en-au;q=0.5')) self.assertEqual([('en-au', 0.5)], p('en-au;q=0.5'))
Expand All @@ -739,6 +740,7 @@ def test_parse_spec_http_header(self):
self.assertEqual([], p('da, en-gb;q=0.8, en;q=0.7,#')) self.assertEqual([], p('da, en-gb;q=0.8, en;q=0.7,#'))
self.assertEqual([], p('de;q=2.0')) self.assertEqual([], p('de;q=2.0'))
self.assertEqual([], p('de;q=0.a')) self.assertEqual([], p('de;q=0.a'))
self.assertEqual([], p('12-345'))
self.assertEqual([], p('')) self.assertEqual([], p(''))


def test_parse_literal_http_header(self): def test_parse_literal_http_header(self):
Expand Down