Ticket #6409: 6409-6446-with-regression-tests.diff
File 6409-6446-with-regression-tests.diff, 3.6 KB (added by , 17 years ago) |
---|
-
django/conf/global_settings.py
diff -r f0b754562bac django/conf/global_settings.py
a b LANGUAGES = ( 47 47 ('el', gettext_noop('Greek')), 48 48 ('en', gettext_noop('English')), 49 49 ('es', gettext_noop('Spanish')), 50 ('es _AR', gettext_noop('Argentinean Spanish')),50 ('es-ar', gettext_noop('Argentinean Spanish')), 51 51 ('fa', gettext_noop('Persian')), 52 52 ('fi', gettext_noop('Finnish')), 53 53 ('fr', gettext_noop('French')), -
django/utils/translation/trans_real.py
diff -r f0b754562bac django/utils/translation/trans_real.py
a b def get_language_from_request(request): 357 357 return lang_code 358 358 359 359 accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '') 360 for lang, unused in parse_accept_lang_header(accept):361 if lang == '*':360 for accept_lang, unused in parse_accept_lang_header(accept): 361 if accept_lang == '*': 362 362 break 363 363 364 364 # We have a very restricted form for our language files (no encoding … … def get_language_from_request(request): 366 366 # language each time. So we avoid the overhead of gettext.find() and 367 367 # look up the MO file manually. 368 368 369 normalized = locale.locale_alias.get(to_locale( lang, True))369 normalized = locale.locale_alias.get(to_locale(accept_lang, True)) 370 370 if not normalized: 371 371 continue 372 372 … … def get_language_from_request(request): 378 378 # need to check again. 379 379 return _accepted[normalized] 380 380 381 for lang in ( normalized, normalized.split('_')[0]):381 for lang in (accept_lang, accept_lang.split('-')[0]): 382 382 if lang not in supported: 383 383 continue 384 langfile = os.path.join(globalpath, lang, 'LC_MESSAGES', 384 normalized = locale.locale_alias.get(to_locale(lang, True)).split('.')[0] 385 langfile = os.path.join(globalpath, normalized, 'LC_MESSAGES', 385 386 'django.mo') 386 387 if os.path.exists(langfile): 387 388 _accepted[normalized] = lang -
tests/regressiontests/i18n/misc.py
diff -r f0b754562bac tests/regressiontests/i18n/misc.py
a b Bad headers; should always return []. 54 54 >>> p('') 55 55 [] 56 56 57 >>> from django.utils.translation.trans_real import get_language_from_request 58 >>> g = get_language_from_request 59 >>> from django.http import HttpRequest 60 >>> r = HttpRequest 61 >>> r.COOKIES = {} 62 63 These tests assumes the es, es_AR, pt and pt_BR translations aren't going to 64 be deleted from the Django source tree. 65 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt-br'} 66 >>> g(r) 67 'pt-br' 68 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt'} 69 >>> g(r) 70 'pt' 71 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es,de'} 72 >>> g(r) 73 'es' 74 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-ar,de'} 75 >>> g(r) 76 'es-ar' 77 78 This test assumes there won't be a Django translation to a US variation 79 of the Spanish language, a safe assumption. When the user sets it 80 as the preferred language, the main 'es' translation should be selected 81 instead. 82 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-us'} 83 >>> g(r) 84 'es' 85 86 This tests the following scenario: there isn't a main language (zh) 87 translation of Django but there is a translation to variation (zh_CN) 88 the user sets zh-cn as the preferred language, it should be selected by 89 Django without falling back nor ignoring it. 90 >>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'} 91 >>> g(r) 92 'zh-cn' 93 57 94 """