Skip to content

Instantly share code, notes, and snippets.

@cyrilis
Created November 5, 2014 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyrilis/393c90ede85c7a9c7736 to your computer and use it in GitHub Desktop.
Save cyrilis/393c90ede85c7a9c7736 to your computer and use it in GitHub Desktop.
Check lang source in nls/lang
fs = require("fs")
path = require('path');
findit = require('findit');
LineByLineReader = require('line-by-line');
langFile = require("../h5-ide/src/nls/en-us/lang")
basePath = path.resolve __dirname, "../h5-ide/src"
# Find all files in h5-ide/src
bindFinder = ()->
finder = findit(basePath)
finder.on 'directory', (dir, stat, stop) ->
base = path.basename(dir);
if (base == '.git' || base == 'node_modules') then stop()
console.log "Dive into directory ==========>",path.resolve(basePath, dir)
finder.on 'file', (file, stat) ->
# if path.extname(file) isnt ".coffee"
# return false
getLangSource(file)
getLangSource = (filePath)->
lr = new LineByLineReader(filePath,{encoding: 'utf8',skipEmptyLines: true});
coffeeReg = /lang\.(\w+\.[^\,\.\;\{\}\(\)\s\]\[]+)/g
templateReg = /{{\s*i18n\s*(?=['"]([^{}]*)['"])/g
getMatches = (string, regex, index) ->
index || (index = 1);
matches = [];
match;
while (match = regex.exec(string))
matches.push(match[index])
return matches
lr.on 'error', (error)->
console.error error
return false
lr.on 'line', (line)->
coffeeMatchs = getMatches(line, coffeeReg, 1)
if coffeeMatchs.length
coffeeMatchs.forEach (e)->
stringArray = e.split(".")
if stringArray.length <= 1
stringArray.unshift("IDE")
if not langFile[stringArray[0]][stringArray[1]]
console.error "COFFEE --------->",e, lr._filepath
templateMatches = getMatches(line, templateReg,1)
if templateMatches.length
templateMatches.forEach (e)->
stringArray = e.split(".")
if stringArray.length <= 1
stringArray.unshift("IDE")
if not langFile[stringArray[0]][stringArray[1]]
console.error "TEMPLATE =======>",e, lr._filepath
lr.on 'end', ->
bindFinder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment