Compare commits
5 Commits
1.0.0
...
90696663ff
Author | SHA1 | Date | |
---|---|---|---|
90696663ff | |||
8c13826943 | |||
0d5ba93b6e | |||
e1063f2507 | |||
62dd77a1d0 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -131,4 +131,5 @@ dist
|
||||
.pnp.*
|
||||
|
||||
# MSE chicanery
|
||||
Maoist-Standard-English.zip
|
||||
Maoist-Standard-English.zip
|
||||
template/assets/minecraft/lang/en_mse.json
|
21
.prettierrc
Normal file
21
.prettierrc
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"arrowParens": "always",
|
||||
"bracketSameLine": false,
|
||||
"bracketSpacing": true,
|
||||
"semi": true,
|
||||
"experimentalTernaries": false,
|
||||
"singleQuote": false,
|
||||
"jsxSingleQuote": false,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"singleAttributePerLine": false,
|
||||
"htmlWhitespaceSensitivity": "css",
|
||||
"vueIndentScriptAndStyle": false,
|
||||
"proseWrap": "preserve",
|
||||
"insertPragma": false,
|
||||
"printWidth": 80,
|
||||
"requirePragma": false,
|
||||
"tabWidth": 4,
|
||||
"useTabs": false,
|
||||
"embeddedLanguageFormatting": "auto"
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"main": "packgen.js",
|
||||
"dependencies": {
|
||||
"archiver": "^7.0.1",
|
||||
"mse-translator": "https://git.stardust.wtf/iridium/MSE-Translator.git"
|
||||
|
182
packgen.js
182
packgen.js
@ -1,76 +1,122 @@
|
||||
const MSE = require("mse-translator")
|
||||
const MSE = require('mse-translator');
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const archiver = require('archiver');
|
||||
|
||||
const urlReq = function(reqUrl, options, cb){
|
||||
if(typeof options === "function"){ cb = options; options = {}; }// incase no options passed in
|
||||
https.get(reqUrl,(res) => {
|
||||
let body = "";
|
||||
res.on("data", (chunk) => {body += chunk;});
|
||||
res.on("end", () => {
|
||||
try {
|
||||
cb(body, res);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
};
|
||||
});
|
||||
}).on("error", (error) => {
|
||||
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"
|
||||
urlReq(piston, function(body, res){
|
||||
json = JSON.parse(body)
|
||||
console.log(`Using base language "${baselang}" from version (${json.versions[0].id})`)
|
||||
|
||||
urlReq(json.versions[1].url, function(body, res){
|
||||
json = JSON.parse(body)
|
||||
//console.log(json.assetIndex)
|
||||
|
||||
urlReq(json.assetIndex.url, function(body, res){
|
||||
json = JSON.parse(body)
|
||||
hash = json.objects[`minecraft/lang/${baselang}.json`].hash
|
||||
urlReq(resources+`${hash.substring(0,2)}/${hash}`, function(body, res){
|
||||
pack = JSON.parse(body)
|
||||
//console.log(body.substring(0,200))
|
||||
var totals = {total:Object.keys(pack).length,translated:0}
|
||||
console.log(`Translating ${totals.total} strings`)
|
||||
Object.keys(pack).forEach(function(key){
|
||||
var translated = MSE.translate(
|
||||
pack[key]
|
||||
.replace(/\%s/gi, "%_") //mc patch
|
||||
.replace(/\$s/gi, "$_")
|
||||
)
|
||||
.replace(/\%_/gi, "%s") //mc patch back
|
||||
.replace(/\$_/gi, "$s")
|
||||
if (translated != pack[key]) {totals.translated = totals.translated+1}
|
||||
pack[key] = translated
|
||||
});
|
||||
console.log(`Translated ${totals.translated} out of ${totals.total} strings`)
|
||||
//console.log(pack)
|
||||
//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) {
|
||||
if (err) throw err;
|
||||
console.log('en_mse.json generated, creating pack and compressing.');
|
||||
const output = fs.createWriteStream(__dirname + '/Maoist-Standard-English.zip');
|
||||
const archive = archiver('zip', {
|
||||
zlib: { level: 9 } // Sets the compression level.
|
||||
});
|
||||
archive.on('error', function(err) {throw err;});
|
||||
output.on('close', function() {
|
||||
console.log("language-pack archive generated with a filesize of " + archive.pointer() + ' bytes');
|
||||
});
|
||||
archive.pipe(output);
|
||||
archive.directory('template/', false);
|
||||
archive.finalize();
|
||||
});
|
||||
const urlReq = function (reqUrl, options, cb) {
|
||||
if (typeof options === 'function') {
|
||||
cb = options;
|
||||
options = {};
|
||||
} // incase no options passed in
|
||||
https
|
||||
.get(reqUrl, (res) => {
|
||||
let body = '';
|
||||
res.on('data', (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
cb(body, res);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('error', (error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
};
|
||||
|
||||
let piston = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json';
|
||||
|
||||
urlReq(piston, function (body, res) {
|
||||
json = JSON.parse(body);
|
||||
let version = json.versions[0].id; // latest version
|
||||
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>`,
|
||||
},
|
||||
];
|
||||
|
||||
console.log(`Using base language "${baselang}" from version (${version})`);
|
||||
|
||||
urlReq(json.versions[1].url, function (body, res) {
|
||||
json = JSON.parse(body);
|
||||
urlReq(json.assetIndex.url, function (body, res) {
|
||||
json = JSON.parse(body);
|
||||
hash = json.objects[`minecraft/lang/${baselang}.json`].hash;
|
||||
urlReq(
|
||||
resources + `${hash.substring(0, 2)}/${hash}`,
|
||||
function (body, res) {
|
||||
pack = JSON.parse(body);
|
||||
var totals = {
|
||||
total: Object.keys(pack).length,
|
||||
translated: 0,
|
||||
};
|
||||
console.log(`Translating ${totals.total} strings`);
|
||||
Object.keys(pack).forEach(function (key) {
|
||||
var translated = MSE.translate(
|
||||
pack[key]
|
||||
.replace(/\%s/gi, '%_') //mc patch
|
||||
.replace(/\$s/gi, '$_'),
|
||||
)
|
||||
.replace(/\%_/gi, '%s') //mc patch back
|
||||
.replace(/\$_/gi, '$s');
|
||||
if (translated != pack[key]) {
|
||||
totals.translated = totals.translated + 1;
|
||||
}
|
||||
pack[key] = translated;
|
||||
});
|
||||
console.log(
|
||||
`Translated ${totals.translated} out of ${totals.total} strings`,
|
||||
);
|
||||
|
||||
var mcmeta = __dirname + '/template/pack.mcmeta';
|
||||
var mcmeta_data = JSON.parse(fs.readFileSync(mcmeta));
|
||||
mcmeta_data.pack.description = mcmeta_template;
|
||||
|
||||
fs.writeFileSync(mcmeta, JSON.stringify(mcmeta_data));
|
||||
fs.writeFile(
|
||||
__dirname +
|
||||
'/template/assets/minecraft/lang/en_mse.json',
|
||||
JSON.stringify(pack, null, 4),
|
||||
'utf8',
|
||||
function (err) {
|
||||
if (err) throw err;
|
||||
console.log(
|
||||
'en_mse.json generated, creating pack and compressing.',
|
||||
);
|
||||
const output = fs.createWriteStream(
|
||||
__dirname + `/${filename}.zip`,
|
||||
);
|
||||
const archive = archiver('zip', {
|
||||
zlib: { level: 9 }, // Sets the compression level.
|
||||
});
|
||||
archive.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
output.on('close', function () {
|
||||
console.log(
|
||||
'language-pack archive generated with a filesize of ' +
|
||||
archive.pointer() +
|
||||
' bytes' +
|
||||
`\n(./${filename}.zip)`,
|
||||
);
|
||||
});
|
||||
archive.pipe(output);
|
||||
archive.directory('template/', false);
|
||||
archive.finalize();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
1
template/assets/minecraft/lang/.dir
Normal file
1
template/assets/minecraft/lang/.dir
Normal file
@ -0,0 +1 @@
|
||||
Language Directory
|
14
template/pack.mcmeta
Normal file
14
template/pack.mcmeta
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 5,
|
||||
"description": "en_MSE"
|
||||
},
|
||||
"language": {
|
||||
"en_mse": {
|
||||
"name": "Maoist standard English",
|
||||
"region": "Maoism–Third Worldism",
|
||||
"bidirectional": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
template/pack.png
Normal file
BIN
template/pack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user