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

setTranslations behaves more like updateTranslations #225

Closed
uuf6429 opened this issue Sep 3, 2020 · 3 comments
Closed

setTranslations behaves more like updateTranslations #225

uuf6429 opened this issue Sep 3, 2020 · 3 comments

Comments

@uuf6429
Copy link

uuf6429 commented Sep 3, 2020

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
@mauriciovillam
Copy link

I have this issue too.

@javleds
Copy link
Contributor

javleds commented Oct 3, 2020

I sent the #231 with a new method that allows to replace all the translations for a single key in one go.

@freekmurze
Copy link
Member

I'll review #231 soon 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants