{"action":"created","issue":{"url":"https://api.github.com/repos/oscarotero/Gettext/issues/152","repository_url":"https://api.github.com/repos/oscarotero/Gettext","labels_url":"https://api.github.com/repos/oscarotero/Gettext/issues/152/labels{/name}","comments_url":"https://api.github.com/repos/oscarotero/Gettext/issues/152/comments","events_url":"https://api.github.com/repos/oscarotero/Gettext/issues/152/events","html_url":"https://github.com/oscarotero/Gettext/issues/152","id":239421521,"number":152,"title":"Translations::mergeWith modifies source translations","user":{"login":"lxg","id":208363,"avatar_url":"https://avatars0.githubusercontent.com/u/208363?v=3","gravatar_id":"","url":"https://api.github.com/users/lxg","html_url":"https://github.com/lxg","followers_url":"https://api.github.com/users/lxg/followers","following_url":"https://api.github.com/users/lxg/following{/other_user}","gists_url":"https://api.github.com/users/lxg/gists{/gist_id}","starred_url":"https://api.github.com/users/lxg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lxg/subscriptions","organizations_url":"https://api.github.com/users/lxg/orgs","repos_url":"https://api.github.com/users/lxg/repos","events_url":"https://api.github.com/users/lxg/events{/privacy}","received_events_url":"https://api.github.com/users/lxg/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-06-29T09:41:47Z","updated_at":"2017-06-29T16:27:40Z","closed_at":"2017-06-29T16:27:40Z","body":"When merging two `Translations` objects using the `mergeWith` method, the source catalog is modified in some situations. This is unexpected and undesired behaviour in my opinion.\r\n\r\nThe problem is in [line 164 of Merge.php](https://github.com/oscarotero/Gettext/blob/master/src/Merge.php#L164):\r\n\r\nThe `Translation` object from the source catalog is added to the target catalog and is now referenced in the target catalog. But modifications of the target catalog will now also modify the source catalog.\r\n\r\nThis is undesired for example in situations where a source catalog is generated by an extractor and is used to be merged with several other catalogs (in my case: target catalogs for different languages).\r\n\r\nThe solution is quite simple. Instead of referencing the source translation, create a clone:\r\n\r\n```\r\ndiff --git a/src/Merge.php b/src/Merge.php\r\n--- a/src/Merge.php\r\n+++ b/src/Merge.php\r\n@@ -161,7 +161,7 @@ class Merge\r\n             if (($existing = $to->find($entry))) {\r\n                 $existing->mergeWith($entry);\r\n             } elseif ($options & self::ADD) {\r\n-                $to[] = $entry;\r\n+                $to[] = $entry->getClone();\r\n             }\r\n         }\r\n     }\r\n```"},"comment":{"url":"https://api.github.com/repos/oscarotero/Gettext/issues/comments/312020206","html_url":"https://github.com/oscarotero/Gettext/issues/152#issuecomment-312020206","issue_url":"https://api.github.com/repos/oscarotero/Gettext/issues/152","id":312020206,"user":{"login":"oscarotero","id":377873,"avatar_url":"https://avatars0.githubusercontent.com/u/377873?v=3","gravatar_id":"","url":"https://api.github.com/users/oscarotero","html_url":"https://github.com/oscarotero","followers_url":"https://api.github.com/users/oscarotero/followers","following_url":"https://api.github.com/users/oscarotero/following{/other_user}","gists_url":"https://api.github.com/users/oscarotero/gists{/gist_id}","starred_url":"https://api.github.com/users/oscarotero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscarotero/subscriptions","organizations_url":"https://api.github.com/users/oscarotero/orgs","repos_url":"https://api.github.com/users/oscarotero/repos","events_url":"https://api.github.com/users/oscarotero/events{/privacy}","received_events_url":"https://api.github.com/users/oscarotero/received_events","type":"User","site_admin":false},"created_at":"2017-06-29T16:27:40Z","updated_at":"2017-06-29T16:27:40Z","body":"Merged. thank you"}}
{"actor":{"display_login":"oscarotero"}}