Skip to main content

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 `

Metadata

Release files for cubicweb-i18nfield 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cubicweb-i18nfield 1.0.1
File Size Uploaded Provenance Actions
cubicweb_i18nfield-1.0.1.tar.gz 18.3 kB Without provenance Details for cubicweb_i18nfield-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cubicweb-i18nfield 1.0.1
File Interpreter ABI Platform Actions
cubicweb_i18nfield-1.0.1-py3-none-any.whl Python 3 none any Details for cubicweb_i18nfield-1.0.1-py3-none-any.whl

Total release size: 37.8 kB

Release files / cubicweb_i18nfield-1.0.1.tar.gz

Download URL cubicweb_i18nfield-1.0.1.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
377e9614076db58062de9fe7e21f7d53c09a00f3edf491a478987d102ae2e29a
BLAKE2b-256 checksum
How to use checksums
521ebc0aacc1c14da793b794b56f2fca467e597439fd9e4bb11aa233cbf30bee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / cubicweb_i18nfield-1.0.1-py3-none-any.whl

Download URL cubicweb_i18nfield-1.0.1-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2830bb81918cfb9db1e2e5e510f31b7f32e18dc7a8520668cebc1c6509593f9d
BLAKE2b-256 checksum
How to use checksums
a58bc03feae82de7c35a8d4f7609bcbcfa8213b6a3b83defd8d37b85de6381c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Security for cubicweb-i18nfield 1.0.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page