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.
- π 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
pip install django-i18n-fields
# With Markdown editor support (martor)
pip install django-i18n-fields[md]# 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'))# 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']# 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!# 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'],
},
}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
π Full documentation: https://django-i18n-fields.readthedocs.io/
Quick Links:
- 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])
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
pytestMIT License - see LICENSE for details.
- π Bug Reports: GitHub Issues
- π¬ Questions: GitHub Discussions
- π Documentation: https://django-i18n-fields.readthedocs.io/