Some language tools for Django.
Install with pip:
$ pip install django-ok-language-tools
Update INSTALLED_APPS:
INSTALLED_APPS = [
...
'ok_language_tools',
...
]
LANGUAGE_TOOLS_REDIRECT_TO_QUERY_PARAMETER
- Query parameter to get next url for 'set_language' view.
LANGUAGE_TOOLS_LANGUAGE_QUERY_PARAMETER
- Query parameter to get languge to translate next url for 'set_language' view.
LANGUAGE_TOOLS_REDIRECT_EXCLUDE_PREFIXES
- Tuple of prefixes to skip redirect for 'language_redirect_middleware'.
For example:
LANGUAGE_TOOLS_REDIRECT_EXCLUDE_PREFIXES = (
'/api/v1/',
'/uploads/',
'/static/',
)
LANGUAGE_TOOLS_DEFAULT_REDIRECT_LANGUAGE
- Language code to redirect for a first user visit.
LANGUAGE_TOOLS_VISITED_SESSION_KEY
- Key to store visited state in session.
- Add 'language_redirect_middleware' to the MIDDLEWARE configuration to redirect users to default language during a first visit:
MIDDLEWARE = [
...
'ok_language_tools.middleware.language_redirect_middleware'
]
- To enable 'set_language' view, add next URL patterns:
urlpatterns = [
...
path('', include('ok_language_tools.urls')),
]
language_url = reverse('ok-language-tools:set-language')
catalog_url = '/catalog/'
language = 'uk'
set_language_url = f'{language_url}?redirect_to={catalog_url}&language={language}'
# or using HTTP_REFERER
set_language_url = f'{language_url}?language={language}'