GitHub PullRequestReviewCommentEvent at 2014-08-23 20:53:32
Repository: symfony-docs
Actor: xabbuh
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/16632678","id":16632678,"diff_hunk":"@@ -0,0 +1,116 @@\n+.. index::\n+    single: Translation; Custom formats\n+\n+Custom Formats\n+==============\n+\n+Sometimes, you need to deal with custom formats for translation files. The\n+Translation component is flexible enough to support this, just creating a\n+loader (to load translations) and, optionally, a dumper (to dump translations).\n+\n+Let's imagine you have a custom format where translation messages are defined\n+using one line for each translation and parenthesis to wrap the key and the\n+message. A translation file would look like this:\n+\n+.. code-block:: text\n+\n+    (welcome)(Bienvenido)\n+    (goodbye)(Adios)\n+    (hello)(Hola)\n+\n+Custom Loader\n+-------------\n+\n+To define a custom loader able to read this kind of files, you must create a\n+new class that implements the\n+:class:`Symfony\\\\Component\\\\Translation\\\\Loader\\\\LoaderInterface`. The\n+:method:`Symfony\\\\Component\\\\Translation\\\\Loader\\\\LoaderInterface::load`\n+method will get a filename and parse it into an array. Then, it will\n+create the catalogue that will be returned::\n+\n+    use Symfony\\Component\\Translation\\MessageCatalogue;\n+    use Symfony\\Component\\Translation\\Loader\\LoaderInterface;\n+\n+    class MyFormatLoader implements LoaderInterface\n+    {\n+        public function load($resource, $locale, $domain = 'messages')\n+        {\n+            $messages = array();\n+            $lines = file($resource);\n+\n+            foreach ($lines as $line) {\n+                if (preg_match('/\\(([^\\)]+)\\)\\(([^\\)]+)\\)/', $line, $matches)) {\n+                    $messages[$matches[1]] = $matches[2];\n+                }\n+            }\n+\n+            $catalogue = new MessageCatalogue($locale);\n+            $catalogue->add($messages, $domain);\n+\n+            return $catalogue;\n+        }\n+\n+    }\n+\n+Once created, it can be used as any other loader::\n+\n+    $translator = new Translator('es_ES');\n+    $translator->addLoader('my_format', new MyFormatLoader());\n+\n+    $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'es_ES');\n+\n+    echo $translator->trans('welcome');\n+\n+It will print *\"Bienvenido\"*.\n+\n+Custom Dumper\n+-------------\n+\n+It is also possible to create a custom dumper for your format, useful when using","path":"components/translation/custom_formats.rst","position":69,"original_position":69,"commit_id":"bfd78b33d71a7de45e69368e75662ac94c6b4876","original_commit_id":"bfd78b33d71a7de45e69368e75662ac94c6b4876","user":{"login":"xabbuh","id":1957048,"avatar_url":"https://avatars.githubusercontent.com/u/1957048?v=2","gravatar_id":"b5fe043ff5cd47b3b35d95e78fce5539","url":"https://api.github.com/users/xabbuh","html_url":"https://github.com/xabbuh","followers_url":"https://api.github.com/users/xabbuh/followers","following_url":"https://api.github.com/users/xabbuh/following{/other_user}","gists_url":"https://api.github.com/users/xabbuh/gists{/gist_id}","starred_url":"https://api.github.com/users/xabbuh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xabbuh/subscriptions","organizations_url":"https://api.github.com/users/xabbuh/orgs","repos_url":"https://api.github.com/users/xabbuh/repos","events_url":"https://api.github.com/users/xabbuh/events{/privacy}","received_events_url":"https://api.github.com/users/xabbuh/received_events","type":"User","site_admin":false},"body":"[...] for your format which is useful [...]","created_at":"2014-08-23T20:53:32Z","updated_at":"2014-08-23T20:53:32Z","html_url":"https://github.com/symfony/symfony-docs/pull/4166#discussion_r16632678","pull_request_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/16632678"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4166#discussion_r16632678"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166","id":20191809,"html_url":"https://github.com/symfony/symfony-docs/pull/4166","diff_url":"https://github.com/symfony/symfony-docs/pull/4166.diff","patch_url":"https://github.com/symfony/symfony-docs/pull/4166.patch","issue_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4166","number":4166,"state":"open","locked":false,"title":"Translation custom loaders","user":{"login":"raulfraile","id":595160,"avatar_url":"https://avatars.githubusercontent.com/u/595160?v=2","gravatar_id":"357ad9b763b4a37ce15946d41e2a4e4a","url":"https://api.github.com/users/raulfraile","html_url":"https://github.com/raulfraile","followers_url":"https://api.github.com/users/raulfraile/followers","following_url":"https://api.github.com/users/raulfraile/following{/other_user}","gists_url":"https://api.github.com/users/raulfraile/gists{/gist_id}","starred_url":"https://api.github.com/users/raulfraile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raulfraile/subscriptions","organizations_url":"https://api.github.com/users/raulfraile/orgs","repos_url":"https://api.github.com/users/raulfraile/repos","events_url":"https://api.github.com/users/raulfraile/events{/privacy}","received_events_url":"https://api.github.com/users/raulfraile/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Doc fix?      | no\r\n| New docs?     | yes\r\n| Applies to    | all\r\n| Fixed tickets | #4156\r\n\r\nThis PR adds a documentation section for creating custom loaders and dumpers to support other formats. ","created_at":"2014-08-22T19:24:48Z","updated_at":"2014-08-23T20:53:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bac449fb49369b3958eca90b87aea4c7d2296f97","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4166/comments","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/bfd78b33d71a7de45e69368e75662ac94c6b4876","head":{"label":"raulfraile:translation_custom_loaders","ref":"translation_custom_loaders","sha":"bfd78b33d71a7de45e69368e75662ac94c6b4876","user":{"login":"raulfraile","id":595160,"avatar_url":"https://avatars.githubusercontent.com/u/595160?v=2","gravatar_id":"357ad9b763b4a37ce15946d41e2a4e4a","url":"https://api.github.com/users/raulfraile","html_url":"https://github.com/raulfraile","followers_url":"https://api.github.com/users/raulfraile/followers","following_url":"https://api.github.com/users/raulfraile/following{/other_user}","gists_url":"https://api.github.com/users/raulfraile/gists{/gist_id}","starred_url":"https://api.github.com/users/raulfraile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raulfraile/subscriptions","organizations_url":"https://api.github.com/users/raulfraile/orgs","repos_url":"https://api.github.com/users/raulfraile/repos","events_url":"https://api.github.com/users/raulfraile/events{/privacy}","received_events_url":"https://api.github.com/users/raulfraile/received_events","type":"User","site_admin":false},"repo":{"id":23235234,"name":"symfony-docs","full_name":"raulfraile/symfony-docs","owner":{"login":"raulfraile","id":595160,"avatar_url":"https://avatars.githubusercontent.com/u/595160?v=2","gravatar_id":"357ad9b763b4a37ce15946d41e2a4e4a","url":"https://api.github.com/users/raulfraile","html_url":"https://github.com/raulfraile","followers_url":"https://api.github.com/users/raulfraile/followers","following_url":"https://api.github.com/users/raulfraile/following{/other_user}","gists_url":"https://api.github.com/users/raulfraile/gists{/gist_id}","starred_url":"https://api.github.com/users/raulfraile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raulfraile/subscriptions","organizations_url":"https://api.github.com/users/raulfraile/orgs","repos_url":"https://api.github.com/users/raulfraile/repos","events_url":"https://api.github.com/users/raulfraile/events{/privacy}","received_events_url":"https://api.github.com/users/raulfraile/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/raulfraile/symfony-docs","description":"The Symfony2 documentation","fork":true,"url":"https://api.github.com/repos/raulfraile/symfony-docs","forks_url":"https://api.github.com/repos/raulfraile/symfony-docs/forks","keys_url":"https://api.github.com/repos/raulfraile/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raulfraile/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raulfraile/symfony-docs/teams","hooks_url":"https://api.github.com/repos/raulfraile/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/raulfraile/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/raulfraile/symfony-docs/events","assignees_url":"https://api.github.com/repos/raulfraile/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/raulfraile/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/raulfraile/symfony-docs/tags","blobs_url":"https://api.github.com/repos/raulfraile/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raulfraile/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raulfraile/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/raulfraile/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raulfraile/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/raulfraile/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/raulfraile/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/raulfraile/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/raulfraile/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/raulfraile/symfony-docs/subscription","commits_url":"https://api.github.com/repos/raulfraile/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/raulfraile/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/raulfraile/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/raulfraile/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/raulfraile/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/raulfraile/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raulfraile/symfony-docs/merges","archive_url":"https://api.github.com/repos/raulfraile/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raulfraile/symfony-docs/downloads","issues_url":"https://api.github.com/repos/raulfraile/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/raulfraile/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/raulfraile/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/raulfraile/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raulfraile/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/raulfraile/symfony-docs/releases{/id}","created_at":"2014-08-22T18:22:42Z","updated_at":"2014-08-22T05:44:07Z","pushed_at":"2014-08-23T20:15:45Z","git_url":"git://github.com/raulfraile/symfony-docs.git","ssh_url":"git@github.com:raulfraile/symfony-docs.git","clone_url":"https://github.com/raulfraile/symfony-docs.git","svn_url":"https://github.com/raulfraile/symfony-docs","homepage":"http://symfony.com/doc/current/","size":21468,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":false,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.3","ref":"2.3","sha":"7a6e3d19115a027bcd717916548accb9702b2fe9","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=2","gravatar_id":"bc6312a5b583c4258c9fad11122c6e31","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":521583,"name":"symfony-docs","full_name":"symfony/symfony-docs","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=2","gravatar_id":"bc6312a5b583c4258c9fad11122c6e31","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony-docs","description":"The Symfony2 documentation","fork":false,"url":"https://api.github.com/repos/symfony/symfony-docs","forks_url":"https://api.github.com/repos/symfony/symfony-docs/forks","keys_url":"https://api.github.com/repos/symfony/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony-docs/teams","hooks_url":"https://api.github.com/repos/symfony/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony-docs/events","assignees_url":"https://api.github.com/repos/symfony/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony-docs/tags","blobs_url":"https://api.github.com/repos/symfony/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony-docs/subscription","commits_url":"https://api.github.com/repos/symfony/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony-docs/merges","archive_url":"https://api.github.com/repos/symfony/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony-docs/downloads","issues_url":"https://api.github.com/repos/symfony/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony-docs/releases{/id}","created_at":"2010-02-17T08:43:51Z","updated_at":"2014-08-22T05:44:07Z","pushed_at":"2014-08-22T19:07:12Z","git_url":"git://github.com/symfony/symfony-docs.git","ssh_url":"git@github.com:symfony/symfony-docs.git","clone_url":"https://github.com/symfony/symfony-docs.git","svn_url":"https://github.com/symfony/symfony-docs","homepage":"http://symfony.com/doc/current/","size":51113,"stargazers_count":915,"watchers_count":915,"language":"Assembly","has_issues":true,"has_downloads":false,"has_wiki":false,"forks_count":1432,"mirror_url":null,"open_issues_count":201,"forks":1432,"open_issues":201,"watchers":915,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4166"},"issue":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4166"},"comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4166/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4166/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony-docs/statuses/bfd78b33d71a7de45e69368e75662ac94c6b4876"}}}}