Browse Source

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 <dan@zerolab.org>
Sævar Öfjörð Magnússon 2 years ago
parent
commit
0705f1d765
1 changed files with 44 additions and 1 deletions
  1. 44 1
      docs/advanced_topics/i18n.md

+ 44 - 1
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