Package: djangocms-xliff
djangocms-xliffXLIFF (XML Localization Interchange File Format) is an XML-based format created
to standardize the way localizable data are passed between and among tools during a localization process.With djangocms-xliff it is possible to export all text objects from a page into an XLIFF-compatible file and re-import
the file at the end of the translation process.InstallationBefore the installation you need to make sure, that your
localization / internalization are set up properly
forDjangoandDjango-CMSSetupdjangocms-xliff is available onPyPI:$pipinstalldjangocms-xliffAdddjangocms_xliffto yourINSTALLED_APPS.INSTALLED_APPS=(...,"djangocms_xliff")Add the views fordjangocms_xliffto yoururls.pyurlpatterns=[path("xliff/",include("djangocms_xliff.urls"))]DocumentationTo make the process fail-safe there are some Django CMS related restrictions:You can only import the file to the same page and language that you exported from before.It is not possible to export a file for one language and import it to another language.It is not possible to add fields during the translation process. (Missing fields will be ignored.)This is because the reference for an entity is the unique ID of the Django CMS plugin, and each plugin has its own
unique ID for each page and language.Therefore, you need to follow these steps to work with djangocms-xliff.Step-by-stepIf the page does not exist yet in the target language, create it and copy the plugins from the page with the source
plugins.Go to the page in the target language.Export the XLIFF file at Language > Export as XLIFF…This will generate an XLIFF file in the following format:<?xml version="1.0" encoding="utf-8" standalone="no"?><xliffxmlns="urn:oasis:names:tc:xliff:document:1.2"version="1.2"><fileoriginal="verbund/meilen/projekt"datatype="plaintext"source-language="fr"target-language="en"><tooltool-id="96"tool-name="djangocms_xliff"tool-company-name="Energie 360°"/><body><trans-unitid="5872__title"resname="5872__title"maxwidth="60"size-unit="char"extype="django.db.models.fields.CharField"><source><![CDATA[The project in short]]></source><target><![CDATA[]]></target><note>CarouselTripleBlockWrapperPlugin</note><note>CarouselTripleBlock</note><note>Titel</note><note>Maxcharacters:60</note></trans-unit><trans-unitid="5874__title"resname="5874__title"maxwidth="35"size-unit="char"extype="django.db.models.fields.CharField"><source><![CDATA[Practical Solution]]></source><target><![CDATA[]]></target><note>CarouselTripleBlockSlidePlugin</note><note>Slide</note><note>Titel</note><note>Maxcharacters:35</note></trans-unit></body></file></xliff>Edit the file in the XLIFF editor of your choice.Import the XLIFF to the same page in the same language you exported from with Languages > Import from XLIFFYou will get a preview of the import that needs to be confirmed.The translations are now imported, and you can publish the page.SettingsBy default, djangocms-xliff searches for the following django model fields:CharField, SlugField, TextField, URLFieldin your
plugins.
The texts from these fields will be used for the XLIFF import and export.If you want to add additional or 3rd party app fields, you can define the following settings in yoursettings.py,
to integrate them into the XLIFF package:# A list of fields, that will be searched for while exporting.DJANGOCMS_XLIFF_FIELDS=("djangocms_text_ckeditor.fields.HTMLField",)# List of tuples with field and custom function for the exportDJANGOCMS_XLIFF_FIELD_EXTRACTORS=(("third_party.models.LinkField","your_module.xliff.link_field_extractor"),)# The signature of the extractor function must be the following:# The source parameter is the same as getattr(instance, field.name)deflink_field_extractor(instance:CMSPlugin,field:LinkField,source:Any)->List[djangocms_xliff.types.Unit]:# example:fromdjangocms_xliff.utilsimportget_type_with_pathtext=source.find_text()return[Unit(plugin_id=str(instance.pk),plugin_type=instance.plugin_type,plugin_name=instance.get_plugin_name(),field_name=field.name,field_type=get_type_with_path(field),field_verbose_name=field.verbose_name,source=text,max_length=field.max_length,)]# List of tuples with field and custom function for the importDJANGOCMS_XLIFF_FIELD_IMPORTERS=(("third_party.models.LinkField","your_module.xliff.link_field_importer"),)# The signature of the importer function must be the following:deflink_field_importer(instance:CMSPlugin,unit:djangocms_xliff.types.Unit)->CMSPlugin:# example:field=getattr(instance,unit.field_name)field.body=unit.targetreturninstance# List of custom validators for fields that need to be ignored or included in the exportDJANGOCMS_XLIFF_VALIDATORS=("your_module.xliff.is_not_background",)# The signature of the validator function must be the following:defis_not_background(field:django.db.models.Field,instance:CMSPlugin)->bool:# example:returnfield.name!="background"Placeholders Outside the CMSAdd a toolbar for your own Django model:fromcms.toolbar_poolimporttoolbar_poolfromdjangocms_xliff.cms_toolbarsimportXliffModelToolbarfrommagazine.modelsimportArticle@toolbar_pool.registerclassArticleXliffToolbar(XliffModelToolbar):passThis package does not handle translatability at database level. There are various packages for that. We recommend the
use of django-modeltranslation. Because this way import and export of XLIFF works out-of-the-box.# By default all fields on a model get exported. You can exclude fields like this:DJANGOCMS_XLIFF_MODEL_METADATA_FIELDS={'magazine.models.Article':{'exclude':["slug","og_title","og_description"]}}ContributeIssues and pull requests are welcomed.You can find a documentation on how to set up your project
inhere