Welcome to Django i18n Fields documentation!ο
DJANGO i18n FIELDSο
A modern Django package providing structured internationalization (i18n) for model fields. Store and manage multilingual content directly in your Django models using a clean, database-agnostic approach.
Improved alternative to django-localized-fields - Works with all databases, not just PostgreSQL.
Key Featuresο
- π Comprehensive Field Types
CharField, TextField, IntegerField, FloatField, BooleanField, FileField, UniqueSlugField, and MartorField (Markdown) with multilingual support
- π― Database Agnostic
Works with PostgreSQL, MySQL, SQLite - any database that supports JSONField
- π Rich Admin Integration
Beautiful tab and dropdown interfaces for managing translations in Django admin, with Markdown editor support via martor
- π Powerful Querying
Filter, order, and annotate queries with language-specific values using
L()expressions- π Django REST Framework Support
Automatic serialization with
LocalizedModelSerializer- returns simple values in the active language- π οΈ Full Type Safety
Complete type hints with mypy and pyright compatibility
Quick Startο
Installationο
pip install django-i18n-fields
# With Markdown editor support (martor)
pip install django-i18n-fields[md]
Basic Usageο
# models.py
from django.db import models
from i18n_fields import LocalizedCharField, LocalizedTextField
class Article(models.Model):
title = LocalizedCharField(max_length=200, required=['en'])
content = LocalizedTextField(blank=True)
# Create with translations
article = Article.objects.create(
title={'en': 'Hello World', 'es': 'Hola Mundo'},
content={'en': 'Content in English', 'es': 'Contenido en espaΓ±ol'}
)
# Access in current language
print(article.title) # Automatically uses active language
# Query by specific language
Article.objects.filter(title__en='Hello World')
# Order by translated field
from i18n_fields import L
Article.objects.order_by(L('title'))
Django Adminο
# admin.py - Option 1: Using the base class (recommended)
from i18n_fields import LocalizedFieldsAdmin
@admin.register(Article)
class ArticleAdmin(LocalizedFieldsAdmin):
list_display = ['title', 'created_at']
# Automatic tab/dropdown widgets for all localized fields!
# admin.py - Option 2: Using the mixin with your own base class
from django.contrib import admin
from i18n_fields import LocalizedFieldsAdminMixin
@admin.register(Article)
class ArticleAdmin(LocalizedFieldsAdminMixin, admin.ModelAdmin):
list_display = ['title', 'created_at']
Django REST Frameworkο
# serializers.py
from i18n_fields.drf import LocalizedModelSerializer
class ArticleSerializer(LocalizedModelSerializer):
class Meta:
model = Article
fields = ['id', 'title', 'content']
# Returns: {"id": 1, "title": "Hello World", "content": "..."}
# Automatically uses active language!
Configurationο
# settings.py
INSTALLED_APPS = [
# ...
'i18n_fields',
]
LANGUAGES = [
('en', 'English'),
('es', 'Spanish'),
('fr', 'French'),
]
I18N_FIELDS = {
'DISPLAY': 'tab', # or 'dropdown' for admin
'FALLBACKS': {
'en-us': ['en'],
'es-mx': ['es'],
},
}
Why Django i18n Fields?ο
vs django-localized-fields
β Works with all databases (not just PostgreSQL)
β Actively maintained with regular updates
β Better type hints and IDE support
β Built-in DRF support with automatic serialization
β Enhanced admin UI with tab/dropdown modes
β Query expressions (
L()andLocalizedRef)β Comprehensive documentation
Documentationο
π Full documentation: https://django-i18n-fields.readthedocs.io/
Quick Links:
Requirementsο
Python 3.10+
Django 5.0+
Django REST Framework 3.0+ (optional, for DRF integration)
martor (optional, for Markdown editor support β install with
pip install django-i18n-fields[md])
Contributingο
We welcome contributions! Please see our Contributing Guide for detailed instructions.
Development Setup:
git clone https://github.com/huynguyengl99/django-i18n-fields.git
cd django-i18n-fields
uv venv
source .venv/bin/activate
uv sync --all-extras
pytest
Licenseο
MIT License - see LICENSE for details.
Supportο
π Bug Reports: GitHub Issues
π¬ Questions: GitHub Discussions
π Documentation: https://django-i18n-fields.readthedocs.io/
Contentsο
Getting Started
API Reference
Development