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
Bug in translateBehavior #9688
Comments
What makes you think it is those specific lines? #9640 was intended to fix saving entities when records are created and only translated records are included in the entity. Previously that scenario would result in no records being saved. How is |
Hi Mark, Well, Because the $values variable stays empty, and I reckon it has to be filled with the fields that need translations.
That's also how i added the behavior to my EmailtemplatesTable.
|
I have exactly the same problem. My default locale PHP 7.0.8 Edit : I confirm that the bug has been introduced in the 3.3.7, work well with the 3.3.6. |
I get it worked again by adding 2 conditions in https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/TranslateBehavior.php#L327: $new = array_diff_key($values, $modified);
foreach ($new as $field => $content) {
// We don't need to create an Entity for the defaultLocale
if ($locale !== $this->config('defaultLocale')) {
$new[$field] = new Entity(compact('locale', 'field', 'content', 'model'), [
'useSetters' => false,
'markNew' => true
]);
}
}
$entity->set('_i18n', array_merge($bundled, array_values($modified + $new)));
$entity->set('_locale', $locale, ['setter' => false]);
$entity->dirty('_locale', false);
foreach ($fields as $field) {
// We also don't need to make the fields dirty for the defaultLocale
if ($locale !== $this->config('defaultLocale')) {
$entity->dirty($field, false);
}
} But i didn't run the tests to see if it break something, i don't have the environment ready to do it. |
Thanks for the additional information, I'll take a look and get a fix together. |
Pull request up now. |
This is a :
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 3.3.7
Platform and Target: Mysql 5.7.13, Ubuntu, Apache, PHP7, the problem is in our REST Api. Issue exists when editing an emailtemplate entity in Angular or sending the data with Postman.
Default Locale = nl_NL
Locale = nl_NL
What you did
We have called it xtranslations for reasons unknown, however we got this in our beforesave:
Which sets all the translations.
The API functions looks like this:
I tried an older version of the translateBehavior, before this pull-request was merged:
#9640
I reckon the problem is in line 282 - translateBehavior:
Since this returns empty. However there are fields in the entity that can and are translated.
However I am not very certain what the problem is. Since I also don't really get what is tried to fix in the Pull-request.
What happened
Because my default Locale is nl_NL I expect de_DE and en_US to be saved in the I18N table, and the the regular entity fields in the emailtemplates table. Since they are the default language.
However I get nl_NL, de_DE and en_US in the I18N table and the values in emailtemplates table aren't updated.
Expected Behavior
See What Happened.
Thanks for your assistance.
The text was updated successfully, but these errors were encountered: