Skip to content

[Translatable] Add methods to remove translations by entity, by field or by locale#3030

Open
kevinkopf wants to merge 1 commit intodoctrine-extensions:mainfrom
kevinkopf:translatable-remove-methods
Open

[Translatable] Add methods to remove translations by entity, by field or by locale#3030
kevinkopf wants to merge 1 commit intodoctrine-extensions:mainfrom
kevinkopf:translatable-remove-methods

Conversation

@kevinkopf
Copy link

@kevinkopf kevinkopf commented Jan 17, 2026

I have found myself in the situation when I needed to find and remove translations. One of the specific use cases goes like this:

  1. Create a TranslationEntity
#[ORM\Table(name: 'article_translations')]
#[ORM\Index(name: 'article_translation_idx', columns: ['foreign_key', 'locale', 'object_class', 'field'])]
#[ORM\Entity(repositoryClass: TranslationRepository::class)]
class ArticleTranslation extends AbstractTranslation
{
    /**
     * All required columns are mapped through inherited superclass
     */
}
  1. Set up the TranslatinoRepository (I do it in Symfony services as per docs)
# services.yaml

  Gedmo\Translatable\Entity\Repository\TranslationRepository:
    factory: [ '@doctrine.orm.entity_manager', 'getRepository' ]
    arguments:
      - 'Gedmo\Translatable\Entity\Translation'
  1. Inject the repository and try to translate:
class SomeHandler
{
  public function __construct() {
    private TranslationRepository $translationRepository,
  }

  public function handle(...) {
    $this->translationRepository->translate($entity, "field", $locale, "Some value");
  }
}

When run multiple times, I end up with multiple translations in the database.

I believe, article_translation_idx should be UniqueConstraint instead of Index, but I decided to introduce the missing removal method before digging deeper into this.

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