Skip to main content

A content translation framework using Postgresql's jsonb field in the background

Project description



.. figure:: :alt: nece

A “Content Translation Framework” using Postgresql’s jsonb field. It simply sets and gets translations from a jsonb field called translations.


You might ask why you should use django-nece since there are other, and
more mature content translation frameworks like `django-hvad`_ and
`django-modeltranslation`_. Both of them are good in some ways, worst in

For instance, it is very hard for ``django-hvad`` users 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 hand ``django-modeltranslation`` adds 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 new ``JSONB`` field to hold translation
information. And overrides the original one on query.



    postgresql >= 9.4.5
    Django >= 1.9
    psycopg2 >= 2.5.4


via pypi:


pip install nece



    python install


Lets say we have a model called ``Fruit``:


    from nece.models import TranslationModel

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

        def __str__(self):

        class Meta:
            translatable_fields = ('name',)

``TranslationModel`` adds 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.language('de_de')
    >> print(

You 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
>> fruit.translate(name='armut').save()
>> fruit.language('en')
>> fruit.translate('it_it', name='pera')
>> fruit.language('it_it')



Default language code. Default value: ```en_us```


Shortcuts for ```languagecode_countrycode``` notation. 



        "en": "en_us",
        "tr": "tr_tr",
        "ar": "ar_sy",
        "bg": "bg_bg",
        "cs": "cs_cz",
        "da": "da_dk",



    {'en': 'en_us'}


Fallback language would be used if a translation is missing.


:: TRANSLATIONS_FALLBACK = { 'fr_ca': ['fr_fr'], 'en_us': ['en_gb'], }

Admin panel

Use TranslatableModelAdmin for pretty JSON editor (powered by django-admin-json-editor_).

.. figure:: :alt: nece


.. code-block:: python

INSTALLED_APPS = [ ... 'django_admin_json_editor', ... ]

from nece.admin import TranslatableModelAdmin

class PlaceAdmin(TranslatableModelAdmin): list_display = ('...')

Contributors & Thanks

  • Erkan Ay_
  • Ayman Khalil_
  • Gönül Sabah_
  • Faruk Rahmet_
  • Mathieu Richardoz_
  • Marc Hertzog_
  • Alexey Kotenko_

Change Log_

.. _django-hvad: .. _django-modeltranslation: .. _Erkan Ay: .. _Ayman Khalil: .. _Gönül Sabah: .. _Faruk Rahmet: .. _Mathieu Richardoz: .. _Marc Hertzog: .. _Alexey Kotenko: .. _Change Log: .. _django-admin-json-editor:

Project details

Download files

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

Files for nece, version 0.8.2
Filename, size File type Python version Upload date Hashes
Filename, size nece-0.8.2-py3-none-any.whl (8.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size nece-0.8.2.tar.gz (7.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page