4

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

Radek
  • 13,813
  • 52
  • 161
  • 255
  • Have you tried: https://stackoverflow.com/a/21470003/11475846 – Lewis Nov 09 '22 at 07:16
  • 1
    I modified the question - I want to add new language not change language in Django admin. – Radek Nov 09 '22 at 07:27
  • Even if I really would like to have the bounty, it's too much work to copy the answer from this page https://testdriven.io/blog/multiple-languages-in-django/ here is exactly discibed how it works. 1. set up settings 2. create locale directory with your translations 3. tag all the positions in your app they need to be translated - This is the way you should do it. – Andy_Lima Nov 18 '22 at 07:15

1 Answers1

7

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

relent95
  • 3,703
  • 1
  • 14
  • 17
  • in other project ( multitenant ) of mine how would it work if I eneable all languages but each tenant might have only selected languages available? – Radek Nov 12 '22 at 08:29
  • 1
    For that, you also have to modify the Django Rosetta source code. For example, a preference item for supported languages can be defined for each tenant. – relent95 Nov 12 '22 at 12:03