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

Merge::mergeTranslations() does not properly pass on $options #147

Closed
melbings opened this issue May 16, 2017 · 3 comments
Closed

Merge::mergeTranslations() does not properly pass on $options #147

melbings opened this issue May 16, 2017 · 3 comments

Comments

@melbings
Copy link
Contributor

There seems to be a bug in Merge::mergeTranslations:

public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS)
    {
        if ($options & self::REMOVE) {
            $filtered = [];

            foreach ($to as $entry) {
                if ($from->find($entry)) {
                    $filtered[$entry->getId()] = $entry;
                }
            }

            $to->exchangeArray($filtered);
        }

        foreach ($from as $entry) {
            if (($existing = $to->find($entry))) {
                $existing->mergeWith($entry); // <--- does not pass on $options
            } elseif ($options & self::ADD) {
                $to[] = $entry;
            }
        }
    }

$options is not passed on to the single translation mergeWith() operations:

$existing->mergeWith($entry);

Therefore, overwriting translations does not work properly:

// Does not actually overwrite translations
$translations->mergeWith($otherTranslations, Merge::ADD | MERGE::HEADERS_ADD | MERGE::HEADERS_OVERRIDE | Merge::TRANSLATION_OVERRIDE);

An easy fix would be to pass on $options in Merge.php:162:

$existing->mergeWith($entry, $options);
@oscarotero
Copy link
Member

Ok, good catch. Do you mind to create a pull request to fix this? Thank you!

@melbings
Copy link
Contributor Author

Here you go: Pull request #150

Please note that the PHPUnit tests seem to be broken (and have been before my pull request).

@oscarotero
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

No branches or pull requests

2 participants