Skip to content

docs: Port "Implementing translation support to entities" page to 7.2#576

Open
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/docs-issue-415-translated-entities-7.2
Open

docs: Port "Implementing translation support to entities" page to 7.2#576
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/docs-issue-415-translated-entities-7.2

Conversation

@promptless-for-oss

Copy link
Copy Markdown
Contributor

Open this suggestion in Promptless to view citations and reasoning process

Ports the legacy translated-entity guide into docs/plugin_miscellaneous/translated_entities.rst (converted from Markdown to RST), replacing the placeholder note with code-level content: the TranslationEntityInterface, TranslationEntityTrait, and TranslationModelTrait helpers, plus a translated-entity Form example. References were verified against mautic/mautic 7.x and updated from the stale legacy names (e.g. TranslationInterface -> TranslationEntityInterface; TranslationMigrationTrait/addTranslationSchema omitted as removed in 6.0). Resolves docs issue #415; targets the 7.2 base branch per the team's porting decision.

Trigger Events


Tip: Add or adjust Promptless's style guide in Agent Knowledge Base ✍️

.. vale on No newline at end of file
.. vale on

Mautic provides helper interfaces and traits that add translated-content support to an entity. Use them so your entity can store a language, relate to a translation parent, and resolve the correct translation at runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ported this page from the legacy _plugin_misc_translated_entities.md source referenced by porting issue #414, converting its Markdown headings and code block into RST.

Source: https://github.com/mautic/developer-documentation/blob/main/source/includes/_plugin_misc_translated_entities.md

``Mautic\CoreBundle\Entity\TranslationEntityTrait``
This trait provides the properties and methods that define an entity's language and its relationships to its translation parent and children. In the entity's ``loadMetadata()`` method, call ``self::addTranslationMetadata($builder, self::class)`` to map the translation columns and relationships.

``Mautic\CoreBundle\Model\TranslationModelTrait``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected the legacy TranslationInterface name to TranslationEntityInterface and updated addTranslationMetadata() to the current static signature self::addTranslationMetadata($builder, self::class), verified against TranslationEntityTrait and TranslationEntityInterface in mautic/mautic 7.x.

Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/CoreBundle/Entity/TranslationEntityTrait.php

``Mautic\CoreBundle\Model\TranslationModelTrait``
Use this trait in the entity's model. It provides ``getTranslatedEntity()``, which determines the entity to use as the translation based on the Contact and/or the request's ``Accept-Language`` header, and ``postTranslationEntitySave()``, which you call at the end of the model's ``saveEntity()`` method to persist the translation relationship.

.. vale off

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the namespace of TranslationModelTrait to Mautic\CoreBundle\Model (legacy docs put it under Entity) and confirmed getTranslatedEntity() and postTranslationEntitySave() exist there in mautic/mautic 7.x.

Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/CoreBundle/Model/TranslationModelTrait.php

'label_attr' => ['class' => 'control-label'],
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.core.form.translation_parent.help',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modernized the Form example from the legacy Symfony 2 string types to the current PageType pattern: translationParent via a *ListType with IdToEntityModelTransformer and language via LocaleType, matching how PageType in mautic/mautic 7.x builds these fields.

Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/PageBundle/Form/Type/PageType.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant