Skip to main content

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

cubicweb_i18nfield-1.0.1.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cubicweb_i18nfield-1.0.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file cubicweb_i18nfield-1.0.1.tar.gz.

File metadata

  • Download URL: cubicweb_i18nfield-1.0.1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for cubicweb_i18nfield-1.0.1.tar.gz
Algorithm Hash digest
SHA256 377e9614076db58062de9fe7e21f7d53c09a00f3edf491a478987d102ae2e29a
MD5 5e5cde3b3951be1196e6b8ad6080aa74
BLAKE2b-256 521ebc0aacc1c14da793b794b56f2fca467e597439fd9e4bb11aa233cbf30bee

See more details on using hashes here.

File details

Details for the file cubicweb_i18nfield-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cubicweb_i18nfield-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2830bb81918cfb9db1e2e5e510f31b7f32e18dc7a8520668cebc1c6509593f9d
MD5 2b1e03bd7062f44fa67c0db18a1a1c61
BLAKE2b-256 a58bc03feae82de7c35a8d4f7609bcbcfa8213b6a3b83defd8d37b85de6381c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page