nece?
Introduction
.. figure:: https://raw.githubusercontent.com/tatterdemalion/django-nece/master/images/nece.png :alt: nece
A “Content Translation Framework” using Postgresql’s jsonb field. It
simply sets and gets translations from a jsonb field called
translations.
Why?
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
others.
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.
Dependencies
------------
::
postgresql >= 9.4.5
Django >= 1.9
psycopg2 >= 2.5.4
Installation
------------
via pypi:
::
pip install nece
via setup.py
::
python setup.py install
Usage
-----
Lets say we have a model called ``Fruit``:
::
from nece.models import TranslationModel
class Fruit(TranslationModel):
name = CharField(max_length=255)
def __str__(self):
return self.name
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.name)
apple
>> f.language('de_de')
>> print(f.name)
Apfel
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
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
pera
Settings
TRANSLATIONS_DEFAULT
Default language code. Default value: ```en_us```
TRANSLATIONS_MAP
~~~~~~~~~~~~~~~~
Shortcuts 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_FALLBACK
Fallback language would be used if a translation is missing.
Example:
:: 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:: https://raw.githubusercontent.com/tatterdemalion/django-nece/master/images/admin.png :alt: nece
Example:
.. code-block:: python
settings.py
INSTALLED_APPS = [ ... 'django_admin_json_editor', ... ]
admin.py
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: https://github.com/kristianoellegaard/django-hvad .. _django-modeltranslation: https://github.com/deschler/django-modeltranslation .. _Erkan Ay: https://github.com/erkanay .. _Ayman Khalil: https://github.com/aymankh86 .. _Gönül Sabah: https://github.com/gonulsabah .. _Faruk Rahmet: https://github.com/farukrahmet .. _Mathieu Richardoz: https://github.com/metamatik .. _Marc Hertzog: https://github.com/kemar .. _Alexey Kotenko: https://github.com/k0t3n .. _Change Log: https://github.com/tatterdemalion/django-nece/blob/master/CHANGELOG.md .. _django-admin-json-editor: https://github.com/abogushov/django-admin-json-editor
Metadata
Release files for nece 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nece-0.8.2.tar.gz | 7.9 kB | Without provenance | Details for nece-0.8.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nece-0.8.2-py3-none-any.whl | Python 3 | none | any | Details for nece-0.8.2-py3-none-any.whl |
Total release size: 16.4 kB
Release files / nece-0.8.2.tar.gz
| Download URL | nece-0.8.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b4d3f527f48215f8176c5b8019d0e164f3b0e9760c908d8c5a44f8e69da42de
|
|
BLAKE2b-256 checksum How to use checksums |
72c1b5d1be1d3cdb0d29cc2016cca308aaed6d5b60639991e9ff03fc8f05cc16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Release files / nece-0.8.2-py3-none-any.whl
| Download URL | nece-0.8.2-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83c491830a7bf9aa8477653a076935fee1911984680e22983f75461175d79f4b
|
|
BLAKE2b-256 checksum How to use checksums |
8b17e62f606f556554a4c930204c02576bb320a8b6aaf00ec61fad79703573dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Security for nece 0.8.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.