# i18n\_patterns and set\_language

**URL:** <https://forum.djangoproject.com/t/i18n-patterns-and-set-language/25759>\
**Category:** Templates & Frontend\
**Created:** [November 30, 2023, 2:51am UTC](https://forum.djangoproject.com/t/i18n-patterns-and-set-language/25759 "2023-11-30T02:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![killianarts](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/killianarts/32/17422_2.png) [@killianarts](https://forum.djangoproject.com/u/killianarts)\
**Post date:** [November 30, 2023, 2:51am UTC](https://forum.djangoproject.com/t/i18n-patterns-and-set-language/25759/1 "2023-11-30T02:51:13Z")

</div>

Hey, first time poster here.

I’m using the `set_language` helper function and ran into a small issue. I found that the language would switch from the default language to some other language, but I couldn’t switch back to the default language.

There are two ways to fix the problem. The first way was to set `prefix_default_language=True` in i18n\_patterns. The second way was to slightly modify `set_language` as so:

```python
def set_language(request):
    # next_url setup at the beginning

    # Strip out the language code from the url before translating the url.
    for lang_code, lang_name in settings.LANGUAGES:
        prefix = '/' + lang_code + '/'
        if next_url.startswith(prefix):
            next_url = next_url[len(prefix) - 1:]
            break
...

```

This makes set\_language work even if the `prefix_default_language` in i18n\_patterns is set to False.

Is there a good reason to keep `prefix_default_language` set to True, besides SEO?

---

<div class="post-metadata">

**Author:** ![killianarts](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/killianarts/32/17422_2.png) [@killianarts](https://forum.djangoproject.com/u/killianarts)\
**Post date:** [November 30, 2023, 6:28am UTC](https://forum.djangoproject.com/t/i18n-patterns-and-set-language/25759/2 "2023-11-30T06:28:57Z")

</div>

Hmm, doing a little digging, it seems like the above modification to `set_language` shouldn’t be necessary. Maybe I should ask a different question:

Is `set_language`/`translate_url` suppose to work even if `prefix_default_language=False` is set in `i18n_patterns`? Because it doesn’t work for me.
