Skip to content

LowerDeez/ok-language-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-ok-language-tools PyPI version

Build status Code health Python versions PyPI downloads Software license Project Status

Some language tools for Django.

Installation

Install with pip:

$ pip install django-ok-language-tools

Update INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'ok_language_tools',
    ...
]

Available settings

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.

Quickstart

  • 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}'

About

Some Django language tools

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages