Skip to content

Feature Request: Support Embedded Entities with Both Shared and EmptyOnTranslate Properties #6

@CreativeNative

Description

@CreativeNative

Feature Request: Support Embedded Entities with Both Shared and EmptyOnTranslate Properties

Description

Currently, the translation bundle does not fully handle embedded entities that contain a mix of properties marked with #[SharedAmongstTranslations] and #[EmptyOnTranslate].

In cases where an embeddable has some properties marked as shared and others marked to be emptied on translation, the current logic only partially applies the rules:

  • handleEmptyOnTranslate is not always invoked for embeddables that are not marked #[EmptyOnTranslate] at the top level.
  • handleSharedAmongstTranslations may override or block emptying logic, resulting in incorrect translation behavior.

This limits the flexibility for entities with mixed attribute usage and can lead to inconsistent translation results.

Proposed Changes

  • Ensure that embedded entities are always inspected recursively, regardless of top-level attributes.
  • Apply #[EmptyOnTranslate] rules to each property within an embedded object.
  • Apply #[SharedAmongstTranslations] rules only after EmptyOnTranslate logic has been evaluated.
  • Return the correct instance based on the combination of both attributes (empty first, then shared).

Benefits

  • Full support for mixed attribute usage in embedded entities.
  • Consistent and predictable translation behavior.
  • Increased flexibility for complex entity structures.

References

Suggested Implementation Plan

  1. Update EntityTranslator to detect all embedded properties, even if the top-level embeddable does not have #[SharedAmongstTranslations] or #[EmptyOnTranslate].
  2. For each property within an embedded entity:
    • Apply handleEmptyOnTranslate if the property has the #[EmptyOnTranslate] attribute.
    • Apply handleSharedAmongstTranslations if the property has the #[SharedAmongstTranslations] attribute.
  3. Combine results:
    • Prefer EmptyOnTranslate nullification first.
    • Apply SharedAmongstTranslations logic afterward.
  4. Ensure recursion works for nested embeddables, maintaining consistent behavior across all levels.
  5. Add comprehensive unit tests to cover mixed attribute scenarios.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions