webfactory / WebfactoryPolyglotBundle

Symfony bundle simplifying translations in Doctrine.
MIT License
3 stars 3 forks source link

How to set the primary locale in a multi-lingual table #72

Closed tacman closed 6 months ago

tacman commented 6 months ago

Thanks for updating the example, I have a question before I update the README.

How do I set the primary locale in a table that has multiple languages?

#[Polyglot\Locale(primary: "en_GB")]
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
class Document

but suppose each document has it's own locale field? My fixtures now look like

        $document = (new Document())
            ->setPrimaryLocale('en')
            ->setText('hello, world');
        $document->getText()->setTranslation('hola, mundo', 'es');
        $manager->persist($document);

        $document = (new Document())
            ->setPrimaryLocale('es')
            ->setText('adios');
        $document->getText()->setTranslation('good-bye', 'en');
        $manager->persist($document);

How do I map the primary locale? When I use it the attribute on the property, I get


  Class App\Entity\Document uses translations, so it needs to provide the primary locale with the Webfactory\Bundle\PolyglotBundle\Attribute\Locale attribute at the class l  
  evel. This can either be at the class itself, or in one of its parent classes.                                                                                              

That is, I don't want to set the primary locale on the entire table, but rather on a specific field.

sebastiankugler commented 6 months ago

I think that's not possible yet (see #50)

tacman commented 6 months ago

Closed in favor of #50