django-modeltrans | Translate Django model fields in a PostgreSQL | Internationalization library
kandi X-RAY | django-modeltrans Summary
kandi X-RAY | django-modeltrans Summary
Translate Django model fields in a PostgreSQL JSONField
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create migrations
- Write the model to out
- Write a migration file
- Return the migrations
- Disable the admin login
- Return the fallback language
- Get the value of an instance field
- Set translation fields
- Get available language codes
- Return a set of available languages
- Return the set of available languages
- Get the language
- Delete blog and categories
- Transform the translated fields into a dictionary
- Create a new model
- Returns a dictionary of the included fields
- Build the localized field name
- Return a postgresql statement
- Preprocess the lhs
- Return help text
- Get MODELTRANS settings
- Ensure all models are translated
- Add a manager to the model
- Translates the given model
- Check the fallback chain
django-modeltrans Key Features
django-modeltrans Examples and Code Snippets
Community Discussions
Trending Discussions on django-modeltrans
QUESTION
I'm using django-modeltranslation to translate model fields. And suppose I have the following model (where the name is translated in the DB):
...ANSWER
Answered 2022-Jan-18 at 22:03IIUC, you can just use get_language()
:
QUESTION
I'm trying to translate some models in an existing project, and I'm learning how to do that using the modeltranslate extension. To experiment, I've added Spanish as an additional language to English and set English as a default in the settings.py
:
ANSWER
Answered 2021-Nov-23 at 12:35"Django Modeltranslate" creates new database fields, in your case name_en
and name_es
without removing the original name
field.
You'will need to copy the contents of the old name
field to the generated ones, and I think that the easy way is to write a custom migration. You can create a file in the migrations folder of your app, with content similar to, and run the migrations command:
QUESTION
I would like to use the modeltranslation package in a Django application that uses the flatpages app.
I installed both, followed the model translation docs, and created a translation.py
file, which I put in the main
app (where all the global stuff lies), as I can't put it directly in the flat pages app (Django code is a requirement and is not committed to VCS).
ANSWER
Answered 2021-Nov-19 at 17:01Found a solution, so I post it here if someone has the same problem. According Django documentation, you can specify the package where migration modules can be found on a per-app basis.
So, in settings.py
, add:
QUESTION
I can not figure out how to convert the name of the object on the fly
...ANSWER
Answered 2021-May-10 at 19:18You can work with setattr(…)
[Django-doc] for this:
QUESTION
I would like to add option to mobile app to change language. Im using django on backend and RN as mobile. So I installed django-modeltranslation
and added my model I want to translate. On mobile I display available languages. When user clicks on specific language I would like to get translated data. I have huge problem to create logic how to do it. I'm not asking about code just some hints and idea
EDIT:
For example: I added translation from django-modeltranslation
to my model (i.e GameTask with field title, description etc). In my settings.py
I have declared languages ('en','de','uk',etc) and added translations in database (for every field of GameTask, I added title(en), title(de) etc). When I change language in settings.py
, values on mobile are changing too (so working as intended). So im not storing any translated text in app files, just in database (except of static errors and informations). Now I just want to send info from mobile with chosen language and activate this language on backend to return content in specific language
ANSWER
Answered 2021-Mar-13 at 16:38If you want to completely make your application multi-language, you need two things.
- Translation system for your app
- Translation system for your api.
First, use a pre-built context api or create your own to support changing language in-app. Something like this: https://medium.com/@ally_20818/multi-language-text-with-react-native-react-context-b76d5677346d
When user changes the language, store the language name or key in async-storage or some other database.
Change the texts in the react-native side based on the selected language.
When you're making a api call, send the selected language too. Get the selected language on api side and return appropriate texts based on language.
UPDATE:
Since you're not storing any text on react-native side, you only need to add a picker (react-native-picker/picker is a native picker) and store the selected language key (en, de, uk etc in your case) in a database like react-native-async-storage
. When you're making api requests with react-native, include an additional header or post data which includes selected language key. And you can get and use that key in your django back-end.
QUESTION
I am developing a django multilingual app and using django-modeltranslation to translate the models. It works fine except one thing: when translation is not available in a specific language, it still shows the objects (let's say posts). I have some posts that are available in tajik while not available in russian, and vice versa.
My goal is to disable showing the posts in the language which I do not have translation. May be by showing 404 or any other way, but it should not show the posts at all, not partially
Here are my settings: settings.py
...ANSWER
Answered 2020-Sep-04 at 07:43So basically, I have put an if statement, which checks if a field is empty. If so, that it excludes the object.
QUESTION
I've translated my Model fields with django-modeltranslation and implemented search using django-elasticsearch-dsl.
Problem: django-modeltranslation creates translation fields in DB, and not in my Models, and search is working only for fields created by Model. As django-elasticsearch-dsl is checking Models to rebuild search index.
When I try:
python3 manage.py search_index --rebuild
I get the error:
...ANSWER
Answered 2020-Apr-09 at 15:51You can add the fields in the Document
class explicitly. Like following
QUESTION
When I'm trying to remove a row, the formset send me the following error [{}, {}, {}, {'id': ['This field is required']}]
.
If I change the following parameter can_delete=True
inside the modelformset_factory, I can delete object but rows stays display even after I pressed the remove button.
I tried to add {% if form.instance.pk %}{{ form.DELETE }}{% endif %}
in the template, it didn't change anything.
I am using django 2.2 and django-dynamic-formset, the country_fr/en come from modeltranslation.
Views
...ANSWER
Answered 2020-Jan-16 at 22:07So the problem come from bootstrap, the d-flex
of each form of the formset contain the attribut !important
wich override the display: none;
of the django-dynamic-formset-script.
I made my own css class to replace d-flex
. I kept can_delete=True
, it's obviously useful; and I removed {% if form.instance.pk %}{{ form.DELETE }}{% endif %}
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-modeltrans
You can use django-modeltrans like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page