Skip to main content

Some language tools for Django.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ok-language-tools-0.0.4.tar.gz (6.2 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page