Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated extraction on Inherited Validation Constraints of different bundles classes. #79

Closed
leokolln opened this issue Nov 8, 2012 · 3 comments

Comments

@leokolln
Copy link

leokolln commented Nov 8, 2012

This is the scenario: I have a base class and and extending class to define an Person -> Employee using the Mapped Superclasse strategy (http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html#mapped-superclasses).

An example code:

// Acme\GeneralBundle\Entity\Person.php
/** @ORM\MappedSuperclass */
abstract class Person {
   /**
    * @ORM\Column(type="string")
    * @Assert\NotBlank(message = "person.name.empty")
    */
   protected $name;
}
// Acme\CompanyBundle\Entity\Employee.php
/** @ORM\Entity() */
class Employee extends Person {
   /**
    * @ORM\Column(type="string")
    * @Assert\NotBlank(message = "employee.sector.empty")
    */
   protected $sector;
}

The problem:
If extract the translation messages separately (by bundles) i end up with a duplicated person.name.empty, one at each bundle.
So, executing:

translation:extract en -b AcmeGeneralBundleBundle
translation:extract en -b AcmeCompanyBundleBundle

Will generate:

<!-- Acme\GeneralBundle\Resources\translations\validators.en.xliff -->
<body>
  <trans-unit id="..." resname="person.name.empty">
    <source>person.name.empty</source>
    <target state="new">person.name.empty</target>
  </trans-unit>
</body>
<!-- Acme\CompanyBundle\Resources\translations\validators.en.xliff -->
<body>
  <trans-unit id="..." resname="person.name.empty">
    <source>person.name.empty</source>
    <target state="new">person.name.empty</target>
  </trans-unit>
  <trans-unit id="..." resname="employee.sector.empty">
    <source>employee.sector.empty</source>
    <target state="new">employee.sector.empty</target>
  </trans-unit>
</body>

If i extract all the messages at one pass (not by bundle, translation:extract en --dir=./src/ --output-dir=./app/Resources/translations) it will not duplicate, but all the messages will end up in the same place, but this is a horrible mess.

It's important remember that Symfony (as of 2.1.3) resolves the hierarchy and if i delete the duplicated entry at Acme\CompanyBundle it will get the correct message from Acme\GeneralBundle.

@leokolln
Copy link
Author

As i was using translations in other parts of my project, i stumbled in another related problem, this time on Templates.

After some reading i learned that there is no "hierarchy resolution" for the translations, it is simple a matter that the translations are read on the order of the bundle declaration on the AppKernel.php, in case of duplicates, the last string translation is used.

So, i'm thinking on a solution.

  • Create a new parameter on the extract (or update) action to indicate that in case of an already present key from the same domain name (considering all other bundles) it should not be "outputed" to the current bundle, it should only add a <jms:reference-file> to the current existing declaration. The parameter could be named --prevent-override...

But for this to work i think there should be a new way of extracting the translations. Currently there is a global translation and output to a single folder, or a "per-bundle" basis. The new one must specify only a root directory (where the bundles are) then translate all of them outputting them to the respective translation folder.

The action must load the AppKernel (i believe this happens on the actual "global" way) so the order is respected.

Any thoughts?

@benjamin-hubert
Copy link
Collaborator

Hi @leokolln and thank your for your contribution.

Could you eventually give us an update about your problem with the current master branch please ?

@leokolln
Copy link
Author

Hi @GOUAILLE

Sorry for not being able to help you guys with this, it has been some years that i'm not working with Web technologies in general, so I'm not using Symfony for some years.

Anyway, nice to see activity on this very useful bundle! Best regards for the team!

@Nyholm Nyholm closed this as completed Apr 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants