Skip to content

Commit

Permalink
fix translator not write file
Browse files Browse the repository at this point in the history
  • Loading branch information
moeiscool committed Jul 18, 2017
1 parent 83f7dd3 commit 36aa398
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions tools/translateLanguageFile.js
Expand Up @@ -13,10 +13,9 @@ var jsonfile=require('jsonfile');
var source=require(langDir+process.argv[2]+'.json')
var list = Object.keys(source)
console.log(list.length)
var stop = 0
var extra = ''
if(process.argv[4]==='he'){process.argv[4]=='ar'}
var current = 0
var current = 1
var currentItem = list[0]
var chosenFile = langDir+process.argv[4]+'.json'
try{
Expand All @@ -29,18 +28,28 @@ var newListAlphabetical={}
var goNext=function(){
++current
currentItem = list[current]
next(currentItem)
if(list.length===current){
console.log('complete checking.. please wait')
Object.keys(newList).sort().forEach(function(y,t){
newListAlphabetical[y]=newList[y]
})
jsonfile.writeFile(chosenFile,newListAlphabetical,{spaces: 2},function(){
console.log('complete writing')
})
}else{
next(currentItem)
}
}
var next=function(v){
if(v===undefined){return false}
if(/<[a-z][\s\S]*>/i.test(source[v])===true){
extra+='&format=html'
}
//trnsl.1.1.20170718T033617Z.a9bbd3b739ca59df.7f89b7474ec69812afd0014b5e338328ebf3fc39
if(newList[v]&&newList[v]!==source[v]){
goNext()
return
}
if(/<[a-z][\s\S]*>/i.test(source[v])===true){
extra+='&format=html'
}
var url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20160311T042953Z.341f2f63f38bdac6.c7e5c01fff7f57160141021ca61b60e36ff4d379'+extra+'&lang='+process.argv[3]+'-'+process.argv[4]+'&text='+source[v]
https.request(url, function(data) {
data.setEncoding('utf8');
Expand All @@ -65,19 +74,8 @@ var next=function(v){
var translation=source[v]
}
newList[v]=translation;
console.log(current+','+v+' ---> '+translation)
if(list.length===current){
stop=1
console.log('complete checking.. please wait')
Object.keys(newList).sort().forEach(function(y,t){
newListAlphabetical[y]=newList[y]
})
jsonfile.writeFile(chosenFile,newListAlphabetical,{spaces: 2},function(){
console.log('complete writing')
})
}else{
goNext()
}
console.log(current+'/'+list.length+','+v+' ---> '+translation)
goNext()
});
}).on('error', function(e) {
console.log('ERROR : 500 '+v)
Expand Down

0 comments on commit 36aa398

Please sign in to comment.