setTranslations behaves more like updateTranslations
uuf6429 opened this issue · comments
What I mean by the title is that I expected setTranslations(string $key, array $translations)
to set all the translations for $key
, however if one looks at the code, it actually only overwrites existing translations.
For example:
$entity->setTranslations('title', ['en'=>'Tiitle', 'de' => 'Title']); // all good
$entity->setTranslations('title', ['en'=>'Title']); // wait for it..
var_export($entity->getTranslations());
// => array( 'en' => 'Title', 'de' => 'Titel' ) <-- didn't expect 'de' to still be there
Looking at the code of forgetTranslation
, I think it only really works because it ends up unsetting $this->$key
($entity->title
). At the moment, I ended up using the same mechanism as well and it seems to work fine:
$entity->setTranslations('title', ['en'=>'Tiitle', 'de' => 'Title']); // all good
unset($entity->title);
$entity->setTranslations('title', ['en'=>'Title']);
var_export($entity->getTranslations());
// => array( 'en' => 'Title' ) <-- all good
I have this issue too.
I sent the #231 with a new method that allows to replace all the translations for a single key in one go.
I'll review #231 soon 👍