#34455: i18n_patterns() not respecting prefix_default_language=False
-------------------------------------+-------------------------------------
     Reporter:  Oussama Jarrousse    |                    Owner:  Sarah
                                     |  Boyce
         Type:  Bug                  |                   Status:  closed
    Component:                       |                  Version:  4.2
  Internationalization               |
     Severity:  Release blocker      |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
  internationalization, i18n,        |  checkin
  prefix_default_language            |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by aboutofpluto):

 Dear all,

 Thank you for the great work on this issue. Unfortunately, I think it is
 not completely solved. We upgraded django 4.1.3 to django 4.2 and got a
 similar problem.

 The patch in this thread is good to find the fallback language but is
 still no good if `LANGUAGE_CODE` is not 'en' AND the urls are translated.

 The `i18n_patterns` decorated patterns with
 `prefix_default_language=False`, and `LANGUAGE_CODE = 'fr'` return 404.
 Actually, if `LANGUAGE_CODE` is not 'en'.
 I am tracing the error, it seems to come from `get_language_from_path`
 that receives `exposition` (the french translation for `exhibition`
 instead of a language).
 Consequently it returns `False` and `get_language_from_request` also (I
 shouldn't have to use cookies or HTTP headers, right?).

 This patch does the trick (django/utils/translation/trans_real.py:548),
 replace `None` by `settings.LANGUAGE_CODE`:
 {{{
 def get_language_from_path(path, strict=False):
     """
     Return the language code if there's a valid language code found in
 `path`.

     If `strict` is False (the default), look for a country-specific
 variant
     when neither the language code nor its generic variant is found.
     """
     regex_match = language_code_prefix_re.match(path)
     if not regex_match:
         return None
     lang_code = regex_match[1]
     try:
         return get_supported_language_variant(lang_code, strict=strict)
     except LookupError:
         return settings.LANGUAGE_CODE

 }}}

 This post is not really useful as it is: it does not provide a correct bug
 report but it might be better now than before 4.2.1 is released.
 I am willing to create a real bug report and to work on it, let me know
 what you think.

 Best,
 Anthony

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34455#comment:24>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070187b4000a5a-c40fb96c-ee67-443a-ab74-1b881f489af8-000000%40eu-central-1.amazonses.com.

Reply via email to