Provides a way to translate entity fields individually.
Project description
Summary
This cube provides a way to manage and display entity field (attribute) translations, stored in the application database.
To achieve this for your particular entity type, you have to:
add an ‘i18nfield_of’ relation definition, linking from the ‘I18nField’ entity type to your translatable entity type(s)
add a ‘ref_lang’ relation definition, linking from your entity types to the ‘I18nLang’ entity type
make your business entity type inherit the ‘TranslatableEntityMixin’ and list its translatable fields in its ‘i18nfields’ attribute
create a simple adapter that inherits ‘_TranslatableEntityAdapter’ and is selectable for your translatable entity types
That’s all for the code part. Just add at least one I18nLang instance in your database and link your translatable entities to their reference language.
The default web UI will then display a new ‘translations’ action menu to users who can modify translatable entities, and display your translatable entities in the web request language by default.
Example
If you want to translate all fields of the Card entity type (from the ‘card’ cube), you will need in your schema.py file:
from yams.buildobjs import RelationDefinition class i18nfield_of(RelationDefinition): subject = 'I18nField' object = 'Card' cardinality = '1*' composite = 'object' class ref_lang(RelationDefinition): subject = 'Card' object = 'I18nLang' cardinality = '1*' inlined = True
And in the entities.py file:
from cubicweb.predicates import is_instance from cubicweb_card.entities import Card as OrigCard from cubicweb_i18nfield.entities import (TranslatableEntityMixin, _TranslatableEntityAdapter) class Card(TranslatableEntityMixin, OrigCard): i18nfields = (u'title', u'synopsis', u'content') def dc_title(self): return self.printable_value('title', format='text/plain') class MyTranslatableEntityAdapter(_TranslatableEntityAdapter): __select__ = _TranslatableEntityAdapter.__select__ & is_instance('Card')
Run tests
In a virtualenv:
` python2 -m tox `
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cubicweb-i18nfield-0.6.0.tar.gz
.
File metadata
- Download URL: cubicweb-i18nfield-0.6.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a8cf6d216ca2c26a3de07e13a8fab36157bad394e38778740dfbfa5abff534 |
|
MD5 | 3b44a942eefd8917c51c1613899e45ea |
|
BLAKE2b-256 | a1aba87f1df1efcaa543d6f961e77f9491658b5e7e0c48e69f091c059ebe2221 |
File details
Details for the file cubicweb_i18nfield-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: cubicweb_i18nfield-0.6.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f403b66192f1cf6aa864cc5cc4bd4fd139b052b98c896e1f4c1a71285fa49955 |
|
MD5 | 3b8a09c91d1234dc30bd866656716e94 |
|
BLAKE2b-256 | 4cff462021b302d7ecefd25bf99216f3fc65ffdf2ea041608b93feec392ed849 |