Commit 2ef052ae authored by Víctor Gallego Fontenla's avatar Víctor Gallego Fontenla 🏉

Updated prints

parent e77f9f2a
const PO = require('pofile')
const util = require('util')
const input = require('readline-sync')
const Chalk = require('chalk')
const Inquirer = require('inquirer')
const Program = require('commander')
const parser = util.promisify(PO.load)
console.clear = () => process.stdout.write('\033c')
async function processFile(file) {
console.clear()
const { language } = await Inquirer.prompt({type: 'input', name: 'language', message: 'Translation language? '})
console.clear()
console.log(Chalk.green.bold(`You are about to translate ${Chalk.keyword('orange').bold.underline(file)} to ${Chalk.keyword('orange').bold.underline(language)}...`))
console.log()
const { proceed } = await Inquirer.prompt({type: 'confirm', name: 'proceed', message: 'Do you want to continue? '})
if(!proceed){
console.clear()
return
}
const content = await parser(file)
const strings = content.items
for(item of strings){
if(item.msgstr[0].trim() === ""){
process.stdout.write('\033c')
console.clear()
console.log(`Translating file ${file}`)
console.log(Chalk.green.bold(`Translating file ${Chalk.keyword('orange').bold.underline(file)}`))
console.log()
console.log('***************************************************************')
console.log(`- Message ID * ${item.msgid}`)
console.log(`- Context * ${item.msgctxt}`)
console.log('***************************************************************')
console.log()
const translation = input.question("Translation: ")
console.log(`${Chalk.blue.bold.underline('Message ID:')} ${Chalk.whiteBright.bold.italic(item.msgid)}`)
console.log(`${Chalk.blue.bold.underline('Context:')} ${Chalk.whiteBright.bold.italic(item.msgctxt)}`)
console.log()
console.log()
const { translation } = await Inquirer.prompt({type: 'input', name: 'translation', message: 'Translation:'})
//TODO check spelling
item.msgstr[0] = translation
process.stdout.write('\033c')
console.clear()
console.log("Continue translation?")
console.log()
console.log("If you want to save now, write 'save' or 's'.")
console.log("If you want to continue translating without saving write 'next' or 'n'")
console.log("If you want to save and exit write 'quit' or 'q'")
console.log("If you want to exit without saving write 'discard' or 'd'")
console.log()
const option = input.question("What do you want to do? ")
const { option } = await Inquirer.prompt({type: 'rawlist', message:"Continue translation?", name: 'option', choices: [
"1> Continue without saving",
"2> Save and continue",
"3> Save and exit",
"4> Discard changes and exit"
], default: 1})
switch(option[0]){
case 's':
content.save(`${file}`)
case '1':
break
case '2':
await content.save(`${file}`)
break
case 'q':
content.save(`${file}`)
case '3':
await content.save(`${file}`)
return
case 'd':
case '4':
return
}
}
}
console.log("All translations done!")
console.log()
let option2
while(option2 !== 'q' && option2 !== 'd'){
console.log(Chalk.green.bold.underline("All translations done!"))
const { save } = await Inquirer.prompt({type: 'confirm', name: 'save', message: 'Do you want to save the file before closing the aplication?'})
console.log("If you want to save and exit write 'quit' or 'q'")
console.log("If you want to exit without saving write 'discard' or 'd'")
console.log()
option2 = input.question("What do you want to do? ")
if(save)
await content.save(`${file}`)
switch(option2[0]){
case 'q':
content.save(`${file}`)
return
case 'd':
return
default:
console.log("Unrecognized option")
}
}
}
processFile(process.argv[2])
Program.version('0.1.1')
.usage('[options] <input file>')
.option('-o, --output [file]', 'Output file (.po). If not specified, it will replace the original file on save.')
.parse(process.argv)
const [inputFile] = Program.args
processFile(inputFile)
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -9,11 +9,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"hunspell-spellcheck": "0.0.4",
"pofile": "^1.0.10",
"readline-sync": "^1.4.8",
"spellchecker": "^3.4.4",
"teacher": "^0.1.0",
"typo-js": "^1.0.3"
"api-npm": "^1.0.0",
"chalk": "^2.3.0",
"commander": "^2.14.1",
"inquirer": "^5.1.0",
"npm": "^5.6.0",
"nspell": "^1.0.5",
"pofile": "^1.0.10"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment