Skip to main content

Django Model Translator

Project description

Django Model Translator — Documentation

django-model-translator django modellardagi bir nechta tilli fieldlarni tarjima qilish uchun vosita
django-model-translator a tool for translating multilingual fields in django models

Installation

pip install django-model-translator

Using

Sozlash / Settings

O'rnatib bo'lgandan keyin settings.py faylidagi INSTALLED_APPS listiga qo'shishingiz kerak
After installation you need to add to INSTALLED_APPS list in settings.py file

INSTALLED_APPS = [
    ...
    'django_model_translator'
]

INSTALLED_APPSga qo'shib bo'lganningizdan keyin settings.py fayliga quyidagilarni kiritishingiz kerak
After adding to INSTALLED_APPS you need to add the following to your settings.py file

DEFAULT_LANGUAGE = 'uz'
ALL_LANGUAGES = ['uz', 'en']

DEFAULT_LANGUAGE — asosiy til, agar mavjud bo'lmagan til berilsa modellar shu tilga tarjima qilinadi
DEFAULT_LANGUAGE — default language, if a non-existent language is given, the models will be translated into that language
ALL_LANGUAGES — Mavjud bo'lgan barcha tillar ro'yxati
ALL_LANGUAGES — List of all available languages

Model yozish / Model writing

models.py faylidagi modellaringizdagi tarjima qilinadigan fieldlarni quyidagicha yozishingiz kerak
You should write the translatable fields in your models in the models.py file as follows

class Book(models.Model):
    name_uz = models.CharField(max_length=50)
    name_en = models.CharField(max_length=50)
    desc_uz = models.TextField()
    desc_en = models.TextField()

Serializer yozish / Writing a serializer

from main.models import Book
from django_model_translator import TranslatableModelSerializer

class BookSerializer(TranslatableModelSerializer):
    class Meta:
        model = Book
        fields = '__all__'
        translatable_fields = ['name', 'desc']

translatable_fieldsga fieldlarning asos nomlarini yozasiz, bizning modelimizda 'name' va 'desc' degan ikkita tarjima qilinadigan ma'lumot bor.
In translatable_fields you write the base names of the fields, in our model there are two translatable data 'name' and 'desc'.

Endi bu serializerni bemalol ishlatishingiz mumkin

Now you can use this serializer with ease

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-model-translator-0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_model_translator-0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file django-model-translator-0.1.tar.gz.

File metadata

  • Download URL: django-model-translator-0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for django-model-translator-0.1.tar.gz
Algorithm Hash digest
SHA256 ceb76671ca2e5abdbf184fc704899fe8ceedd36b84d40ce846678c75db0d7a7b
MD5 b9a20f55d91ee7cef8a8774d56337f4f
BLAKE2b-256 f0303914b4723c21528230dbe9052cd5c0e1306e588ecd07e23b46d67a9f1ca8

See more details on using hashes here.

File details

Details for the file django_model_translator-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_model_translator-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd368d4d980074af9168053da39715b61a6eadeb69c7b3f1efd7de56b60a494e
MD5 b3fe1da526dd9c114ac61a0b7ddb0fbe
BLAKE2b-256 5c13f5f184f3a24cf7284e5b69f55ffe37bb7389906c6ca25366b8cd04b2aef4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page