{"action":"created","comment":{"url":"https://api.github.com/repos/viewstools/get-text/pulls/comments/176063379","pull_request_review_id":105698535,"id":176063379,"diff_hunk":"@@ -0,0 +1,68 @@\n+const REPLACE = /^(?:text|placeholder)\\s(?:<[^\\s]*\\s)?(.*)/;\n+const GET_TEXT_AND_SLOT = /\\/(text|placeholder)\\s(<[^\\s]*\\s)?/;\n+\n+const isText = line => /^(text|placeholder)/.test(line);\n+const isBlock = line => /^[A-Z]/.test(line);\n+const replaceText = (line, newText) =>\n+  line.replace(line.match(REPLACE)[1], newText);\n+const getPath = key => {\n+  const match = key.match(/([^\\s]+)\\s/);\n+  return match[1].split('/');\n+};\n+const getStartIndex = (path, lines) => {\n+  let startIndex = 0;\n+  path.forEach((name, index) => {\n+    for (let i = startIndex; i < lines.length; i++) {\n+      if (isBlock(name) && new RegExp(name).test(lines[i])) {\n+        startIndex = i + 1;\n+        break;\n+      }\n+    }\n+  });\n+  return startIndex;\n+};\n+\n+function setI18n({ defaultLanguage, source, view, translations }) {\n+  if (!defaultLanguage) {\n+    defaultLanguage = 'en';\n+  }\n+  const lines = source\n+    .replace(/\\r\\n/g, '\\n')\n+    .split('\\n')\n+    .map(line => line.trim());\n+  const languages = Object.keys(translations).filter(\n+    lang => lang !== defaultLanguage\n+  );\n+  const keys = Object.keys(translations[defaultLanguage]);\n+\n+  keys.forEach(key => {\n+    const startIndex = getStartIndex(getPath(key), lines);\n+    languages.forEach(lang => {\n+      let added = false;\n+      let i = startIndex;\n+      while (!added) {\n+        const bits = key.match(GET_TEXT_AND_SLOT);\n+        const whenLine = `when <${lang}`;\n+        const textLine = `${bits[1]} ${bits[2] || ''}${\n+          translations[lang][key]\n+        }`;","path":"set-i18n.js","position":48,"original_position":48,"commit_id":"242f175a5d296deac9e8d207fe0446ebf8ebf3de","original_commit_id":"242f175a5d296deac9e8d207fe0446ebf8ebf3de","user":{"login":"dariocravero","id":376268,"avatar_url":"https://avatars3.githubusercontent.com/u/376268?v=4","gravatar_id":"","url":"https://api.github.com/users/dariocravero","html_url":"https://github.com/dariocravero","followers_url":"https://api.github.com/users/dariocravero/followers","following_url":"https://api.github.com/users/dariocravero/following{/other_user}","gists_url":"https://api.github.com/users/dariocravero/gists{/gist_id}","starred_url":"https://api.github.com/users/dariocravero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariocravero/subscriptions","organizations_url":"https://api.github.com/users/dariocravero/orgs","repos_url":"https://api.github.com/users/dariocravero/repos","events_url":"https://api.github.com/users/dariocravero/events{/privacy}","received_events_url":"https://api.github.com/users/dariocravero/received_events","type":"User","site_admin":false},"body":"we should be able to get these three constants outside of the while loop","created_at":"2018-03-21T12:25:16Z","updated_at":"2018-03-21T12:25:16Z","html_url":"https://github.com/viewstools/get-text/pull/1#discussion_r176063379","pull_request_url":"https://api.github.com/repos/viewstools/get-text/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/comments/176063379"},"html":{"href":"https://github.com/viewstools/get-text/pull/1#discussion_r176063379"},"pull_request":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/viewstools/get-text/pulls/1","id":175581493,"html_url":"https://github.com/viewstools/get-text/pull/1","diff_url":"https://github.com/viewstools/get-text/pull/1.diff","patch_url":"https://github.com/viewstools/get-text/pull/1.patch","issue_url":"https://api.github.com/repos/viewstools/get-text/issues/1","number":1,"state":"open","locked":false,"title":"Set","user":{"login":"eugenserbanescu","id":4499514,"avatar_url":"https://avatars1.githubusercontent.com/u/4499514?v=4","gravatar_id":"","url":"https://api.github.com/users/eugenserbanescu","html_url":"https://github.com/eugenserbanescu","followers_url":"https://api.github.com/users/eugenserbanescu/followers","following_url":"https://api.github.com/users/eugenserbanescu/following{/other_user}","gists_url":"https://api.github.com/users/eugenserbanescu/gists{/gist_id}","starred_url":"https://api.github.com/users/eugenserbanescu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugenserbanescu/subscriptions","organizations_url":"https://api.github.com/users/eugenserbanescu/orgs","repos_url":"https://api.github.com/users/eugenserbanescu/repos","events_url":"https://api.github.com/users/eugenserbanescu/events{/privacy}","received_events_url":"https://api.github.com/users/eugenserbanescu/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-03-16T16:20:55Z","updated_at":"2018-03-21T12:25:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e00ee2666a57b75953e589017a5a47dae97285e","assignee":null,"assignees":[],"requested_reviewers":[{"login":"neesonch","id":8180182,"avatar_url":"https://avatars1.githubusercontent.com/u/8180182?v=4","gravatar_id":"","url":"https://api.github.com/users/neesonch","html_url":"https://github.com/neesonch","followers_url":"https://api.github.com/users/neesonch/followers","following_url":"https://api.github.com/users/neesonch/following{/other_user}","gists_url":"https://api.github.com/users/neesonch/gists{/gist_id}","starred_url":"https://api.github.com/users/neesonch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neesonch/subscriptions","organizations_url":"https://api.github.com/users/neesonch/orgs","repos_url":"https://api.github.com/users/neesonch/repos","events_url":"https://api.github.com/users/neesonch/events{/privacy}","received_events_url":"https://api.github.com/users/neesonch/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/viewstools/get-text/pulls/1/commits","review_comments_url":"https://api.github.com/repos/viewstools/get-text/pulls/1/comments","review_comment_url":"https://api.github.com/repos/viewstools/get-text/pulls/comments{/number}","comments_url":"https://api.github.com/repos/viewstools/get-text/issues/1/comments","statuses_url":"https://api.github.com/repos/viewstools/get-text/statuses/242f175a5d296deac9e8d207fe0446ebf8ebf3de","head":{"label":"viewstools:set","ref":"set","sha":"242f175a5d296deac9e8d207fe0446ebf8ebf3de","user":{"login":"viewstools","id":25788402,"avatar_url":"https://avatars2.githubusercontent.com/u/25788402?v=4","gravatar_id":"","url":"https://api.github.com/users/viewstools","html_url":"https://github.com/viewstools","followers_url":"https://api.github.com/users/viewstools/followers","following_url":"https://api.github.com/users/viewstools/following{/other_user}","gists_url":"https://api.github.com/users/viewstools/gists{/gist_id}","starred_url":"https://api.github.com/users/viewstools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viewstools/subscriptions","organizations_url":"https://api.github.com/users/viewstools/orgs","repos_url":"https://api.github.com/users/viewstools/repos","events_url":"https://api.github.com/users/viewstools/events{/privacy}","received_events_url":"https://api.github.com/users/viewstools/received_events","type":"Organization","site_admin":false},"repo":{"id":121377447,"name":"get-text","full_name":"viewstools/get-text","owner":{"login":"viewstools","id":25788402,"avatar_url":"https://avatars2.githubusercontent.com/u/25788402?v=4","gravatar_id":"","url":"https://api.github.com/users/viewstools","html_url":"https://github.com/viewstools","followers_url":"https://api.github.com/users/viewstools/followers","following_url":"https://api.github.com/users/viewstools/following{/other_user}","gists_url":"https://api.github.com/users/viewstools/gists{/gist_id}","starred_url":"https://api.github.com/users/viewstools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viewstools/subscriptions","organizations_url":"https://api.github.com/users/viewstools/orgs","repos_url":"https://api.github.com/users/viewstools/repos","events_url":"https://api.github.com/users/viewstools/events{/privacy}","received_events_url":"https://api.github.com/users/viewstools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/viewstools/get-text","description":"Get your Views text into a JSON for ready for I18n","fork":false,"url":"https://api.github.com/repos/viewstools/get-text","forks_url":"https://api.github.com/repos/viewstools/get-text/forks","keys_url":"https://api.github.com/repos/viewstools/get-text/keys{/key_id}","collaborators_url":"https://api.github.com/repos/viewstools/get-text/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/viewstools/get-text/teams","hooks_url":"https://api.github.com/repos/viewstools/get-text/hooks","issue_events_url":"https://api.github.com/repos/viewstools/get-text/issues/events{/number}","events_url":"https://api.github.com/repos/viewstools/get-text/events","assignees_url":"https://api.github.com/repos/viewstools/get-text/assignees{/user}","branches_url":"https://api.github.com/repos/viewstools/get-text/branches{/branch}","tags_url":"https://api.github.com/repos/viewstools/get-text/tags","blobs_url":"https://api.github.com/repos/viewstools/get-text/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/viewstools/get-text/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/viewstools/get-text/git/refs{/sha}","trees_url":"https://api.github.com/repos/viewstools/get-text/git/trees{/sha}","statuses_url":"https://api.github.com/repos/viewstools/get-text/statuses/{sha}","languages_url":"https://api.github.com/repos/viewstools/get-text/languages","stargazers_url":"https://api.github.com/repos/viewstools/get-text/stargazers","contributors_url":"https://api.github.com/repos/viewstools/get-text/contributors","subscribers_url":"https://api.github.com/repos/viewstools/get-text/subscribers","subscription_url":"https://api.github.com/repos/viewstools/get-text/subscription","commits_url":"https://api.github.com/repos/viewstools/get-text/commits{/sha}","git_commits_url":"https://api.github.com/repos/viewstools/get-text/git/commits{/sha}","comments_url":"https://api.github.com/repos/viewstools/get-text/comments{/number}","issue_comment_url":"https://api.github.com/repos/viewstools/get-text/issues/comments{/number}","contents_url":"https://api.github.com/repos/viewstools/get-text/contents/{+path}","compare_url":"https://api.github.com/repos/viewstools/get-text/compare/{base}...{head}","merges_url":"https://api.github.com/repos/viewstools/get-text/merges","archive_url":"https://api.github.com/repos/viewstools/get-text/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/viewstools/get-text/downloads","issues_url":"https://api.github.com/repos/viewstools/get-text/issues{/number}","pulls_url":"https://api.github.com/repos/viewstools/get-text/pulls{/number}","milestones_url":"https://api.github.com/repos/viewstools/get-text/milestones{/number}","notifications_url":"https://api.github.com/repos/viewstools/get-text/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/viewstools/get-text/labels{/name}","releases_url":"https://api.github.com/repos/viewstools/get-text/releases{/id}","deployments_url":"https://api.github.com/repos/viewstools/get-text/deployments","created_at":"2018-02-13T12:00:15Z","updated_at":"2018-03-20T12:27:22Z","pushed_at":"2018-03-21T10:29:45Z","git_url":"git://github.com/viewstools/get-text.git","ssh_url":"git@github.com:viewstools/get-text.git","clone_url":"https://github.com/viewstools/get-text.git","svn_url":"https://github.com/viewstools/get-text","homepage":null,"size":44,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"viewstools:with-path","ref":"with-path","sha":"0f8c49700e4f93871d9e20109e6f23ba0fab3b8c","user":{"login":"viewstools","id":25788402,"avatar_url":"https://avatars2.githubusercontent.com/u/25788402?v=4","gravatar_id":"","url":"https://api.github.com/users/viewstools","html_url":"https://github.com/viewstools","followers_url":"https://api.github.com/users/viewstools/followers","following_url":"https://api.github.com/users/viewstools/following{/other_user}","gists_url":"https://api.github.com/users/viewstools/gists{/gist_id}","starred_url":"https://api.github.com/users/viewstools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viewstools/subscriptions","organizations_url":"https://api.github.com/users/viewstools/orgs","repos_url":"https://api.github.com/users/viewstools/repos","events_url":"https://api.github.com/users/viewstools/events{/privacy}","received_events_url":"https://api.github.com/users/viewstools/received_events","type":"Organization","site_admin":false},"repo":{"id":121377447,"name":"get-text","full_name":"viewstools/get-text","owner":{"login":"viewstools","id":25788402,"avatar_url":"https://avatars2.githubusercontent.com/u/25788402?v=4","gravatar_id":"","url":"https://api.github.com/users/viewstools","html_url":"https://github.com/viewstools","followers_url":"https://api.github.com/users/viewstools/followers","following_url":"https://api.github.com/users/viewstools/following{/other_user}","gists_url":"https://api.github.com/users/viewstools/gists{/gist_id}","starred_url":"https://api.github.com/users/viewstools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viewstools/subscriptions","organizations_url":"https://api.github.com/users/viewstools/orgs","repos_url":"https://api.github.com/users/viewstools/repos","events_url":"https://api.github.com/users/viewstools/events{/privacy}","received_events_url":"https://api.github.com/users/viewstools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/viewstools/get-text","description":"Get your Views text into a JSON for ready for I18n","fork":false,"url":"https://api.github.com/repos/viewstools/get-text","forks_url":"https://api.github.com/repos/viewstools/get-text/forks","keys_url":"https://api.github.com/repos/viewstools/get-text/keys{/key_id}","collaborators_url":"https://api.github.com/repos/viewstools/get-text/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/viewstools/get-text/teams","hooks_url":"https://api.github.com/repos/viewstools/get-text/hooks","issue_events_url":"https://api.github.com/repos/viewstools/get-text/issues/events{/number}","events_url":"https://api.github.com/repos/viewstools/get-text/events","assignees_url":"https://api.github.com/repos/viewstools/get-text/assignees{/user}","branches_url":"https://api.github.com/repos/viewstools/get-text/branches{/branch}","tags_url":"https://api.github.com/repos/viewstools/get-text/tags","blobs_url":"https://api.github.com/repos/viewstools/get-text/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/viewstools/get-text/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/viewstools/get-text/git/refs{/sha}","trees_url":"https://api.github.com/repos/viewstools/get-text/git/trees{/sha}","statuses_url":"https://api.github.com/repos/viewstools/get-text/statuses/{sha}","languages_url":"https://api.github.com/repos/viewstools/get-text/languages","stargazers_url":"https://api.github.com/repos/viewstools/get-text/stargazers","contributors_url":"https://api.github.com/repos/viewstools/get-text/contributors","subscribers_url":"https://api.github.com/repos/viewstools/get-text/subscribers","subscription_url":"https://api.github.com/repos/viewstools/get-text/subscription","commits_url":"https://api.github.com/repos/viewstools/get-text/commits{/sha}","git_commits_url":"https://api.github.com/repos/viewstools/get-text/git/commits{/sha}","comments_url":"https://api.github.com/repos/viewstools/get-text/comments{/number}","issue_comment_url":"https://api.github.com/repos/viewstools/get-text/issues/comments{/number}","contents_url":"https://api.github.com/repos/viewstools/get-text/contents/{+path}","compare_url":"https://api.github.com/repos/viewstools/get-text/compare/{base}...{head}","merges_url":"https://api.github.com/repos/viewstools/get-text/merges","archive_url":"https://api.github.com/repos/viewstools/get-text/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/viewstools/get-text/downloads","issues_url":"https://api.github.com/repos/viewstools/get-text/issues{/number}","pulls_url":"https://api.github.com/repos/viewstools/get-text/pulls{/number}","milestones_url":"https://api.github.com/repos/viewstools/get-text/milestones{/number}","notifications_url":"https://api.github.com/repos/viewstools/get-text/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/viewstools/get-text/labels{/name}","releases_url":"https://api.github.com/repos/viewstools/get-text/releases{/id}","deployments_url":"https://api.github.com/repos/viewstools/get-text/deployments","created_at":"2018-02-13T12:00:15Z","updated_at":"2018-03-20T12:27:22Z","pushed_at":"2018-03-21T10:29:45Z","git_url":"git://github.com/viewstools/get-text.git","ssh_url":"git@github.com:viewstools/get-text.git","clone_url":"https://github.com/viewstools/get-text.git","svn_url":"https://github.com/viewstools/get-text","homepage":null,"size":44,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/1"},"html":{"href":"https://github.com/viewstools/get-text/pull/1"},"issue":{"href":"https://api.github.com/repos/viewstools/get-text/issues/1"},"comments":{"href":"https://api.github.com/repos/viewstools/get-text/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/viewstools/get-text/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/viewstools/get-text/statuses/242f175a5d296deac9e8d207fe0446ebf8ebf3de"}},"author_association":"NONE"}}
{"actor":{"display_login":"dariocravero"}}