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>
pull/8755/head
Sævar Öfjörð Magnússon 2022-06-28 09:41:08 +00:00 zatwierdzone przez GitHub
rodzic b8a9a2d319
commit 0705f1d765
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 44 dodań i 1 usunięć

Wyświetl plik

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