From 71569d61e043fc8fbf9fc97c4dd18f0ea956a41c Mon Sep 17 00:00:00 2001
From: David Beckley <beckl.ds@gmail.com>
Date: Fri, 19 Sep 2014 18:34:11 -0700
Subject: [PATCH 1/3] Fix issue #1472

---
 scripts/copy-i18n-tags.coffee | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/scripts/copy-i18n-tags.coffee b/scripts/copy-i18n-tags.coffee
index c7f49b975..2b234bcee 100644
--- a/scripts/copy-i18n-tags.coffee
+++ b/scripts/copy-i18n-tags.coffee
@@ -1,5 +1,16 @@
 fs = require 'fs'
+path = require 'path'
 en = require('../app/locale/en').translation
+
+en_source = fs.readFileSync(path.join(__dirname, '../app/locale/en.coffee'), encoding='utf8')
+comments_map = {}
+
+comment_pattern = /^[\s\n]*([^:\n]+):\s*"[^#\n"]+"\s*#(.*)$/gm
+
+comment = []
+while (comment = comment_pattern.exec en_source)?
+    comments_map[comment[1]] = comment[2]
+
 dir = fs.readdirSync 'app/locale'
 for file in dir when not (file in ['locale.coffee', 'en.coffee'])
   contents = require('../app/locale/' + file)
@@ -16,6 +27,9 @@ for file in dir when not (file in ['locale.coffee', 'en.coffee'])
       tagMissing = not cat[enTag]?
       tag = (cat[enTag] ?= enString)
       tag = tag.replace /"/g, '\\"'
-      lines.push "#{if tagMissing then '#' else ''}    #{enTag}: \"#{tag}\""
+      comment = ""
+      comment = " \##{comments_map[enTag]}" if comments_map[enTag]?
+
+      lines.push "#{if tagMissing then '#' else ''}    #{enTag}: \"#{tag}\"#{comment}"
   newContents = lines.join('\n') + '\n'
   fs.writeFileSync 'app/locale/' + file, newContents

From 624684f9c8d27672a5b6a4a1a6d1b459e53e9c9e Mon Sep 17 00:00:00 2001
From: David Beckley <beckl.ds@gmail.com>
Date: Fri, 19 Sep 2014 19:25:33 -0700
Subject: [PATCH 2/3] Try to conform to guidelines

---
 scripts/copy-i18n-tags.coffee | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/copy-i18n-tags.coffee b/scripts/copy-i18n-tags.coffee
index 2b234bcee..92dce432b 100644
--- a/scripts/copy-i18n-tags.coffee
+++ b/scripts/copy-i18n-tags.coffee
@@ -2,14 +2,14 @@ fs = require 'fs'
 path = require 'path'
 en = require('../app/locale/en').translation
 
-en_source = fs.readFileSync(path.join(__dirname, '../app/locale/en.coffee'), encoding='utf8')
-comments_map = {}
+enSource = fs.readFileSync(path.join(__dirname, '../app/locale/en.coffee'), encoding='utf8')
+commentsMap = {}
 
-comment_pattern = /^[\s\n]*([^:\n]+):\s*"[^#\n"]+"\s*#(.*)$/gm
+commentPattern = /^[\s\n]*([^:\n]+):\s*"[^#\n"]+"\s*#(.*)$/gm
 
 comment = []
-while (comment = comment_pattern.exec en_source)?
-    comments_map[comment[1]] = comment[2]
+while (comment = commentPattern.exec enSource)?
+  commentsMap[comment[1]] = comment[2]
 
 dir = fs.readdirSync 'app/locale'
 for file in dir when not (file in ['locale.coffee', 'en.coffee'])
@@ -28,7 +28,7 @@ for file in dir when not (file in ['locale.coffee', 'en.coffee'])
       tag = (cat[enTag] ?= enString)
       tag = tag.replace /"/g, '\\"'
       comment = ""
-      comment = " \##{comments_map[enTag]}" if comments_map[enTag]?
+      comment = " \##{commentsMap[enTag]}" if commentsMap[enTag]?
 
       lines.push "#{if tagMissing then '#' else ''}    #{enTag}: \"#{tag}\"#{comment}"
   newContents = lines.join('\n') + '\n'

From 983bb5a90c40cd084e44d3ec6d94ca06659d834a Mon Sep 17 00:00:00 2001
From: David Beckley <beckl.ds@gmail.com>
Date: Fri, 19 Sep 2014 23:05:35 -0700
Subject: [PATCH 3/3] Allow for multiple categories with the same tags

---
 scripts/copy-i18n-tags.coffee | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/scripts/copy-i18n-tags.coffee b/scripts/copy-i18n-tags.coffee
index 92dce432b..42df476ea 100644
--- a/scripts/copy-i18n-tags.coffee
+++ b/scripts/copy-i18n-tags.coffee
@@ -5,11 +5,23 @@ en = require('../app/locale/en').translation
 enSource = fs.readFileSync(path.join(__dirname, '../app/locale/en.coffee'), encoding='utf8')
 commentsMap = {}
 
+categorySplitPattern = /^[\s\n]*(?=[^:\n]+:\s*$)/gm
+categoryCapturePattern = /^[\s\n]*([^:\n]+):\s*$/gm
 commentPattern = /^[\s\n]*([^:\n]+):\s*"[^#\n"]+"\s*#(.*)$/gm
 
-comment = []
-while (comment = commentPattern.exec enSource)?
-  commentsMap[comment[1]] = comment[2]
+splitByCategories = enSource.split(categorySplitPattern)
+
+for section in splitByCategories
+  categoryMatch = categoryCapturePattern.exec section
+
+  if categoryMatch?
+    category = categoryMatch[1]
+    comment = []
+
+    commentsMap[category] ?= {}
+
+    while (comment = commentPattern.exec section)?
+      commentsMap[category][comment[1]] = comment[2]
 
 dir = fs.readdirSync 'app/locale'
 for file in dir when not (file in ['locale.coffee', 'en.coffee'])
@@ -27,8 +39,10 @@ for file in dir when not (file in ['locale.coffee', 'en.coffee'])
       tagMissing = not cat[enTag]?
       tag = (cat[enTag] ?= enString)
       tag = tag.replace /"/g, '\\"'
+
       comment = ""
-      comment = " \##{commentsMap[enTag]}" if commentsMap[enTag]?
+      if commentsMap[enCat]? and commentsMap[enCat][enTag]?
+        comment = " \##{commentsMap[enCat][enTag]}"
 
       lines.push "#{if tagMissing then '#' else ''}    #{enTag}: \"#{tag}\"#{comment}"
   newContents = lines.join('\n') + '\n'