How to add new site language in Django admin - python

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

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

Related

Django-ckeditor5 how to set codeblock's programming languages in admin template

I am integrating django-ckeditor5 in my Django website but facing some difficulties with adjusting the programming languages that appears on the code-block drop-down from my admin.
I want to customize this section to only include programming languages like Python, SQL and JavaScript. I haven't seen a way to configure this via the setting.py file. Please, I need help.

Using Django admin as a base for backend

First sorry for my poor English.
I came from asp.net mvc. Now I use django with nanoboxio
In asp, I can create sections like below.
Create model and add it to dbcontext
Right click controller folder and create new controller with views.
Modify as you wish
For now, I know Django can create admin interface for your model. I try and happy with it. but i want to develop it.
I want to for example;
Create a post model.
Create a admin interface for it.
Copy generated admin interface controller and views to another app
Modify it
How can I do that?
Django's MVC is quite different to ASP.
Django's MVC pattern is less strict so you sort of combine the view and the controller in the views.py. However, if you want to change the Admin, the Django docs are quite nice here: docs.djangoproject.com
If you want to create a custom admin functionality the docs should give you a first idea and if you're planning to create a blog, I would advice you to use an existing plugin such as Zinnia. There, you can find the desired functionalities and modify them instead of building them from scratch.
Also, there are a couple of tutorials on how to build reusable apps and they usually include a detailed guideline how to implement admin functionalities there. Just look it up on google.
I hope that helps you!

Which languages are supported by django as part I18N, Localization

I'm trying to do Internationalization using Django. I've followed through docs and able to set it up right.
My questions here are
i) What are all the language supported by django?
ii) I've created '.po', '.mo' message files for the languages 'de' , 'de-at' but when trying to access those resources from API I'm only able to get resources from 'de' for both the cases. Does Django overrides 'de-at' by 'de' message file resources. Why is it so?
I've created message files using below commands by executing in project directory.
django-admin.py makemessages -l de
After running above command. I've added resources for both the languages corresponding in their '.po' file
django-admin.py compilemessages
Any help would be appreciated.
de-at is not supported by Django. So by default Django takes de message files.
Django documentation says :
In each of these places, the language preference is expected to be in the standard language format, as a string. For example, Brazilian Portuguese is pt-br.
If a base language is available but the sublanguage specified is not, Django uses the base language. For example, if a user specifies de-at (Austrian German) but Django only has de available, Django uses de.
Hence It returns messages inside a file 'de'
If the question is actual this might help you.
I had task to translate website both to de and de-at.
Django supports de-at language.
List of supported languages:
https://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
Or you can find on git language_info, I saw list of supported languages there too.
If you created in languages de-at - dash is separator and folder in locale named de_AT ( makemessages de_AT) it is enough. Django defines them as different languages. Problem may be in form you are using on front-end side. In my case form that I got from django documentation crashes on sublanguages so try to change your front-end form, you can find them in another stackoverflow questions.

How to manage system languages from django admin site?

Is there some way to enable/disable or add/delete system languages from django admin interface? Since Django says:
"It reads metadata in your model to provide a powerful and production-ready interface that content producers can immediately use to start adding content to the site."
And django book tells us:
"This is a Web-based interface, limited to trusted site administrators, that enables the adding, editing and deletion of site content."
I assume that main point is the power of manage content site. Then if my language setting enables content in some language in my site, why does django not allows me to modify it? (add/delete language to site).
I would have something like this:
Do you mean to translate the Admin interface itself? If so, this might help. Do you expect to have translation files in DB, in the admin/i18n? I don't think this is not how Django works, it works with .po/.mo files.
The internationalization documentation is really good, maybe a bit too big to digest when you just start, but Django has several switches to control what you want.
A good place to understand what switch to use for your need (at least I found it very interesting) is the implementation notes paragraph in there, and how Django discovers translations which gives a HLD of the logic.
Sorry if my answer look off-topic, but as Lara, I feel like I don't completely understand your question.

Including satchmo-livesettings in main django-admin site

I plan to use the sachmo-livesettings module in my django application (not using or related to satchmo). In the satchmo store the livesettings are visible on the main django-admin site. When adding livesettings to my app, though I can access them directly using a dedicated url (e.g. ../settings) I don't manage to make them visible on the main django admin site in the menu on the right side. Do you have any ideas how to include a livesettings overview on the admin site?
There is not much documentation on how to use livesettings, do you have any links to documents about satchmo-livesettings and django-admin. I'm particularly interested on how to add things on the right side (where normally the history of changed model objects is displayed).
Thanks
I'm not too familiar with the satchmo specific bits, but generally the way you handle this kind of thing in Django is by overriding admin templates and creating your own /admin/ urls/views.

Categories

Resources