{"action":"created","comment":{"url":"https://api.github.com/repos/omegaup/hook_tools/pulls/comments/185908503","pull_request_review_id":117394570,"id":185908503,"diff_hunk":"@@ -441,11 +463,203 @@ def run_one(self, filename, contents):\n \n             return contents, []\n \n+    def run_all(self, file_contents, contents_callback):\n+        return [], [], []\n+\n     @property\n     def name(self):\n         return 'python'\n \n \n+class I18nLinter(Linter):\n+    '''Runs i18n'''\n+    # pylint: disable=R0903\n+\n+    # Paths\n+    _JS_TEMPLATES_PATH = 'frontend/www/js/omegaup'\n+    _TEMPLATES_PATH = 'frontend/templates'\n+\n+    # Colours\n+    _OKGREEN = git_tools.COLORS.OKGREEN\n+    _FAIL = git_tools.COLORS.FAIL\n+    _NORMAL = git_tools.COLORS.NORMAL\n+    _HEADER = git_tools.COLORS.HEADER\n+    _LANGS = ['en', 'es', 'pt', 'pseudo']\n+\n+    def __init__(self, options=None):\n+        super().__init__()\n+        self.__options = options or {}\n+\n+    @staticmethod\n+    def _generate_javascript(lang, strings):\n+        '''Generates the JavaScript version of the i18n file.'''\n+\n+        result = []\n+        result.append('// generated by stuff/i18n.py. DO NOT EDIT.')\n+        result.append(\"var omegaup = require('../dist/omegaup.js');\\n\")\n+        result.append('omegaup.OmegaUp.loadTranslations({')\n+        for key in sorted(strings.keys()):\n+            result.append('\\t%s: %s,' % (key, json.dumps(strings[key][lang])))\n+        result.append('});\\n')\n+        return '\\n'.join(result)\n+\n+    @staticmethod\n+    def _generate_json(lang, strings):\n+        '''Generates the JSON version of the i18n file.'''\n+\n+        json_map = {}\n+        for key in sorted(strings.keys()):\n+            json_map[key] = strings[key][lang]\n+        return json_map\n+\n+    @staticmethod\n+    def _generate_pseudo(lang, strings):\n+        '''Generates pseudoloc file'''\n+\n+        result = []\n+        for key in sorted(strings.keys()):\n+            result.append('%s = \"%s\"\\n' %\n+                          (key, strings[key][lang].replace('\"', r'\\\"')))\n+        return ''.join(result)\n+\n+    @staticmethod\n+    def _pseudoloc(original):\n+        '''Converts the pseudoloc version of s.'''\n+        table = str.maketrans('elsot', '31507')\n+        tokens = re.split(r'(%\\([a-zA-Z0-9_-]+\\))', original)\n+        for i, token in enumerate(tokens):\n+            if token.startswith('%(') and token.endswith(')'):\n+                continue\n+            tokens[i] = token.translate(table)\n+\n+        return '(%s)' % ''.join(tokens)\n+\n+    def _get_translated_strings(self, contents_callback, not_sorted):\n+        strings = {}\n+        languages = set()\n+        for lang in self._LANGS:\n+            content = self._get_filename_and_contents(lang, contents_callback)\n+            languages.add(lang)\n+            last_key = ''\n+            for lineno, line in enumerate(content['contents']):\n+                try:\n+                    row = line.decode('utf-8')\n+                    key, value = re.compile(r'\\s+=\\s+').split(row.strip(), 1)\n+                    if last_key >= key:\n+                        not_sorted.add(lang)\n+                    last_key = key\n+                    if key not in strings:\n+                        strings[key] = collections.defaultdict(str)\n+                    match = re.compile(r'^\"((?:[^\"]|\\\\\")*)\"$').match(value)\n+                    if match is None:\n+                        raise Exception(\"Invalid value\")\n+                    strings[key][lang] = match.group(1).replace(r'\\\"', '\"')\n+                except:  # pylint: disable=bare-except\n+                    raise LinterException('Invalid i18n line \"%s\" in %s:%d' %\n+                                          (row.strip(), content['filename'],\n+                                           lineno + 1), fixable=False)\n+\n+        if not_sorted:\n+            raise LinterException('Entries in %s are not sorted.'\n+                                  % ', '.join(sorted(not_sorted)),\n+                                  fixable=False)\n+\n+        return self._check_missing_entries(strings, languages)\n+\n+    def _check_missing_entries(self, strings, languages):\n+        missing_items_lang = set()\n+        for key, values in strings.items():\n+            missing_languages = languages.difference(list(values.keys()))\n+            if 'pseudo' in missing_languages:\n+                missing_languages.remove('pseudo')\n+\n+            if missing_languages:\n+                print('%s%s%s' % (self._HEADER, key, self._NORMAL),\n+                      file=sys.stderr)\n+\n+                for lang in sorted(languages):\n+                    if lang in values:\n+                        print('\\t%s%-10s%s %s' %\n+                              (self._OKGREEN, lang, self._NORMAL,\n+                               values[lang]), file=sys.stderr)\n+                    else:\n+                        print('\\t%s%-10s%s missing%s' %\n+                              (self._OKGREEN, lang, self._FAIL, self._NORMAL),\n+                              file=sys.stderr)\n+                        missing_items_lang.add(lang)\n+\n+                raise LinterException('There are missing items in the %s.lang'\n+                                      ' file' % missing_items_lang,\n+                                      fixable=False)\n+\n+            if key == 'locale':\n+                values['pseudo'] = 'pseudo'\n+            else:\n+                values['pseudo'] = self._pseudoloc(values['en'])\n+\n+        return strings","path":"linters.py","position":null,"original_position":212,"commit_id":"3f517e0ad2c2cff28eae294e4357d9e148d8dcff","original_commit_id":"1000a792719acbd67a0df155ca68bbdbfeef3535","user":{"login":"pabo99","id":3230352,"avatar_url":"https://avatars0.githubusercontent.com/u/3230352?v=4","gravatar_id":"","url":"https://api.github.com/users/pabo99","html_url":"https://github.com/pabo99","followers_url":"https://api.github.com/users/pabo99/followers","following_url":"https://api.github.com/users/pabo99/following{/other_user}","gists_url":"https://api.github.com/users/pabo99/gists{/gist_id}","starred_url":"https://api.github.com/users/pabo99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabo99/subscriptions","organizations_url":"https://api.github.com/users/pabo99/orgs","repos_url":"https://api.github.com/users/pabo99/repos","events_url":"https://api.github.com/users/pabo99/events{/privacy}","received_events_url":"https://api.github.com/users/pabo99/received_events","type":"User","site_admin":false},"body":"listo","created_at":"2018-05-03T19:14:56Z","updated_at":"2018-05-03T19:14:56Z","html_url":"https://github.com/omegaup/hook_tools/pull/6#discussion_r185908503","pull_request_url":"https://api.github.com/repos/omegaup/hook_tools/pulls/6","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/comments/185908503"},"html":{"href":"https://github.com/omegaup/hook_tools/pull/6#discussion_r185908503"},"pull_request":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/6"}},"in_reply_to_id":185502695},"pull_request":{"url":"https://api.github.com/repos/omegaup/hook_tools/pulls/6","id":179860958,"html_url":"https://github.com/omegaup/hook_tools/pull/6","diff_url":"https://github.com/omegaup/hook_tools/pull/6.diff","patch_url":"https://github.com/omegaup/hook_tools/pull/6.patch","issue_url":"https://api.github.com/repos/omegaup/hook_tools/issues/6","number":6,"state":"open","locked":false,"title":"Agregando el i18n como un validador en los linters","user":{"login":"pabo99","id":3230352,"avatar_url":"https://avatars0.githubusercontent.com/u/3230352?v=4","gravatar_id":"","url":"https://api.github.com/users/pabo99","html_url":"https://github.com/pabo99","followers_url":"https://api.github.com/users/pabo99/followers","following_url":"https://api.github.com/users/pabo99/following{/other_user}","gists_url":"https://api.github.com/users/pabo99/gists{/gist_id}","starred_url":"https://api.github.com/users/pabo99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabo99/subscriptions","organizations_url":"https://api.github.com/users/pabo99/orgs","repos_url":"https://api.github.com/users/pabo99/repos","events_url":"https://api.github.com/users/pabo99/events{/privacy}","received_events_url":"https://api.github.com/users/pabo99/received_events","type":"User","site_admin":false},"body":"Se agrega la clase `I18nLinter` para validar los archivos de internacionalización.\r\n\r\nFixes #1319","created_at":"2018-04-06T06:01:03Z","updated_at":"2018-05-03T19:14:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9b70475e4b529901e44fc59941647a58e438645d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/omegaup/hook_tools/pulls/6/commits","review_comments_url":"https://api.github.com/repos/omegaup/hook_tools/pulls/6/comments","review_comment_url":"https://api.github.com/repos/omegaup/hook_tools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/omegaup/hook_tools/issues/6/comments","statuses_url":"https://api.github.com/repos/omegaup/hook_tools/statuses/3f517e0ad2c2cff28eae294e4357d9e148d8dcff","head":{"label":"pabo99:add-i18n-linter","ref":"add-i18n-linter","sha":"3f517e0ad2c2cff28eae294e4357d9e148d8dcff","user":{"login":"pabo99","id":3230352,"avatar_url":"https://avatars0.githubusercontent.com/u/3230352?v=4","gravatar_id":"","url":"https://api.github.com/users/pabo99","html_url":"https://github.com/pabo99","followers_url":"https://api.github.com/users/pabo99/followers","following_url":"https://api.github.com/users/pabo99/following{/other_user}","gists_url":"https://api.github.com/users/pabo99/gists{/gist_id}","starred_url":"https://api.github.com/users/pabo99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabo99/subscriptions","organizations_url":"https://api.github.com/users/pabo99/orgs","repos_url":"https://api.github.com/users/pabo99/repos","events_url":"https://api.github.com/users/pabo99/events{/privacy}","received_events_url":"https://api.github.com/users/pabo99/received_events","type":"User","site_admin":false},"repo":{"id":126928250,"name":"hook_tools","full_name":"pabo99/hook_tools","owner":{"login":"pabo99","id":3230352,"avatar_url":"https://avatars0.githubusercontent.com/u/3230352?v=4","gravatar_id":"","url":"https://api.github.com/users/pabo99","html_url":"https://github.com/pabo99","followers_url":"https://api.github.com/users/pabo99/followers","following_url":"https://api.github.com/users/pabo99/following{/other_user}","gists_url":"https://api.github.com/users/pabo99/gists{/gist_id}","starred_url":"https://api.github.com/users/pabo99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabo99/subscriptions","organizations_url":"https://api.github.com/users/pabo99/orgs","repos_url":"https://api.github.com/users/pabo99/repos","events_url":"https://api.github.com/users/pabo99/events{/privacy}","received_events_url":"https://api.github.com/users/pabo99/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pabo99/hook_tools","description":"Herramientas para hacer validaciones automáticas de código","fork":true,"url":"https://api.github.com/repos/pabo99/hook_tools","forks_url":"https://api.github.com/repos/pabo99/hook_tools/forks","keys_url":"https://api.github.com/repos/pabo99/hook_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pabo99/hook_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pabo99/hook_tools/teams","hooks_url":"https://api.github.com/repos/pabo99/hook_tools/hooks","issue_events_url":"https://api.github.com/repos/pabo99/hook_tools/issues/events{/number}","events_url":"https://api.github.com/repos/pabo99/hook_tools/events","assignees_url":"https://api.github.com/repos/pabo99/hook_tools/assignees{/user}","branches_url":"https://api.github.com/repos/pabo99/hook_tools/branches{/branch}","tags_url":"https://api.github.com/repos/pabo99/hook_tools/tags","blobs_url":"https://api.github.com/repos/pabo99/hook_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pabo99/hook_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pabo99/hook_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/pabo99/hook_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pabo99/hook_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/pabo99/hook_tools/languages","stargazers_url":"https://api.github.com/repos/pabo99/hook_tools/stargazers","contributors_url":"https://api.github.com/repos/pabo99/hook_tools/contributors","subscribers_url":"https://api.github.com/repos/pabo99/hook_tools/subscribers","subscription_url":"https://api.github.com/repos/pabo99/hook_tools/subscription","commits_url":"https://api.github.com/repos/pabo99/hook_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/pabo99/hook_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/pabo99/hook_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/pabo99/hook_tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/pabo99/hook_tools/contents/{+path}","compare_url":"https://api.github.com/repos/pabo99/hook_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pabo99/hook_tools/merges","archive_url":"https://api.github.com/repos/pabo99/hook_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pabo99/hook_tools/downloads","issues_url":"https://api.github.com/repos/pabo99/hook_tools/issues{/number}","pulls_url":"https://api.github.com/repos/pabo99/hook_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/pabo99/hook_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/pabo99/hook_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pabo99/hook_tools/labels{/name}","releases_url":"https://api.github.com/repos/pabo99/hook_tools/releases{/id}","deployments_url":"https://api.github.com/repos/pabo99/hook_tools/deployments","created_at":"2018-03-27T04:21:42Z","updated_at":"2018-03-27T04:21:43Z","pushed_at":"2018-05-03T19:11:55Z","git_url":"git://github.com/pabo99/hook_tools.git","ssh_url":"git@github.com:pabo99/hook_tools.git","clone_url":"https://github.com/pabo99/hook_tools.git","svn_url":"https://github.com/pabo99/hook_tools","homepage":null,"size":346,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"omegaup:master","ref":"master","sha":"7bcb953298a2c9550fb8bc7ebe849f1756a328c7","user":{"login":"omegaup","id":558429,"avatar_url":"https://avatars0.githubusercontent.com/u/558429?v=4","gravatar_id":"","url":"https://api.github.com/users/omegaup","html_url":"https://github.com/omegaup","followers_url":"https://api.github.com/users/omegaup/followers","following_url":"https://api.github.com/users/omegaup/following{/other_user}","gists_url":"https://api.github.com/users/omegaup/gists{/gist_id}","starred_url":"https://api.github.com/users/omegaup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omegaup/subscriptions","organizations_url":"https://api.github.com/users/omegaup/orgs","repos_url":"https://api.github.com/users/omegaup/repos","events_url":"https://api.github.com/users/omegaup/events{/privacy}","received_events_url":"https://api.github.com/users/omegaup/received_events","type":"Organization","site_admin":false},"repo":{"id":89899357,"name":"hook_tools","full_name":"omegaup/hook_tools","owner":{"login":"omegaup","id":558429,"avatar_url":"https://avatars0.githubusercontent.com/u/558429?v=4","gravatar_id":"","url":"https://api.github.com/users/omegaup","html_url":"https://github.com/omegaup","followers_url":"https://api.github.com/users/omegaup/followers","following_url":"https://api.github.com/users/omegaup/following{/other_user}","gists_url":"https://api.github.com/users/omegaup/gists{/gist_id}","starred_url":"https://api.github.com/users/omegaup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omegaup/subscriptions","organizations_url":"https://api.github.com/users/omegaup/orgs","repos_url":"https://api.github.com/users/omegaup/repos","events_url":"https://api.github.com/users/omegaup/events{/privacy}","received_events_url":"https://api.github.com/users/omegaup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/omegaup/hook_tools","description":"Herramientas para hacer validaciones automáticas de código","fork":false,"url":"https://api.github.com/repos/omegaup/hook_tools","forks_url":"https://api.github.com/repos/omegaup/hook_tools/forks","keys_url":"https://api.github.com/repos/omegaup/hook_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/omegaup/hook_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/omegaup/hook_tools/teams","hooks_url":"https://api.github.com/repos/omegaup/hook_tools/hooks","issue_events_url":"https://api.github.com/repos/omegaup/hook_tools/issues/events{/number}","events_url":"https://api.github.com/repos/omegaup/hook_tools/events","assignees_url":"https://api.github.com/repos/omegaup/hook_tools/assignees{/user}","branches_url":"https://api.github.com/repos/omegaup/hook_tools/branches{/branch}","tags_url":"https://api.github.com/repos/omegaup/hook_tools/tags","blobs_url":"https://api.github.com/repos/omegaup/hook_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/omegaup/hook_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/omegaup/hook_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/omegaup/hook_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/omegaup/hook_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/omegaup/hook_tools/languages","stargazers_url":"https://api.github.com/repos/omegaup/hook_tools/stargazers","contributors_url":"https://api.github.com/repos/omegaup/hook_tools/contributors","subscribers_url":"https://api.github.com/repos/omegaup/hook_tools/subscribers","subscription_url":"https://api.github.com/repos/omegaup/hook_tools/subscription","commits_url":"https://api.github.com/repos/omegaup/hook_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/omegaup/hook_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/omegaup/hook_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/omegaup/hook_tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/omegaup/hook_tools/contents/{+path}","compare_url":"https://api.github.com/repos/omegaup/hook_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/omegaup/hook_tools/merges","archive_url":"https://api.github.com/repos/omegaup/hook_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/omegaup/hook_tools/downloads","issues_url":"https://api.github.com/repos/omegaup/hook_tools/issues{/number}","pulls_url":"https://api.github.com/repos/omegaup/hook_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/omegaup/hook_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/omegaup/hook_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/omegaup/hook_tools/labels{/name}","releases_url":"https://api.github.com/repos/omegaup/hook_tools/releases{/id}","deployments_url":"https://api.github.com/repos/omegaup/hook_tools/deployments","created_at":"2017-05-01T05:16:46Z","updated_at":"2018-03-29T14:00:27Z","pushed_at":"2018-05-03T19:11:56Z","git_url":"git://github.com/omegaup/hook_tools.git","ssh_url":"git@github.com:omegaup/hook_tools.git","clone_url":"https://github.com/omegaup/hook_tools.git","svn_url":"https://github.com/omegaup/hook_tools","homepage":null,"size":241,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":3,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/6"},"html":{"href":"https://github.com/omegaup/hook_tools/pull/6"},"issue":{"href":"https://api.github.com/repos/omegaup/hook_tools/issues/6"},"comments":{"href":"https://api.github.com/repos/omegaup/hook_tools/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/omegaup/hook_tools/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/omegaup/hook_tools/statuses/3f517e0ad2c2cff28eae294e4357d9e148d8dcff"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pabo99"}}