A Django plugin that mimics Odoo's `translate=True` functionality, providing automatic language-aware field handling with a beautiful admin interface integration.
## Features
- 🌍 **Language-Aware Fields**: Automatic translation handling based on Django's current language
- 📝 **Rich Admin Interface**: Modal overlay with WYSIWYG editor for easy translation management
- 🗄️ **JSON Storage**: Efficient storage of translations in a single database column
- 🔧 **Easy Integration**: Drop-in replacement for Django's standard fields
- 🎨 **Draggable & Resizable**: Modern modal interface with drag and resize capabilities
- 🚀 **DRF Support**: Built-in Django REST Framework serializers for API development
- ✅ **Field Validation**: Proper validation for Email, URL, and Slug fields per language
- 🎯 **Type Safety**: Full support for Django's field types with translation capabilities
## Quick Start
### 1. Installation
```bash
pip install django-translatable-fields
```
Add to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = [
# ... other apps
'django_translatable_fields',
]
```
### 2. Define Your Model
```python
from django.db import models
from django_translatable_fields.fields import CharField, TextField, EmailField, URLField, SlugField
from django_translatable_fields.descriptors import TranslatableModelMixin
class Product(TranslatableModelMixin, models.Model):
name = CharField(max_length=200, translatable=True)
The plugin provides an Odoo-style admin interface:
- **Primary Field**: Shows the default language (English) input field
- **Translate Button**: Click the translate icon (🌐) next to any translatable field
- **Modal Overlay**: Opens a modal with input fields for all configured languages
- **Clean Interface**: Only the primary language is visible initially, keeping the interface clean
Just like in Odoo, the translate functionality is accessed through a button next to each translatable field, opening an overlay with all language versions.
## Configuration
Configure your languages in Django settings:
```python
LANGUAGES = [
('en', 'English'),
('de', 'German'),
('fr', 'French'),
('es', 'Spanish'),
]
```
## API Reference
### Fields
- `CharField`: Like Django's `CharField` but with `translatable=True` parameter
- `TextField`: Like Django's `TextField` but with `translatable=True` parameter
- `EmailField`: Like Django's `EmailField` but with `translatable=True` parameter
- `URLField`: Like Django's `URLField` but with `translatable=True` parameter
- `SlugField`: Like Django's `SlugField` but with `translatable=True` parameter
Both fields accept a `translatable=True` parameter (default: True).
### Model Methods
When using `TranslatableModelMixin`:
- `obj.field_name`: Returns value in current language
- `obj.field_name_en`: Returns English translation
- `obj.get_translation(field_name, language_code)`: Get specific translation
- `obj.set_translation(field_name, language_code, value)`: Set specific translation
- `obj.get_all_translations(field_name)`: Get all translations as dict
### Admin Classes
- `TranslatableModelAdmin`: Use instead of `ModelAdmin` for automatic widget handling
- `TranslatableAdminMixin`: Mixin for custom admin classes