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

Updated prints

parent e77f9f2a
const PO = require('pofile') const PO = require('pofile')
const util = require('util') 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) const parser = util.promisify(PO.load)
console.clear = () => process.stdout.write('\033c')
async function processFile(file) { 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 content = await parser(file)
const strings = content.items const strings = content.items
for(item of strings){ for(item of strings){
if(item.msgstr[0].trim() === ""){ 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('***************************************************************')
console.log(`- Message ID * ${item.msgid}`)
console.log(`- Context * ${item.msgctxt}`)
console.log('***************************************************************')
console.log() console.log()
const translation = input.question("Translation: ") console.log(`${Chalk.blue.bold.underline('Message ID:')} ${Chalk.whiteBright.bold.italic(item.msgid)}`)
item.msgstr[0] = translation console.log(`${Chalk.blue.bold.underline('Context:')} ${Chalk.whiteBright.bold.italic(item.msgctxt)}`)
process.stdout.write('\033c')
console.log("Continue translation?")
console.log() 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() console.log()
const option = input.question("What do you want to do? ")
const { translation } = await Inquirer.prompt({type: 'input', name: 'translation', message: 'Translation:'})
//TODO check spelling
item.msgstr[0] = translation
console.clear()
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]){ switch(option[0]){
case 's': case '1':
content.save(`${file}`)
break break
case 'q': case '2':
content.save(`${file}`) await content.save(`${file}`)
break
case '3':
await content.save(`${file}`)
return return
case 'd': case '4':
return return
} }
} }
} }
console.log("All translations done!") console.log(Chalk.green.bold.underline("All translations done!"))
console.log() const { save } = await Inquirer.prompt({type: 'confirm', name: 'save', message: 'Do you want to save the file before closing the aplication?'})
let option2 if(save)
while(option2 !== 'q' && option2 !== 'd'){ await content.save(`${file}`)
console.log("If you want to save and exit write 'quit' or 'q'") return
console.log("If you want to exit without saving write 'discard' or 'd'")
console.log()
option2 = input.question("What do you want to do? ")
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 @@ ...@@ -9,11 +9,12 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"hunspell-spellcheck": "0.0.4", "api-npm": "^1.0.0",
"pofile": "^1.0.10", "chalk": "^2.3.0",
"readline-sync": "^1.4.8", "commander": "^2.14.1",
"spellchecker": "^3.4.4", "inquirer": "^5.1.0",
"teacher": "^0.1.0", "npm": "^5.6.0",
"typo-js": "^1.0.3" "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