I do something like this in my projects.
Step zero: we are determined with the list of supported languages
If you donāt need to support Arabic, Japanese and other exotic things, you can set up in the settings a list of languages āāthat will work on the site:
# settings.py from django.utils.translation import ugettext_lazy as _ LANGUAGES = [ ('en', _('English')), ('ru', _('Russian')), ]
By default, all languages āāavailable in Django are set up in the LANGUAGES setting, so if you donāt want to restrict anything, you can leave the settings unchanged.
Step one: create a model for storing settings
# models.py from django.conf import settings from django.utils.translation import ugettext_lazy as _ class WebsiteSettings(models.Model): language = models.CharField(max_length=16, unique=True, choices=settings.LANGUAGES, verbose_name=_('Language')) some_text = models.TextField(blank=True, verbose_name=_('Some text')) class Meta: verbose_name = _('website settings') verbose_name_plural = _('website settings') ordering = ['language'] def __str__(self): return dict(settings.LANGUAGES).get(self.language, self.language)
All salt in the language field: each language has its own and unique copy of WebsiteSettings . All other fields are registered to your taste as needed. Migrations, admin and other rubbish are done in the same way as for any other model.
Step two: we push settings in templates
The cap is usually on every page, but each time itās inconvenient to get the settings in each view, so we will register the receiving of the settings in context_processors .
Create such a context_processors.py file (or context_processors.py existing one):
from .models import WebsiteSettings def website_settings(request): web_settings = WebsiteSettings.objects.filter(language=request.LANGUAGE_CODE).first() if not web_settings: web_settings = WebsiteSettings(language='fallback') return {'web_settings': web_settings}
And turn it on in the settings:
# settings.py TEMPLATES = [ { # ... Š²ŃŠµ оŃŃŠ°Š»ŃŠ½ŃŠµ ŠæŠ°ŃŠ°Š¼ŠµŃŃŃ ... 'OPTIONS': { 'context_processors': [ # ... Š²ŃŠµ оŃŃŠ°Š»ŃŠ½ŃŠµ ŠæŠ°ŃŠ°Š¼ŠµŃŃŃ ... 'ŠøŠ¼ŃŠæŃиложениŃ.context_processors.website_settings', ], }, }, ]
Now in each template there will be a web_settings object for the current language, the fields of which can be accessed like this:
{{ web_settings.some_text }}
As Django selects the current language, read somewhere in the documentation . And LocaleMiddleware not forget to include LocaleMiddleware .