Skip to content
Advertisement

How to add new site language in Django admin

I work on a project where we want to have multilingual site. We start with two languages defined in settings.py

LANGUAGES = (
    ("en-us", _("United States")),
    ("cs", _("Czech Republic")),
)

I am not the programmer doing the work but if I understood correctly all we need is to be able to add – for example – French language for the whole website but not via setting.py but Django admin web interface.

LANGUAGES = (
    ("en-us", _("United States")),
    ("cs", _("Czech Republic")),
    ("fr", _("French")),
)

We are using rosetta for translating in Django admin. So I want to use Django admin to add new laguage so it appears in rosetta interface.

Could someone tell me how we can control ( add or remove or disable ) languages from Django admin?

I checked these but did not find the answer

Advertisement

Answer

The short answer is that you can’t do that.

The settings.py of a Django project is not designed, and not recommended to be modified by the web application.(It can introduce a security breach.)

So I recommend to change LANGUAGES manually, or to enable all languages supported by Django by removing LANGUAGES key. Of course, don’t forget to generate message files with the makemessages command.

If you really want such a dynamic feature, your best bet will be to implement it on your own by modifying the Django Rosetta source code.(Define a preference item for supported languages on a DB model, and filter languages by its value.)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement