mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Linting of .tools and test
This commit is contained in:
parent
aef6bd3d59
commit
17349dcb05
19 changed files with 333 additions and 173 deletions
|
@ -8,35 +8,39 @@ const language = process.argv[2];
|
|||
|
||||
|
||||
function getTranslationPath(language){
|
||||
"use strict";
|
||||
|
||||
return path.join(__dirname, "../_locales/" + language + "/messages.json");
|
||||
}
|
||||
async function loadTranslation(language){
|
||||
"use strict";
|
||||
|
||||
const path = getTranslationPath(language);
|
||||
return await util.promisify(fs.exists)(path)
|
||||
.then(function(exists){
|
||||
if (exists){
|
||||
console.log("language exists -> load data");
|
||||
return util.promisify(fs.readFile)(path, {encoding: "UTF-8"})
|
||||
.then(function(data){
|
||||
return JSON.parse(data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log("language does not exist -> create it");
|
||||
return {};
|
||||
}
|
||||
});
|
||||
const exists = await util.promisify(fs.exists)(path);
|
||||
if (exists){
|
||||
console.log("language exists -> load data");
|
||||
const data = await util.promisify(fs.readFile)(path, {encoding: "UTF-8"});
|
||||
return JSON.parse(data);
|
||||
}
|
||||
else {
|
||||
console.log("language does not exist -> create it");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function saveTranslation(language, data){
|
||||
"use strict";
|
||||
|
||||
const path = getTranslationPath(language);
|
||||
return await util.promisify(fs.writeFile)(path, JSON.stringify(data, null, "\t"));
|
||||
}
|
||||
|
||||
async function getInput(prompt){
|
||||
return new Promise(function(resolve, reject){
|
||||
"use strict";
|
||||
|
||||
return new Promise(function(resolve){
|
||||
process.stdout.write(prompt);
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.resume();
|
||||
process.stdin.on("data", function onData(data){
|
||||
process.stdin.removeListener("data", onData);
|
||||
|
@ -47,18 +51,22 @@ async function getInput(prompt){
|
|||
}
|
||||
|
||||
async function askForTranslation(key){
|
||||
"use strict";
|
||||
|
||||
const enData = en[key];
|
||||
console.log("English translation for", key, ":", enData.message);
|
||||
if (enData.description){
|
||||
console.log("\nDescription:", enData.description);
|
||||
}
|
||||
return await getInput("Please enter translation: ");
|
||||
return getInput("Please enter translation: ");
|
||||
}
|
||||
|
||||
async function translate(language){
|
||||
"use strict";
|
||||
|
||||
const originalData = await loadTranslation(language);
|
||||
const data = {};
|
||||
for (var i = 0; i < enKeys.length; i += 1){
|
||||
for (let i = 0; i < enKeys.length; i += 1){
|
||||
const key = enKeys[i];
|
||||
const oldData = originalData[key];
|
||||
const enData = en[key];
|
||||
|
@ -76,5 +84,11 @@ async function translate(language){
|
|||
}
|
||||
|
||||
translate(language).then(function(data){
|
||||
"use strict";
|
||||
|
||||
return saveTranslation(language, data);
|
||||
}).catch(function(error){
|
||||
"use strict";
|
||||
|
||||
console.error(error);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue