mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 14:03:28 -04:00
Merge pull request #1580 from ThatOtherPerson/copy-comments
Fix issue #1472
This commit is contained in:
commit
bd3b5c43a5
1 changed files with 29 additions and 1 deletions
|
@ -1,5 +1,28 @@
|
|||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
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
|
||||
|
||||
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'])
|
||||
contents = require('../app/locale/' + file)
|
||||
|
@ -16,6 +39,11 @@ 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 = ""
|
||||
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'
|
||||
fs.writeFileSync 'app/locale/' + file, newContents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue