Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • Adding new site language in Django admin
  • How to manage system languages from django admin site?
  • https://djangowaves.com/tutorial/multiple-languages-in-Django/
  • Add translation for model field using django rosetta
  • Adding languages dynamically through Django Admin
like image 774
Radek Avatar asked Oct 22 '25 06:10

Radek


1 Answers

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.)

like image 95
relent95 Avatar answered Oct 23 '25 21:10

relent95