{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/pontoon/pulls/comments/49990069","id":49990069,"diff_hunk":"@@ -0,0 +1,178 @@\n+from __future__ import absolute_import\n+\n+import codecs\n+import logging\n+\n+from l20n.format.parser import L20nParser\n+from l20n.format.serializer import Serializer\n+from l20n.format import ast\n+\n+from pontoon.base.models import Locale\n+from pontoon.sync.exceptions import ParseError\n+from pontoon.sync.formats.base import ParsedResource\n+from pontoon.sync.vcs.models import VCSTranslation\n+\n+log = logging.getLogger(__name__)\n+\n+\n+class L20NStringEntity(VCSTranslation):\n+    \"\"\"\n+    Represents single string entities in l20n (without its attributes).\n+    e.g.\n+    <string_entry \"translation string\">\n+    \"\"\"\n+    def __init__(self, entry, translation_string, comments, order):\n+        self.entry = entry\n+        self.string = translation_string\n+        super(L20NStringEntity, self).__init__(\n+            key=entry.id.name,\n+            strings={None: translation_string},\n+            source_string=translation_string,\n+            comments=comments,\n+            fuzzy=False,\n+            order=order,\n+        )\n+\n+    def __repr__(self):\n+        return '<L20NStringEntity {key}>'.format(key=self.key.encode('utf-8'))\n+\n+    def update_entry(self, structure, locale):\n+        if self.strings:\n+            self.entry.value.content[0] = self.strings[None]\n+        else:\n+            structure.body.remove(self.entry)\n+\n+class L20NHashEntity(VCSTranslation):\n+    \"\"\"\n+    Represents the hash objects in l20n (without its attributes).\n+    e.g.\n+    <sample_hash {\n+        one: 'One string',\n+        other: 'Many string'\n+    }>\n+    \"\"\"\n+    def __init__(self, entry, strings, comments, order):\n+        self.entry = entry\n+        super(L20NHashEntity, self).__init__(\n+            key=entry.id.name,\n+            source_string=strings.get(0, ''),\n+            source_string_plural=strings.get(1, ''),\n+            strings=strings,\n+            comments=comments,\n+            fuzzy=False,\n+            order=order,\n+        )\n+\n+    def __repr__(self):\n+        return '<L20NHashEntity {key}>'.format(key=self.key.encode('utf-8'))\n+\n+    def update_entry(self, structure, locale):\n+        if self.strings:\n+            self.entry.value.items = (\n+                ast.HashItem(\n+                    ast.Identifier(locale.get_cldr_plural(plural_form)),\n+                    ast.String([value], value),\n+                    False\n+                ) for plural_form, value in self.strings.items()\n+            )\n+        else:\n+            structure.body.remove(self.entry)\n+\n+\n+class L20NAttributeEntity(VCSTranslation):\n+    \"\"\"\n+    Represents an attributes of the parent entity/entry.\n+    e.g.\n+    <sample_entry \"Sample string\"\n+        sample_attr: \"Sample attribute\">\n+    Will modify only contents of sample_attr.\n+    \"\"\"\n+    def __init__(self, entry, attr, order):\n+        self.entry = entry\n+        self.attr = attr\n+        self.string = attr.value.source\n+        super(L20NAttributeEntity, self).__init__(\n+            key=\".\".join([entry.id.name, attr.id.name]),\n+            source_string=attr.value.source,\n+            strings={None: attr.value.source},\n+            comments=[],\n+            fuzzy=False,\n+            order=order,\n+        )\n+\n+    def __repr__(self):\n+        return '<L20NAttributeEntity {key}>'.format(key=self.key.encode('utf-8'))\n+\n+    def update_entry(self, structure, locale):\n+        if self.strings:\n+            self.attr.value.content[0] = self.strings[None]\n+        else:\n+            self.entry.attrs.remove(self.attr)\n+\n+\n+class L20NResource(ParsedResource):\n+    def __init__(self, path, source_path, locale, structure):\n+        self.path = path\n+        self.source_path = source_path\n+        self.locale = locale\n+        self.structure = structure\n+\n+    @property\n+    def translations(self):\n+        \"\"\"\n+        Method maps objects from parser to the VCS translations.\n+        To avoid unecessary computations, translations are memoized.","path":"pontoon/sync/formats/l20n.py","position":124,"original_position":124,"commit_id":"ab4067f538f52f74437e2cf46978a11dabdc869e","original_commit_id":"ab4067f538f52f74437e2cf46978a11dabdc869e","user":{"login":"mathjazz","id":626716,"avatar_url":"https://avatars.githubusercontent.com/u/626716?v=3","gravatar_id":"","url":"https://api.github.com/users/mathjazz","html_url":"https://github.com/mathjazz","followers_url":"https://api.github.com/users/mathjazz/followers","following_url":"https://api.github.com/users/mathjazz/following{/other_user}","gists_url":"https://api.github.com/users/mathjazz/gists{/gist_id}","starred_url":"https://api.github.com/users/mathjazz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathjazz/subscriptions","organizations_url":"https://api.github.com/users/mathjazz/orgs","repos_url":"https://api.github.com/users/mathjazz/repos","events_url":"https://api.github.com/users/mathjazz/events{/privacy}","received_events_url":"https://api.github.com/users/mathjazz/received_events","type":"User","site_admin":false},"body":"Memorized.","created_at":"2016-01-18T11:53:37Z","updated_at":"2016-01-18T11:53:37Z","html_url":"https://github.com/mozilla/pontoon/pull/322#discussion_r49990069","pull_request_url":"https://api.github.com/repos/mozilla/pontoon/pulls/322","_links":{"self":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/comments/49990069"},"html":{"href":"https://github.com/mozilla/pontoon/pull/322#discussion_r49990069"},"pull_request":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/322"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/pontoon/pulls/322","id":55722061,"html_url":"https://github.com/mozilla/pontoon/pull/322","diff_url":"https://github.com/mozilla/pontoon/pull/322.diff","patch_url":"https://github.com/mozilla/pontoon/pull/322.patch","issue_url":"https://api.github.com/repos/mozilla/pontoon/issues/322","number":322,"state":"open","locked":false,"title":"Bug 1236109: Synchronization of l20n files.","user":{"login":"jotes","id":8784972,"avatar_url":"https://avatars.githubusercontent.com/u/8784972?v=3","gravatar_id":"","url":"https://api.github.com/users/jotes","html_url":"https://github.com/jotes","followers_url":"https://api.github.com/users/jotes/followers","following_url":"https://api.github.com/users/jotes/following{/other_user}","gists_url":"https://api.github.com/users/jotes/gists{/gist_id}","starred_url":"https://api.github.com/users/jotes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jotes/subscriptions","organizations_url":"https://api.github.com/users/jotes/orgs","repos_url":"https://api.github.com/users/jotes/repos","events_url":"https://api.github.com/users/jotes/events{/privacy}","received_events_url":"https://api.github.com/users/jotes/received_events","type":"User","site_admin":false},"body":"Hi, i decided to split work into smaller reviewable parts. @mathjazz  Could you look at this? It's still in initial stage, i'll try to finish the rest asap.","created_at":"2016-01-12T07:15:49Z","updated_at":"2016-01-18T11:53:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"912168ed3c178879772fb27ecdd854ab9483e4ce","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/pontoon/pulls/322/commits","review_comments_url":"https://api.github.com/repos/mozilla/pontoon/pulls/322/comments","review_comment_url":"https://api.github.com/repos/mozilla/pontoon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/pontoon/issues/322/comments","statuses_url":"https://api.github.com/repos/mozilla/pontoon/statuses/ab4067f538f52f74437e2cf46978a11dabdc869e","head":{"label":"jotes:support_for_l20n","ref":"support_for_l20n","sha":"ab4067f538f52f74437e2cf46978a11dabdc869e","user":{"login":"jotes","id":8784972,"avatar_url":"https://avatars.githubusercontent.com/u/8784972?v=3","gravatar_id":"","url":"https://api.github.com/users/jotes","html_url":"https://github.com/jotes","followers_url":"https://api.github.com/users/jotes/followers","following_url":"https://api.github.com/users/jotes/following{/other_user}","gists_url":"https://api.github.com/users/jotes/gists{/gist_id}","starred_url":"https://api.github.com/users/jotes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jotes/subscriptions","organizations_url":"https://api.github.com/users/jotes/orgs","repos_url":"https://api.github.com/users/jotes/repos","events_url":"https://api.github.com/users/jotes/events{/privacy}","received_events_url":"https://api.github.com/users/jotes/received_events","type":"User","site_admin":false},"repo":{"id":40921914,"name":"pontoon","full_name":"jotes/pontoon","owner":{"login":"jotes","id":8784972,"avatar_url":"https://avatars.githubusercontent.com/u/8784972?v=3","gravatar_id":"","url":"https://api.github.com/users/jotes","html_url":"https://github.com/jotes","followers_url":"https://api.github.com/users/jotes/followers","following_url":"https://api.github.com/users/jotes/following{/other_user}","gists_url":"https://api.github.com/users/jotes/gists{/gist_id}","starred_url":"https://api.github.com/users/jotes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jotes/subscriptions","organizations_url":"https://api.github.com/users/jotes/orgs","repos_url":"https://api.github.com/users/jotes/repos","events_url":"https://api.github.com/users/jotes/events{/privacy}","received_events_url":"https://api.github.com/users/jotes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jotes/pontoon","description":"In-place localization tool","fork":true,"url":"https://api.github.com/repos/jotes/pontoon","forks_url":"https://api.github.com/repos/jotes/pontoon/forks","keys_url":"https://api.github.com/repos/jotes/pontoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jotes/pontoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jotes/pontoon/teams","hooks_url":"https://api.github.com/repos/jotes/pontoon/hooks","issue_events_url":"https://api.github.com/repos/jotes/pontoon/issues/events{/number}","events_url":"https://api.github.com/repos/jotes/pontoon/events","assignees_url":"https://api.github.com/repos/jotes/pontoon/assignees{/user}","branches_url":"https://api.github.com/repos/jotes/pontoon/branches{/branch}","tags_url":"https://api.github.com/repos/jotes/pontoon/tags","blobs_url":"https://api.github.com/repos/jotes/pontoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jotes/pontoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jotes/pontoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/jotes/pontoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jotes/pontoon/statuses/{sha}","languages_url":"https://api.github.com/repos/jotes/pontoon/languages","stargazers_url":"https://api.github.com/repos/jotes/pontoon/stargazers","contributors_url":"https://api.github.com/repos/jotes/pontoon/contributors","subscribers_url":"https://api.github.com/repos/jotes/pontoon/subscribers","subscription_url":"https://api.github.com/repos/jotes/pontoon/subscription","commits_url":"https://api.github.com/repos/jotes/pontoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/jotes/pontoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/jotes/pontoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/jotes/pontoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/jotes/pontoon/contents/{+path}","compare_url":"https://api.github.com/repos/jotes/pontoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jotes/pontoon/merges","archive_url":"https://api.github.com/repos/jotes/pontoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jotes/pontoon/downloads","issues_url":"https://api.github.com/repos/jotes/pontoon/issues{/number}","pulls_url":"https://api.github.com/repos/jotes/pontoon/pulls{/number}","milestones_url":"https://api.github.com/repos/jotes/pontoon/milestones{/number}","notifications_url":"https://api.github.com/repos/jotes/pontoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jotes/pontoon/labels{/name}","releases_url":"https://api.github.com/repos/jotes/pontoon/releases{/id}","created_at":"2015-08-17T19:18:45Z","updated_at":"2016-01-15T00:41:30Z","pushed_at":"2016-01-18T06:34:33Z","git_url":"git://github.com/jotes/pontoon.git","ssh_url":"git@github.com:jotes/pontoon.git","clone_url":"https://github.com/jotes/pontoon.git","svn_url":"https://github.com/jotes/pontoon","homepage":"https://pontoon.mozilla.org/","size":18881,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"mozilla:master","ref":"master","sha":"9c53c7c56c5cc1985117daeda7eb5dd71b8c8f7d","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1385890,"name":"pontoon","full_name":"mozilla/pontoon","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/pontoon","description":"In-place localization tool","fork":false,"url":"https://api.github.com/repos/mozilla/pontoon","forks_url":"https://api.github.com/repos/mozilla/pontoon/forks","keys_url":"https://api.github.com/repos/mozilla/pontoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/pontoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/pontoon/teams","hooks_url":"https://api.github.com/repos/mozilla/pontoon/hooks","issue_events_url":"https://api.github.com/repos/mozilla/pontoon/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/pontoon/events","assignees_url":"https://api.github.com/repos/mozilla/pontoon/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/pontoon/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/pontoon/tags","blobs_url":"https://api.github.com/repos/mozilla/pontoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/pontoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/pontoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/pontoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/pontoon/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/pontoon/languages","stargazers_url":"https://api.github.com/repos/mozilla/pontoon/stargazers","contributors_url":"https://api.github.com/repos/mozilla/pontoon/contributors","subscribers_url":"https://api.github.com/repos/mozilla/pontoon/subscribers","subscription_url":"https://api.github.com/repos/mozilla/pontoon/subscription","commits_url":"https://api.github.com/repos/mozilla/pontoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/pontoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/pontoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/pontoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/pontoon/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/pontoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/pontoon/merges","archive_url":"https://api.github.com/repos/mozilla/pontoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/pontoon/downloads","issues_url":"https://api.github.com/repos/mozilla/pontoon/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/pontoon/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/pontoon/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/pontoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/pontoon/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/pontoon/releases{/id}","created_at":"2011-02-19T11:25:51Z","updated_at":"2016-01-18T06:56:50Z","pushed_at":"2016-01-18T06:34:33Z","git_url":"git://github.com/mozilla/pontoon.git","ssh_url":"git@github.com:mozilla/pontoon.git","clone_url":"https://github.com/mozilla/pontoon.git","svn_url":"https://github.com/mozilla/pontoon","homepage":"https://pontoon.mozilla.org/","size":19146,"stargazers_count":94,"watchers_count":94,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":6,"forks":34,"open_issues":6,"watchers":94,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/322"},"html":{"href":"https://github.com/mozilla/pontoon/pull/322"},"issue":{"href":"https://api.github.com/repos/mozilla/pontoon/issues/322"},"comments":{"href":"https://api.github.com/repos/mozilla/pontoon/issues/322/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/322/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/pontoon/pulls/322/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/pontoon/statuses/ab4067f538f52f74437e2cf46978a11dabdc869e"}}}}