https://github.com/xi/django-parlor
Django model translations with even less nasty hacks.
https://github.com/xi/django-parlor
django translation
Last synced: 9 months ago
JSON representation
Django model translations with even less nasty hacks.
- Host: GitHub
- URL: https://github.com/xi/django-parlor
- Owner: xi
- License: mit
- Created: 2025-08-06T13:46:41.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-08-06T14:08:03.000Z (12 months ago)
- Last Synced: 2025-08-06T14:25:24.125Z (12 months ago)
- Topics: django, translation
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-parlor
Django model translations with even less nasty hacks.
## Installation
```
pip install django-parlor
```
## Usage
```python
from django.contrib import admin
from django.db import models
from parlor.admin import TranslatableAdmin
from parlor.models import TranslatableModel
class MyModel(TranslatableModel):
...
class MyModelTranslation(models.Model):
parent = MyModel.get_parent_field()
language_code = MyModel.get_language_field()
label = models.CharField(max_length=32)
...
class Meta:
unique_together = [('parent', 'language_code')]
admin.site.register(MyModel, TranslatableAdmin)
animal = MyModel.objects.create()
animal.translations.create(language_code='en', label='Frog')
animal.translations.create(language_code='de', label='Frosch')
print(animal.label)
```
## Status
Right now this is more of a proof-of-concept. If people are interested in this
library it could certainly be expanded.
## Relation to django-parler
### Standing on the Shoulders of Giants
There are two popular libraries for model translation in Django:
[django-modeltranslation](https://github.com/deschler/django-modeltranslation)
and [django-parler](https://github.com/django-parler/django-parler). The former
adds additional columns to the same table while the latter adds a new table for
each translatable model. Both of these libraries use a lot of magic which makes
them easy to use, but also leads to some hard-to-debug edge cases.
There is also
[django-translated-fields](https://github.com/matthiask/django-translated-fields),
which uses the same basic approach as django-modeltranslation, but with much
less magic (and much less lines of code).
Here I try to do something similar for django-parler, which has been
unmaintained for some time now.
### Migration
If you want to migrate from django-parler to django-parlor, you need to replace
all instances of `parler.TranslatedFields` by explicit translation models as
described above. Note that the `parent` field is called `master` in
django-parler.
To keep using the same data, you will also need to set `Meta.db_table` to the
name generated by django-parler (typically `myapp_mymodel_translation`).
Finally you should run `manage.py makemigrations`. The generated migrations
will only contain minor changes though.
### Conceptual differences
- With django-parlor, the translation model must be created explicitly.
- In the admin UI, django-parlor uses a stock inline instead of a custom
tabbed interface.
- django-parlor only provides basic attribute access while django-parler
provides a lot more features.