Skip to main content

Structured internationalization fields for Django models.

Project description

PyPI Code Coverage Test Checked with mypy Checked with pyright

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() and LocalizedRef)

  • 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

Project details


Download files

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

Source Distribution

django_i18n_fields-1.2.0.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

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

django_i18n_fields-1.2.0-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file django_i18n_fields-1.2.0.tar.gz.

File metadata

  • Download URL: django_i18n_fields-1.2.0.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_i18n_fields-1.2.0.tar.gz
Algorithm Hash digest
SHA256 78cf473aaf8cc66df669c2b1310a6d4a7fd2e0ee87da2e4363f04f5703627604
MD5 74c85251f4acf032f10400795e5da2f7
BLAKE2b-256 cfa636b8abdaf3d363b7b6ade026cf9e6aff463695d75ff37d56e49ec684d2d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_i18n_fields-1.2.0.tar.gz:

Publisher: publish.yml on huynguyengl99/django-i18n-fields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_i18n_fields-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_i18n_fields-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca6afd444bd14d32dc949c91afd5f6445c9a48930686a3a2fda8ad31ddb7e2a7
MD5 cf1fd0b128add55166dc12bd0f0a64e8
BLAKE2b-256 4367e061db2eff691428ef653977749195f09b14f69615fc6c0a018ce316042e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_i18n_fields-1.2.0-py3-none-any.whl:

Publisher: publish.yml on huynguyengl99/django-i18n-fields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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