From 0705f1d76556891a9c9551b164de4c32ccefcd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A6var=20=C3=96fj=C3=B6r=C3=B0=20Magn=C3=BAsson?= Date: Tue, 28 Jun 2022 09:41:08 +0000 Subject: [PATCH] Document the prefix_default_language parameter to i18n_patterns (#8763) * Document the prefix_default_language parameter to i18n_patterns * Update docs/advanced_topics/i18n.md Co-authored-by: Dan Braghis --- docs/advanced_topics/i18n.md | 45 +++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/advanced_topics/i18n.md b/docs/advanced_topics/i18n.md index dee65d2246..c0340f6e4c 100644 --- a/docs/advanced_topics/i18n.md +++ b/docs/advanced_topics/i18n.md @@ -250,7 +250,7 @@ want to be translated) into an `i18n_patterns` block: ```python # /my_project/urls.py -... +# ... from django.conf.urls.i18n import i18n_patterns @@ -272,6 +272,49 @@ urlpatterns += i18n_patterns( ) ``` +##### Bypass language prefix for the default language + +If you want your default language to have URLs that resolve normally without a language prefix, +you can set the `prefix_default_language` parameter of `i18n_patterns` to `False`. +For example, if you have your languages configured like this: + +```python +# myproject/settings.py + +# ... + +LANGUAGE_CODE = 'en' +WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [ + ('en', "English"), + ('fr', "French"), +] + +# ... +``` + +And your `urls.py` configured like this: + +```python +# myproject/urls.py +# ... + +# These URLs will be available under a language code prefix only for languages that +# are not set as default in LANGUAGE_CODE. + +urlpatterns += i18n_patterns( + path('search/', search_views.search, name='search'), + path("", include(wagtail_urls)), + prefix_default_language=False, +) +``` + +Your URLs will now be prefixed only for the French version of your website, e.g. + +``` +- /search/ +- /fr/search/ +``` + #### User language auto-detection After wrapping your URL patterns with `i18n_patterns`, your site will now