0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

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>
This commit is contained in:
Sævar Öfjörð Magnússon 2022-06-28 09:41:08 +00:00 committed by GitHub
parent b8a9a2d319
commit 0705f1d765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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