description and filename changes

This commit is contained in:
ayaka 2024-04-19 21:41:02 +12:00
parent e1063f2507
commit 0d5ba93b6e

View File

@ -4,102 +4,118 @@ 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') { if (typeof options === 'function') {
cb = options; cb = options;
options = {}; options = {};
} // incase no options passed in } // incase no options passed in
https https
.get(reqUrl, (res) => { .get(reqUrl, (res) => {
let body = ''; let body = '';
res.on('data', (chunk) => { res.on('data', (chunk) => {
body += chunk; body += chunk;
}); });
res.on('end', () => { 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 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( let version = json.versions[0].id; // latest version
`Using base language "${baselang}" from version (${json.versions[0].id})`, let resources = 'https://resources.download.minecraft.net/';
); let baselang = 'en_gb';
//let filename = `${baselang} v${version} en_MSE`
let filename = `Maoist-Standard-English`;
let mcmeta_template = [
{
text: `§cen_MSE§r\n`,
},
{
text: `§8(§f${baselang}§8)-<§f${version}§8>`,
},
];
urlReq(json.versions[1].url, function (body, res) { console.log(`Using base language "${baselang}" from version (${version})`);
json = JSON.parse(body);
urlReq(json.assetIndex.url, function (body, res) { urlReq(json.versions[1].url, function (body, res) {
json = JSON.parse(body); json = JSON.parse(body);
hash = json.objects[`minecraft/lang/${baselang}.json`].hash; urlReq(json.assetIndex.url, function (body, res) {
urlReq( json = JSON.parse(body);
resources + `${hash.substring(0, 2)}/${hash}`, hash = json.objects[`minecraft/lang/${baselang}.json`].hash;
function (body, res) { urlReq(
pack = JSON.parse(body); resources + `${hash.substring(0, 2)}/${hash}`,
var totals = { function (body, res) {
total: Object.keys(pack).length, pack = JSON.parse(body);
translated: 0, var totals = {
}; total: Object.keys(pack).length,
console.log(`Translating ${totals.total} strings`); translated: 0,
Object.keys(pack).forEach(function (key) { };
var translated = MSE.translate( console.log(`Translating ${totals.total} strings`);
pack[key] Object.keys(pack).forEach(function (key) {
.replace(/\%s/gi, '%_') //mc patch var translated = MSE.translate(
.replace(/\$s/gi, '$_'), pack[key]
) .replace(/\%s/gi, '%_') //mc patch
.replace(/\%_/gi, '%s') //mc patch back .replace(/\$s/gi, '$_'),
.replace(/\$_/gi, '$s'); )
if (translated != pack[key]) { .replace(/\%_/gi, '%s') //mc patch back
totals.translated = totals.translated + 1; .replace(/\$_/gi, '$s');
} if (translated != pack[key]) {
pack[key] = translated; totals.translated = totals.translated + 1;
}); }
console.log( pack[key] = translated;
`Translated ${totals.translated} out of ${totals.total} strings`, });
); console.log(
fs.writeFile( `Translated ${totals.translated} out of ${totals.total} strings`,
__dirname + );
'/template/assets/minecraft/lang/en_mse.json',
JSON.stringify(pack, null, 4), var mcmeta = __dirname + '/template/pack.mcmeta';
'utf8', var mcmeta_data = JSON.parse(fs.readFileSync(mcmeta));
function (err) { mcmeta_data.pack.description = mcmeta_template;
if (err) throw err;
console.log( fs.writeFileSync(mcmeta, JSON.stringify(mcmeta_data));
'en_mse.json generated, creating pack and compressing.', fs.writeFile(
); __dirname + '/template/assets/minecraft/lang/en_mse.json',
const output = fs.createWriteStream( JSON.stringify(pack, null, 4),
__dirname + '/Maoist-Standard-English.zip', 'utf8',
); function (err) {
const archive = archiver('zip', { if (err) throw err;
zlib: { level: 9 }, // Sets the compression level. console.log(
}); 'en_mse.json generated, creating pack and compressing.',
archive.on('error', function (err) { );
throw err; const output = fs.createWriteStream(
}); __dirname + `/${filename}.zip`,
output.on('close', function () { );
console.log( const archive = archiver('zip', {
'language-pack archive generated with a filesize of ' + zlib: { level: 9 }, // Sets the compression level.
archive.pointer() + });
' bytes', archive.on('error', function (err) {
); throw err;
}); });
archive.pipe(output); output.on('close', function () {
archive.directory('template/', false); console.log(
archive.finalize(); 'language-pack archive generated with a filesize of ' +
}, archive.pointer() +
); ' bytes' +
}, `\n(./${filename}.zip)`,
); );
}); });
archive.pipe(output);
archive.directory('template/', false);
archive.finalize();
},
);
},
);
}); });
});
}); });