-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Add translation provider events #52376
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
Conversation
just to be sure: does this need documenting? |
@wickedOne can you provide more context about your use case, and why translation pull/push events are needed? Note that 6.4/7.0 are closed for new features and you will need to target 7.1 branch as soon as it will be created. |
as stated in this comment #49231 (comment) there are several usecases which would benefit of having these events available before the write (be it either to the provider or the filesystem) action. of course there are other ways around it, but this is the least hacky one imo |
Can you report use cases here in the PR description to ease the review for everyone? Thanks |
the events were added to enable easy access for post processing of translations. one real life example for instance is a translation with references to other translations. <trans-unit id="Nip4l6f" resname="general.confirm">
<source>general.confirm</source>
<target>are you sure?</target>
</trans-unit>
<trans-unit id="OqbB6Xw" resname="general.confirm.really">
<source>general.confirm.really</source>
<target>really, {general.confim}</target>
</trans-unit> this is not supported by for instance Phrase, so with the pull event you can resolve & replace those references yourself before the translations are written to the filesystem. another example would be resolving cascading fallback locales for pull-, or adding a ticket number as note metadata for push events. |
src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Translation/Command/TranslationPushCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Translation/Tests/Command/TranslationPushCommandTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Translation/Tests/Command/TranslationPushCommandTest.php
Outdated
Show resolved
Hide resolved
thanks for the review @OskarStark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a CHANGELOG entry is added
thanks, will do that the 7.1 branch is created |
Branch 7.1 now created ;) |
- added translation pull & push event
15273cd
to
9524971
Compare
references between translations is not supported by the Symfony translator either, so I don't see why the lack of support in Phrase would be an issue. So I would still like to understand the actual use case. |
defaultLocale: $defaultLocale, | ||
transPaths: [$this->translationAppDir.'/translations'], | ||
enabledLocales: $locales, | ||
eventDispatcher: $dispatcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Symfony does not provide BC for argument names (except for attribute constructors), I would not use them in tests: this would hide BC breaks changing the parameter list by adding a new parameter in the middle.
use Symfony\Component\Translation\Provider\FilteringProvider; | ||
use Symfony\Component\Translation\Provider\TranslationProviderCollection; | ||
use Symfony\Component\Translation\Reader\TranslationReaderInterface; | ||
use Symfony\Component\Translation\TranslatorBag; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this only dispatches an event, it should depend on the PSR interface instead to be more flexible.
correct, that isn't supported by either, just like cascading locales, so dispatching these events is to provide a little bit more flexibility to the end user in regards to post-processing of translations |
As we discussed with @OskarStark during SymfonyCon Brussels hackday, the provided use case can easily be handled by using decorator pattern (decorate any TranslationProvider and pre/post process what you need in your decorator). I'm not in favor of merging this PR for now. |
Closing then. Thanks @wickedOne for proposing and @welcoMattic + @OskarStark for the review! |
two new events to allow mutation of the translator bag just before it's send to the provider or written to the filesystem.
briefly discussed over here: #49231 (comment)