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

[Feature] add replaceTranslations method #231

Merged

Conversation

javleds
Copy link
Contributor

@javleds javleds commented Oct 3, 2020

Hi!

In order to allow the users to replace all the translations for a single key in one go, we add the replaceTranslations function which forgets all the translations for the key provided and registers the new values.

public function replaceTranslations(string $key, array $translations)

Here's an example:

$translations = ['en' => 'hello', 'es' => 'hola'];

$newsItem->setTranslations('hello', $translations);
$newsItem->getTranslations(); // ['en' => 'hello', 'es' => 'hola']

$newTranslations = ['en' => 'hello'];

$newsItem->replaceTranslations('hello', $newTranslations);
$newsItem->getTranslations(); // ['en' => 'hello']

If something is missing or do you consider that we should change something, please let me know.

@javleds javleds force-pushed the feature/add-replace-translations-method branch from 1e4252e to 090e382 Compare October 3, 2020 00:54
@freekmurze freekmurze merged commit 37ab2c7 into spatie:master Oct 3, 2020
@freekmurze
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants