formatting
This commit is contained in:
parent
62dd77a1d0
commit
e1063f2507
115
packgen.js
115
packgen.js
@ -1,76 +1,105 @@
|
|||||||
const MSE = require("mse-translator")
|
const MSE = require('mse-translator');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const archiver = require('archiver');
|
const archiver = require('archiver');
|
||||||
|
|
||||||
const urlReq = function (reqUrl, options, cb) {
|
const urlReq = function (reqUrl, options, cb) {
|
||||||
if(typeof options === "function"){ cb = options; options = {}; }// incase no options passed in
|
if (typeof options === 'function') {
|
||||||
https.get(reqUrl,(res) => {
|
cb = options;
|
||||||
let body = "";
|
options = {};
|
||||||
res.on("data", (chunk) => {body += chunk;});
|
} // incase no options passed in
|
||||||
res.on("end", () => {
|
https
|
||||||
|
.get(reqUrl, (res) => {
|
||||||
|
let body = '';
|
||||||
|
res.on('data', (chunk) => {
|
||||||
|
body += chunk;
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
try {
|
try {
|
||||||
cb(body, res);
|
cb(body, res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
}).on("error", (error) => {
|
})
|
||||||
|
.on('error', (error) => {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let piston = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json';
|
||||||
|
let resources = 'https://resources.download.minecraft.net/';
|
||||||
|
let baselang = 'en_gb';
|
||||||
|
|
||||||
let piston = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
|
|
||||||
let resources = "https://resources.download.minecraft.net/"
|
|
||||||
let baselang = "en_gb"
|
|
||||||
urlReq(piston, function (body, res) {
|
urlReq(piston, function (body, res) {
|
||||||
json = JSON.parse(body)
|
json = JSON.parse(body);
|
||||||
console.log(`Using base language "${baselang}" from version (${json.versions[0].id})`)
|
console.log(
|
||||||
|
`Using base language "${baselang}" from version (${json.versions[0].id})`,
|
||||||
|
);
|
||||||
|
|
||||||
urlReq(json.versions[1].url, function (body, res) {
|
urlReq(json.versions[1].url, function (body, res) {
|
||||||
json = JSON.parse(body)
|
json = JSON.parse(body);
|
||||||
//console.log(json.assetIndex)
|
|
||||||
|
|
||||||
urlReq(json.assetIndex.url, function (body, res) {
|
urlReq(json.assetIndex.url, function (body, res) {
|
||||||
json = JSON.parse(body)
|
json = JSON.parse(body);
|
||||||
hash = json.objects[`minecraft/lang/${baselang}.json`].hash
|
hash = json.objects[`minecraft/lang/${baselang}.json`].hash;
|
||||||
urlReq(resources+`${hash.substring(0,2)}/${hash}`, function(body, res){
|
urlReq(
|
||||||
pack = JSON.parse(body)
|
resources + `${hash.substring(0, 2)}/${hash}`,
|
||||||
//console.log(body.substring(0,200))
|
function (body, res) {
|
||||||
var totals = {total:Object.keys(pack).length,translated:0}
|
pack = JSON.parse(body);
|
||||||
console.log(`Translating ${totals.total} strings`)
|
var totals = {
|
||||||
|
total: Object.keys(pack).length,
|
||||||
|
translated: 0,
|
||||||
|
};
|
||||||
|
console.log(`Translating ${totals.total} strings`);
|
||||||
Object.keys(pack).forEach(function (key) {
|
Object.keys(pack).forEach(function (key) {
|
||||||
var translated = MSE.translate(
|
var translated = MSE.translate(
|
||||||
pack[key]
|
pack[key]
|
||||||
.replace(/\%s/gi, "%_") //mc patch
|
.replace(/\%s/gi, '%_') //mc patch
|
||||||
.replace(/\$s/gi, "$_")
|
.replace(/\$s/gi, '$_'),
|
||||||
)
|
)
|
||||||
.replace(/\%_/gi, "%s") //mc patch back
|
.replace(/\%_/gi, '%s') //mc patch back
|
||||||
.replace(/\$_/gi, "$s")
|
.replace(/\$_/gi, '$s');
|
||||||
if (translated != pack[key]) {totals.translated = totals.translated+1}
|
if (translated != pack[key]) {
|
||||||
pack[key] = translated
|
totals.translated = totals.translated + 1;
|
||||||
|
}
|
||||||
|
pack[key] = translated;
|
||||||
});
|
});
|
||||||
console.log(`Translated ${totals.translated} out of ${totals.total} strings`)
|
console.log(
|
||||||
//console.log(pack)
|
`Translated ${totals.translated} out of ${totals.total} strings`,
|
||||||
//fs.writeFile('myjsonfile.json', JSON.stringify(pack), 'utf8');
|
);
|
||||||
fs.writeFile (__dirname + "/template/assets/minecraft/lang/en_mse.json", JSON.stringify(pack,null,4), 'utf8',function(err) {
|
fs.writeFile(
|
||||||
|
__dirname +
|
||||||
|
'/template/assets/minecraft/lang/en_mse.json',
|
||||||
|
JSON.stringify(pack, null, 4),
|
||||||
|
'utf8',
|
||||||
|
function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('en_mse.json generated, creating pack and compressing.');
|
console.log(
|
||||||
const output = fs.createWriteStream(__dirname + '/Maoist-Standard-English.zip');
|
'en_mse.json generated, creating pack and compressing.',
|
||||||
|
);
|
||||||
|
const output = fs.createWriteStream(
|
||||||
|
__dirname + '/Maoist-Standard-English.zip',
|
||||||
|
);
|
||||||
const archive = archiver('zip', {
|
const archive = archiver('zip', {
|
||||||
zlib: { level: 9 } // Sets the compression level.
|
zlib: { level: 9 }, // Sets the compression level.
|
||||||
|
});
|
||||||
|
archive.on('error', function (err) {
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
archive.on('error', function(err) {throw err;});
|
|
||||||
output.on('close', function () {
|
output.on('close', function () {
|
||||||
console.log("language-pack archive generated with a filesize of " + archive.pointer() + ' bytes');
|
console.log(
|
||||||
|
'language-pack archive generated with a filesize of ' +
|
||||||
|
archive.pointer() +
|
||||||
|
' bytes',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
archive.pipe(output);
|
archive.pipe(output);
|
||||||
archive.directory('template/', false);
|
archive.directory('template/', false);
|
||||||
archive.finalize();
|
archive.finalize();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user