A django app that allows to swich the language based on the domain
Project description
django-domain-language
A django app that allows to swich the language based on the domain the django server is accessed with.
You might be runing a site called mysite.com
and want to run the german version of the site under meineseite.de
this app helps you doing this. You can configure what domain should be served in what language. You can also use it to
configure language specific subdomains like de.mysite.com and fr.mysite.com.
Installation
Install the package with
python setup.py install
Add domain_lang
to the installed apps
INSTALLED_APPS = [
...
'domain_lang',
]
Add the Middleware after LocaleMiddleware
MIDDLEWARE = [
...
'django.middleware.locale.LocaleMiddleware',
'domain_lang.middleware.DomainLanguageMiddleware',
...
]
If you want to have access to the configured domains in your templates add domain_lang.context_processors.domain_language
to the context_processors.
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'domain_lang.context_processors.domain_language',
],
},
},
]
Finally run the migrations to create the database tables.
python manage.py migrate
Usage
After installing it and runing the django server you will find the DomainLanguageMappings in your admin.
There you can configure the domains and their respecitve language. The Middleware will then always set the acitve language based on the domain of the reuqest.
If no Mapping is configured for the active domain the language set by LocaleMiddleware
will be in place.
Cookies
You have to login for each domain seperatly. If you use subdomains for your langauge selection (en.example.com, de.example.com, ...)
you can prepend the SESSION_COOKIE_DOMAIN
with a dot, which will allow you to log in once for all subdomains.
SESSION_COOKIE_DOMAIN = '.example.com'
Template Context
If you have added domain_lang.context_processors.domain_language
to your context_processors, all Mappings will be provided
in the variable called language_mappings
. You can use this to show links to other versions of your site.
Template Tag
This app provides one template tag that allows you to translate a domain. It will also translate the domain part of the given url according to the configured mappgings
{% load domain_lang %}
{% translate_url 'mysite.com/contact/' 'de' %} # Might be translated to meineseite.de/kontakt/
LICENSE
django-domain-language is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-domain-language-0.0.1.tar.gz
.
File metadata
- Download URL: django-domain-language-0.0.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21d92605f3012a686db35f7114c4b04efbc74447205db7f120563207b4b9da99 |
|
MD5 | e3b96bfd79a2ea2d639a6eefa95d991a |
|
BLAKE2b-256 | 39bc7266e6b3ca11dedc6182c9c016de677d8c3af8270d4e3375780a889468a5 |
File details
Details for the file django_domain_language-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_domain_language-0.0.1-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d1b0354d94da9f600a6fcfe6d0102dcdb874e9651312cdfa3e374998bbdb7a |
|
MD5 | 4b4bb966729e71626126b92853b52d6d |
|
BLAKE2b-256 | 2a4b65f8d57e254286beec48161b68047d281e6529f952ffa3ae7a5973c22b9b |