-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] [Loco] Fix idempotency of LocoProvider write method #44187
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
2c49719
to
a0b0692
Compare
a0b0692
to
66a3c03
Compare
Ready for review /cc @nicolas-grekas @OskarStark |
|
||
$ids = array_intersect_key($keysIdsMap, $messages); | ||
|
||
$this->translateAssets(array_combine(array_values($ids), array_values($messages)), $locale); |
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.
what if some keys don't have an asset id ? This would fail in array_combine
AFAICT due to the different number of items.
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.
The case could not happen, Loco generate an asset for every asset.
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 we just create assets for new keys, they mandatory have an asset id
Thank you @welcoMattic. |
This PR fix the exception thrown when we push translations twice, with existing translations on Loco.
Explanation of the fix:
To translate an "asset" (a translation key in Loco vocabulary), we need its Loco
id
. But Loco does not allow us to retrieve an id from a key. So, we fetch all ids for the current domain. Then, we build a map withkey
as key, andid
as value. After that, we can intersect the keys of this map and our messages array to get all Loco ids of the currently processed messages.Todo: