Package: django-nece
IMPORTANT NOTICEThis is a fork ofhttps://github.com/tatterdemalion/django-necewhich is not maintained anymore.The package name has been changed fromnecetodjango-nece.nece?IntroductionA “Content Translation Framework” using Postgresql’s jsonb field. It
simply sets and gets translations from a jsonb field calledtranslations.Why?You might ask why you should use django-nece since there are other, and
more mature content translation frameworks likedjango-hvadanddjango-modeltranslation. Both of them are good in some ways, worst in
others.For instance, it is very hard fordjango-hvadusers to get default
language if there is no corresponding translation for an object. And it
holds translated values in a different table, so every translation query
results in another hit to the database.On the other handdjango-modeltranslationadds multiple additional
fields for multiple languages. The number of fields inceases by the
number of languages you need to support. At the end it becomes a huge
chunk of an object if you need to add more than 20 languages.nece?more or less works like the latter one with an important
difference. It uses Postgresql’s newJSONBfield to hold translation
information. And overrides the original one on query.Dependenciespostgresql >= 9.4.5
Django >= 2.2
psycopg2 >= 2.5.4Installationvia pypi:pip install django-neceUsageLets say we have a model calledFruit:from nece.models import TranslationModel

class Fruit(TranslationModel):
    name = CharField(max_length=255)

    def __str__(self):
        return self.name

    class Meta:
        translatable_fields = ('name',)TranslationModeladds a jsonb field to this table and sets
translations in a notation like the one below:{u'de_de': {u'name': u'Apfel'},
 u'tr_tr': {u'name': u'elma'}}When we need the German translation we can simply choose the language
and get the attribute as usual:>> f = Fruit.objects.get(name='apple')
>> print(f.name)
apple
>> f.language('de_de')
>> print(f.name)
ApfelYou can also filter out the ones containing any language translation:>> Fruit.objects.all()
[<Fruit: apple>, <Fruit: pear>, <Fruit: banana>]
>> Fruit.objects.language('tr_tr')
[<Fruit: elma>, <Fruit: armut>]  # there is no translation for banana
>> Fruit.objects.language_or_default('tr_tr')
[<Fruit: elma>, <Fruit: armut>, <Fruit: banana>]
>> Fruit.objects.language('tr_tr').filter(name='elma')
[<Fruit: elma>]
>> Fruit.objects.language('tr_tr').get(name='elma')
<Fruit: elma>Updating translations>> fruit._language_code
tr_tr
>> fruit.name
elma
>> fruit.translate(name='armut').save()
>> fruit.name
armut
>> fruit.language('en')
>> fruit.translate('it_it', name='pera')
>> fruit.language('it_it')
>> fruit.name
peraSettingsTRANSLATIONS_DEFAULTDefault language code. Default value:`en_us`TRANSLATIONS_MAPShortcuts for`languagecode_countrycode`notation.Example:TRANSLATIONS_MAP = {
    "en": "en_us",
    "tr": "tr_tr",
    "ar": "ar_sy",
    "bg": "bg_bg",
    "cs": "cs_cz",
    "da": "da_dk",
    ...
}Default:{'en': 'en_us'}TRANSLATIONS_FALLBACKFallback language would be used if a translation is missing.Example:TRANSLATIONS_FALLBACK = {
    'fr_ca': ['fr_fr'],
    'en_us': ['en_gb'],
}Admin panelUseTranslatableModelAdminfor pretty JSON editor (powered bydjango-admin-json-editor).Example:# settings.pyINSTALLED_APPS=[...'django_admin_json_editor',...]# admin.pyfromnece.adminimportTranslatableModelAdminclassPlaceAdmin(TranslatableModelAdmin):list_display=('...')Contributors & ThanksErkan AyAyman KhalilGönül SabahFaruk RahmetMathieu RichardozMarc HertzogAlexey KotenkoChange Log