Giter Site home page Giter Site logo

ok-language-tools's Introduction

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

ok-language-tools's People

Contributors

lowerdeez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.