#23689: Django detects HTTP Accept-Language header in case-sensitive manner -------------------------------------+------------------------------------- Reporter: wayneye | Owner: nobody Type: Bug | Status: closed Component: | Version: 1.7 Internationalization | Severity: Normal | Resolution: needsinfo Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 1 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Daniel Samuels): I've just hit this same problem today, here's some example code: views.py: {{{#!python class ExampleView(TemplateView): template_name = 'example.html' def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: context = super().get_context_data(**kwargs) context['language_code'] = translation.get_language() # ^-- should be pt-BR, but is pt return context }}} test_views.py {{{#!python def test_example_view(db, client): language_code = 'pt-BR' resp = client.get(reverse('example'), HTTP_ACCEPT_LANGUAGE=language_code) assert resp.context_data['language_code'] == language_code # ^-- AssertionError: pt-BR != pt }}} The code path that's going wrong is: * `LocaleMiddleware.process_request` calls `translation.get_language_from_request` * `get_language_from_request` calls `parse_accept_lang_header` which turns `pt-BR` ito `pt-br` * `get_language_from_request` then calls `get_supported_language_variant`, passing `pt-br` as the `lang_code` * `get_supported_language_variant` then runs `if code in supported_lang_codes`, which is `False` (note that `'pt-BR' in supported_lang_codes == True`) * `get_supported_language_variant` then returns the fallback lang_code `pt` -- Ticket URL: <https://code.djangoproject.com/ticket/23689#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/01070181628eb09e-bc7445ca-dc2a-4ddd-b9c7-7ee6cc91f4cd-000000%40eu-central-1.amazonses.com.