Opened 12 years ago

Closed 12 years ago

#19381 closed Bug (duplicate)

Translations fail when using Latin American Spanish and Regular spanish in Chrome

Reported by: Dan Loewenherz Owned by: nobody
Component: Internationalization Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Chrome I have the following languages set, in this order of precedence:

1) Latin American Spanish
2) Spanish
3) US English
4) English

The site has been localized for Spanish and renders perfectly in Firefox, Opera, and IE. When I view it in Chrome, however, it renders in English. I have cleared cache multiple times and am viewing the site in incognito. The Accept Language request header is this:

Accept-Language: es-419,es;q=0.8,en-US;q=0.6,en;q=0.4

Which is appropriate. I dug a little deeper and found this in django/utils/translation/trans_real.py

def parse_accept_lang_header(lang_string):
    """
    Parses the lang_string, which is the body of an HTTP Accept-Language
    header, and returns a list of (lang, q-value), ordered by 'q' values.

    Any format errors in lang_string results in an empty list being returned.
    """
    result = []
    pieces = accept_language_re.split(lang_string)
    if pieces[-1]:
        return []
    for i in range(0, len(pieces) - 1, 3):
        first, lang, priority = pieces[i : i + 3]
        if first:
            return []
        priority = priority and float(priority) or 1.0
        result.append((lang, priority))
    result.sort(key=lambda k: k[1], reverse=True)
    return result

With the header string I gave above, pieces becomes ['es-419,', 'es', '0.8', '', 'en-US', '0.6', '', 'en', '0.4', '']. In the first trio, first resolves to es-419,. The conditional if first passes, and then the parse_accept_lang_header returns an empty list, basically telling anything that calls this guy that the headers have no language info, which is incorrect.

Why does if first fail here? What can be done to fix this?

Change History (1)

comment:1 by Claude Paroz, 12 years ago

Resolution: duplicate
Status: newclosed

I guess this has been fixed in #19142.

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