mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-27 21:31:16 -04:00
Allow for multiple categories with the same tags
This commit is contained in:
parent
624684f9c8
commit
983bb5a90c
1 changed files with 18 additions and 4 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Reference in a new issue