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