Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Language codes can include numbers, e.g. es-419 is Spanish for LatAm and... #87

Closed
wants to merge 1 commit into from

5 participants

Dave Dash Ramiro Morales Danilo Bargen Simon Meers Claude Paroz
Dave Dash

... Carribean.

Sorry I didn't add a test-case or anything else, but the test case is that

parse_accept_lang_header('es-419') would result in (('es-419', 1.0),) or something ;)

Dave Dash Language codes can include numbers, e.g. es-419 is Spanish for LatAm …
…and Carribean.


Sorry I didn't add a test-case or anything else, but the test case is that 

parse_accept_lang_header('es-419') would result in (('es-419', 1.0),) or something ;)
ddccb1e
Ramiro Morales
Owner
ramiro commented May 29, 2012

IS there any online resource where information about this can be confirmed?

Danilo Bargen
dbrgn commented June 05, 2012

The number based language code seems to be a valid IETF language tag. The HTTP 1.1 RFC 2616 doesn't seem to mention alphanumeric subtags, but RFC 3066 does (Section 2.1). RFC 3066 has since been superseded by RFC 5646, which adds a bunch of new stuff.

I'm not sure which one Django would have to follow, or whether HTTP 1.1 allows newer forms of language tags.

Dave Dash

I think the reality is that es-419 is being sent by browsers (Chrome for example) and Django shouldn't filter it out.

Without this patch what happens is even if I list es-419 as my least favorite language, but still keep it in my accept-headers, that entire accept-languag header is ignored, and none of my preferences is adhered to.

e.g.:

es;en;it;de;en-US;es-419

would be invalid, and I would be served LANGUAGE_CODE instead of 'es'.

Danilo Bargen
dbrgn commented on ddccb1e June 11, 2012

In case some core dev agrees on changing this, there are probably more places where we'd have to change the regexes.

Simon Meers
Owner

Together with the RFCs above, this list also confirms the use of UN region codes in language tags

Claude Paroz
Owner

The ticket has been accepted (https://code.djangoproject.com/ticket/19142). Closing the pull request as tests are missing. Feel free to resubmit one with tests included.

Claude Paroz claudep closed this October 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 21, 2012
Dave Dash Language codes can include numbers, e.g. es-419 is Spanish for LatAm …
…and Carribean.


Sorry I didn't add a test-case or anything else, but the test case is that 

parse_accept_lang_header('es-419') would result in (('es-419', 1.0),) or something ;)
ddccb1e
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  django/utils/translation/trans_real.py
2  django/utils/translation/trans_real.py
@@ -29,7 +29,7 @@
29 29
 
30 30
 # Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9.
31 31
 accept_language_re = re.compile(r'''
32  
-        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)         # "en", "en-au", "x-y-z", "*"
  32
+        ([A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8})*|\*)         # "en", "en-au", "x-y-z", "*"
33 33
         (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
34 34
         (?:\s*,\s*|$)                                 # Multiple accepts per header.
35 35
         ''', re.VERBOSE)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.