{"action":"created","comment":{"url":"https://api.github.com/repos/thephpleague/iso3166/pulls/comments/70833563","id":70833563,"diff_hunk":"@@ -0,0 +1,141 @@\n+<?php\n+\n+namespace League\\ISO3166;\n+\n+use DomainException;\n+use Generator;\n+use InvalidArgumentException;\n+use Traversable;\n+\n+class DataLocalizer\n+{\n+    use KeyValidators;\n+\n+    /**\n+     *  the index key to add to the entry\n+     *  @var string\n+     */\n+    private $key;\n+\n+    /**\n+     *  locale to use to display the region name\n+     *  @var string\n+     */\n+    private $locale;\n+\n+    /**\n+     * New Instance\n+     * \n+     * @param string $key    the index key to add to the entry\n+     * @param string $locale locale to use to display the region name\n+     */\n+    public function __construct($key = 'name', $locale = '')\n+    {\n+        $this->guardAgainstInvalidKey($key);\n+        $this->guardAgainstInvalidString($locale, '$locale');\n+        $this->key = $key;\n+        $this->locale = $this->filterLocale($locale);\n+    }\n+\n+    /**\n+     * Filters the key to ensure it is a valid key.\n+     *\n+     * @param string $input the index key to add to the entry\n+     *\n+     * @throws DomainException if input is not valid.\n+     */\n+    private function guardAgainstInvalidKey($input) \n+    {\n+        $this->guardAgainstInvalidString($input, '$key');\n+        $invalid_keys = [ISO3166::KEY_ALPHA3 => 1, ISO3166::KEY_ALPHA2 => 1, ISO3166::KEY_NUMERIC = 1];\n+        if (isset($invalid_keys[$input])) {\n+            throw new DomainException(sprintf(\n+                'Invalid value for $key, got \"%s\", $key can not be : %s',\n+                $input,\n+                implode(', ', array_keys($invalid_keys))\n+            ));\n+        }\n+    }\n+\n+    /**\n+     * Filters the key to ensure it is a valid key.\n+     *\n+     * @param string $input the index key to add to the entry\n+     *\n+     * @return string\n+     */\n+    private function filterLocale($locale)\n+    {\n+        $locale = trim($locale);\n+        if ('' !== $locale) {\n+            return $locale;\n+        }\n+\n+        return locale_get_default();\n+    }\n+\n+    /**\n+     * localize a collection of country entries\n+     *\n+     * @see DataLocalizer::localize\n+     *\n+     * @param iterable $iterable\n+     *\n+     * @throws InvalidArgumentException if input is not a iterable.\n+     *\n+     * @return Generator\n+     */\n+    public function __invoke($iterable)\n+    {\n+        return $this->localize($iterable);\n+    }\n+\n+    /**\n+     * localize a collection of country entries\n+     *\n+     * @param iterable $iterable\n+     *\n+     * @throws InvalidArgumentException if input is not a iterable.\n+     *\n+     * @return Generator\n+     */\n+    public function localize($iterable)","path":"src/DataLocalizer.php","position":102,"original_position":102,"commit_id":"85fc1cc3ab4e0a10cd9c357671e9ba50f50f6263","original_commit_id":"85fc1cc3ab4e0a10cd9c357671e9ba50f50f6263","user":{"login":"nyamsprod","id":51073,"avatar_url":"https://avatars.githubusercontent.com/u/51073?v=3","gravatar_id":"","url":"https://api.github.com/users/nyamsprod","html_url":"https://github.com/nyamsprod","followers_url":"https://api.github.com/users/nyamsprod/followers","following_url":"https://api.github.com/users/nyamsprod/following{/other_user}","gists_url":"https://api.github.com/users/nyamsprod/gists{/gist_id}","starred_url":"https://api.github.com/users/nyamsprod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyamsprod/subscriptions","organizations_url":"https://api.github.com/users/nyamsprod/orgs","repos_url":"https://api.github.com/users/nyamsprod/repos","events_url":"https://api.github.com/users/nyamsprod/events{/privacy}","received_events_url":"https://api.github.com/users/nyamsprod/received_events","type":"User","site_admin":false},"body":"Well the only public method is `DataLocalizer::localize` adding `DataLocalizer::__invoke` make easier to use IMHO. anyway if an interface is created the `__invoke` will not be part of the interface","created_at":"2016-07-14T16:05:25Z","updated_at":"2016-07-14T16:05:25Z","html_url":"https://github.com/thephpleague/iso3166/pull/21#discussion_r70833563","pull_request_url":"https://api.github.com/repos/thephpleague/iso3166/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/comments/70833563"},"html":{"href":"https://github.com/thephpleague/iso3166/pull/21#discussion_r70833563"},"pull_request":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/thephpleague/iso3166/pulls/21","id":77144841,"html_url":"https://github.com/thephpleague/iso3166/pull/21","diff_url":"https://github.com/thephpleague/iso3166/pull/21.diff","patch_url":"https://github.com/thephpleague/iso3166/pull/21.patch","issue_url":"https://api.github.com/repos/thephpleague/iso3166/issues/21","number":21,"state":"open","locked":false,"title":"Adding Localization","user":{"login":"nyamsprod","id":51073,"avatar_url":"https://avatars.githubusercontent.com/u/51073?v=3","gravatar_id":"","url":"https://api.github.com/users/nyamsprod","html_url":"https://github.com/nyamsprod","followers_url":"https://api.github.com/users/nyamsprod/followers","following_url":"https://api.github.com/users/nyamsprod/following{/other_user}","gists_url":"https://api.github.com/users/nyamsprod/gists{/gist_id}","starred_url":"https://api.github.com/users/nyamsprod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyamsprod/subscriptions","organizations_url":"https://api.github.com/users/nyamsprod/orgs","repos_url":"https://api.github.com/users/nyamsprod/repos","events_url":"https://api.github.com/users/nyamsprod/events{/privacy}","received_events_url":"https://api.github.com/users/nyamsprod/received_events","type":"User","site_admin":false},"body":"A DataLocalizer class is added. This class enables localizing the country full name using:\r\n- PHP intl extension.\r\n- the data from `ISO3166::KEY_ALPHA3`.\r\n\r\nThe public API is as follow:\r\n\r\n```php\r\npublic DataLocalizer::__construct($key = 'name', $locale = '')\r\npublic DataLocalizer::localize(iterable $iterable): Generator\r\npublic DataLocalizer::__invoke(iterable $iterable): Generator\r\n// __invoke is an alias of the localize method\r\n```\r\n\r\nA simple usage will be:\r\n\r\n```php\r\nuse League\\ISO3166\\ISO3166;\r\nuse League\\ISO3166\\DataLocalizer;\r\n\r\n$localizer = new DataLocalizer('local_name', 'fr');\r\n$collection = new ISO3166;\r\n$res1 = $localizer($collection);\r\n$res2 = $localizer->localize($collection->listBy(ISO3166::KEY_ALPHA2);\r\n$res3 = $localizer->__invoke([$collection->getByAlpha3('SEN')]);\r\n ```\r\n\r\nThe result is a generator you can iterate over where each entry has a new key `local_name` with the country name being localized as its value.\r\n\r\n- If the alpha3 code is unknown: the new key will return the alpha3 code\r\n- If the locale is unknown: the new key will return the localized name according to PHP `local_get_default`\r\n\r\nA possible BC break is that this feature relies on PHP intl extension which is AFAIK bundle by default since PHP5.5.\r\n\r\nThis feature may resolve #11 \r\n","created_at":"2016-07-12T15:56:47Z","updated_at":"2016-07-14T16:05:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c57d80aad1fb547549bdfeae036a2951440ce81","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/thephpleague/iso3166/pulls/21/commits","review_comments_url":"https://api.github.com/repos/thephpleague/iso3166/pulls/21/comments","review_comment_url":"https://api.github.com/repos/thephpleague/iso3166/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thephpleague/iso3166/issues/21/comments","statuses_url":"https://api.github.com/repos/thephpleague/iso3166/statuses/85fc1cc3ab4e0a10cd9c357671e9ba50f50f6263","head":{"label":"nyamsprod:feature/localization","ref":"feature/localization","sha":"85fc1cc3ab4e0a10cd9c357671e9ba50f50f6263","user":{"login":"nyamsprod","id":51073,"avatar_url":"https://avatars.githubusercontent.com/u/51073?v=3","gravatar_id":"","url":"https://api.github.com/users/nyamsprod","html_url":"https://github.com/nyamsprod","followers_url":"https://api.github.com/users/nyamsprod/followers","following_url":"https://api.github.com/users/nyamsprod/following{/other_user}","gists_url":"https://api.github.com/users/nyamsprod/gists{/gist_id}","starred_url":"https://api.github.com/users/nyamsprod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyamsprod/subscriptions","organizations_url":"https://api.github.com/users/nyamsprod/orgs","repos_url":"https://api.github.com/users/nyamsprod/repos","events_url":"https://api.github.com/users/nyamsprod/events{/privacy}","received_events_url":"https://api.github.com/users/nyamsprod/received_events","type":"User","site_admin":false},"repo":{"id":63159421,"name":"iso3166","full_name":"nyamsprod/iso3166","owner":{"login":"nyamsprod","id":51073,"avatar_url":"https://avatars.githubusercontent.com/u/51073?v=3","gravatar_id":"","url":"https://api.github.com/users/nyamsprod","html_url":"https://github.com/nyamsprod","followers_url":"https://api.github.com/users/nyamsprod/followers","following_url":"https://api.github.com/users/nyamsprod/following{/other_user}","gists_url":"https://api.github.com/users/nyamsprod/gists{/gist_id}","starred_url":"https://api.github.com/users/nyamsprod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyamsprod/subscriptions","organizations_url":"https://api.github.com/users/nyamsprod/orgs","repos_url":"https://api.github.com/users/nyamsprod/repos","events_url":"https://api.github.com/users/nyamsprod/events{/privacy}","received_events_url":"https://api.github.com/users/nyamsprod/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nyamsprod/iso3166","description":"A PHP library providing ISO 3166-1 data.","fork":true,"url":"https://api.github.com/repos/nyamsprod/iso3166","forks_url":"https://api.github.com/repos/nyamsprod/iso3166/forks","keys_url":"https://api.github.com/repos/nyamsprod/iso3166/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nyamsprod/iso3166/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nyamsprod/iso3166/teams","hooks_url":"https://api.github.com/repos/nyamsprod/iso3166/hooks","issue_events_url":"https://api.github.com/repos/nyamsprod/iso3166/issues/events{/number}","events_url":"https://api.github.com/repos/nyamsprod/iso3166/events","assignees_url":"https://api.github.com/repos/nyamsprod/iso3166/assignees{/user}","branches_url":"https://api.github.com/repos/nyamsprod/iso3166/branches{/branch}","tags_url":"https://api.github.com/repos/nyamsprod/iso3166/tags","blobs_url":"https://api.github.com/repos/nyamsprod/iso3166/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nyamsprod/iso3166/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nyamsprod/iso3166/git/refs{/sha}","trees_url":"https://api.github.com/repos/nyamsprod/iso3166/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nyamsprod/iso3166/statuses/{sha}","languages_url":"https://api.github.com/repos/nyamsprod/iso3166/languages","stargazers_url":"https://api.github.com/repos/nyamsprod/iso3166/stargazers","contributors_url":"https://api.github.com/repos/nyamsprod/iso3166/contributors","subscribers_url":"https://api.github.com/repos/nyamsprod/iso3166/subscribers","subscription_url":"https://api.github.com/repos/nyamsprod/iso3166/subscription","commits_url":"https://api.github.com/repos/nyamsprod/iso3166/commits{/sha}","git_commits_url":"https://api.github.com/repos/nyamsprod/iso3166/git/commits{/sha}","comments_url":"https://api.github.com/repos/nyamsprod/iso3166/comments{/number}","issue_comment_url":"https://api.github.com/repos/nyamsprod/iso3166/issues/comments{/number}","contents_url":"https://api.github.com/repos/nyamsprod/iso3166/contents/{+path}","compare_url":"https://api.github.com/repos/nyamsprod/iso3166/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nyamsprod/iso3166/merges","archive_url":"https://api.github.com/repos/nyamsprod/iso3166/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nyamsprod/iso3166/downloads","issues_url":"https://api.github.com/repos/nyamsprod/iso3166/issues{/number}","pulls_url":"https://api.github.com/repos/nyamsprod/iso3166/pulls{/number}","milestones_url":"https://api.github.com/repos/nyamsprod/iso3166/milestones{/number}","notifications_url":"https://api.github.com/repos/nyamsprod/iso3166/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nyamsprod/iso3166/labels{/name}","releases_url":"https://api.github.com/repos/nyamsprod/iso3166/releases{/id}","deployments_url":"https://api.github.com/repos/nyamsprod/iso3166/deployments","created_at":"2016-07-12T13:17:20Z","updated_at":"2016-07-12T13:17:21Z","pushed_at":"2016-07-12T15:24:57Z","git_url":"git://github.com/nyamsprod/iso3166.git","ssh_url":"git@github.com:nyamsprod/iso3166.git","clone_url":"https://github.com/nyamsprod/iso3166.git","svn_url":"https://github.com/nyamsprod/iso3166","homepage":"https://iso3166.thephpleague.com","size":31,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"thephpleague:master","ref":"master","sha":"c3b99d5807bdaaf6ceeb79346c2427ef82a3b302","user":{"login":"thephpleague","id":527621,"avatar_url":"https://avatars.githubusercontent.com/u/527621?v=3","gravatar_id":"","url":"https://api.github.com/users/thephpleague","html_url":"https://github.com/thephpleague","followers_url":"https://api.github.com/users/thephpleague/followers","following_url":"https://api.github.com/users/thephpleague/following{/other_user}","gists_url":"https://api.github.com/users/thephpleague/gists{/gist_id}","starred_url":"https://api.github.com/users/thephpleague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thephpleague/subscriptions","organizations_url":"https://api.github.com/users/thephpleague/orgs","repos_url":"https://api.github.com/users/thephpleague/repos","events_url":"https://api.github.com/users/thephpleague/events{/privacy}","received_events_url":"https://api.github.com/users/thephpleague/received_events","type":"Organization","site_admin":false},"repo":{"id":62299633,"name":"iso3166","full_name":"thephpleague/iso3166","owner":{"login":"thephpleague","id":527621,"avatar_url":"https://avatars.githubusercontent.com/u/527621?v=3","gravatar_id":"","url":"https://api.github.com/users/thephpleague","html_url":"https://github.com/thephpleague","followers_url":"https://api.github.com/users/thephpleague/followers","following_url":"https://api.github.com/users/thephpleague/following{/other_user}","gists_url":"https://api.github.com/users/thephpleague/gists{/gist_id}","starred_url":"https://api.github.com/users/thephpleague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thephpleague/subscriptions","organizations_url":"https://api.github.com/users/thephpleague/orgs","repos_url":"https://api.github.com/users/thephpleague/repos","events_url":"https://api.github.com/users/thephpleague/events{/privacy}","received_events_url":"https://api.github.com/users/thephpleague/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thephpleague/iso3166","description":"A PHP library providing ISO 3166-1 data.","fork":false,"url":"https://api.github.com/repos/thephpleague/iso3166","forks_url":"https://api.github.com/repos/thephpleague/iso3166/forks","keys_url":"https://api.github.com/repos/thephpleague/iso3166/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thephpleague/iso3166/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thephpleague/iso3166/teams","hooks_url":"https://api.github.com/repos/thephpleague/iso3166/hooks","issue_events_url":"https://api.github.com/repos/thephpleague/iso3166/issues/events{/number}","events_url":"https://api.github.com/repos/thephpleague/iso3166/events","assignees_url":"https://api.github.com/repos/thephpleague/iso3166/assignees{/user}","branches_url":"https://api.github.com/repos/thephpleague/iso3166/branches{/branch}","tags_url":"https://api.github.com/repos/thephpleague/iso3166/tags","blobs_url":"https://api.github.com/repos/thephpleague/iso3166/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thephpleague/iso3166/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thephpleague/iso3166/git/refs{/sha}","trees_url":"https://api.github.com/repos/thephpleague/iso3166/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thephpleague/iso3166/statuses/{sha}","languages_url":"https://api.github.com/repos/thephpleague/iso3166/languages","stargazers_url":"https://api.github.com/repos/thephpleague/iso3166/stargazers","contributors_url":"https://api.github.com/repos/thephpleague/iso3166/contributors","subscribers_url":"https://api.github.com/repos/thephpleague/iso3166/subscribers","subscription_url":"https://api.github.com/repos/thephpleague/iso3166/subscription","commits_url":"https://api.github.com/repos/thephpleague/iso3166/commits{/sha}","git_commits_url":"https://api.github.com/repos/thephpleague/iso3166/git/commits{/sha}","comments_url":"https://api.github.com/repos/thephpleague/iso3166/comments{/number}","issue_comment_url":"https://api.github.com/repos/thephpleague/iso3166/issues/comments{/number}","contents_url":"https://api.github.com/repos/thephpleague/iso3166/contents/{+path}","compare_url":"https://api.github.com/repos/thephpleague/iso3166/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thephpleague/iso3166/merges","archive_url":"https://api.github.com/repos/thephpleague/iso3166/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thephpleague/iso3166/downloads","issues_url":"https://api.github.com/repos/thephpleague/iso3166/issues{/number}","pulls_url":"https://api.github.com/repos/thephpleague/iso3166/pulls{/number}","milestones_url":"https://api.github.com/repos/thephpleague/iso3166/milestones{/number}","notifications_url":"https://api.github.com/repos/thephpleague/iso3166/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thephpleague/iso3166/labels{/name}","releases_url":"https://api.github.com/repos/thephpleague/iso3166/releases{/id}","deployments_url":"https://api.github.com/repos/thephpleague/iso3166/deployments","created_at":"2016-06-30T09:48:51Z","updated_at":"2016-07-13T15:11:33Z","pushed_at":"2016-07-14T13:22:21Z","git_url":"git://github.com/thephpleague/iso3166.git","ssh_url":"git@github.com:thephpleague/iso3166.git","clone_url":"https://github.com/thephpleague/iso3166.git","svn_url":"https://github.com/thephpleague/iso3166","homepage":"https://iso3166.thephpleague.com","size":46,"stargazers_count":60,"watchers_count":60,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":9,"forks":5,"open_issues":9,"watchers":60,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/21"},"html":{"href":"https://github.com/thephpleague/iso3166/pull/21"},"issue":{"href":"https://api.github.com/repos/thephpleague/iso3166/issues/21"},"comments":{"href":"https://api.github.com/repos/thephpleague/iso3166/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thephpleague/iso3166/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/thephpleague/iso3166/statuses/85fc1cc3ab4e0a10cd9c357671e9ba50f50f6263"}}}}
{"actor":{"display_login":"nyamsprod"}}