generated from nea89o/Forge1.8.9Template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
category-localizer.js
78 lines (69 loc) · 2.85 KB
/
category-localizer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* This file is part of Resourcify
* Copyright (C) 2024 DeDiamondPro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License Version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const https = require('https');
function capitalizeWords(str) {
return str.replace(/(\b[a-z])/g, match => match.toUpperCase());
}
function fetchData(url, headers = {}) {
return new Promise((resolve, reject) => {
https.get(url, { headers }, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
resolve(JSON.parse(data));
});
res.on('error', (err) => {
reject(err);
});
});
});
}
async function fetchAndProcessData() {
const modrinthData = await fetchData('https://api.modrinth.com/v2/tag/category');
const modrinthIndexes = [];
modrinthData.forEach(item => {
if (!["resourcepack", "shader", "mod"].includes(item.project_type)) return;
let header = `"resourcify.categories.${item.header.toLowerCase().replaceAll(" ", "_")}": "${capitalizeWords(item.header)}",`;
if (!modrinthIndexes.includes(header)) {
modrinthIndexes.push(header);
}
let category = `"resourcify.categories.${item.name.toLowerCase().replaceAll(" ", "_")}": "${capitalizeWords(item.name)}",`
if(!modrinthIndexes.includes(category)) {
modrinthIndexes.push(category);
}
});
console.log(`Modrinth (${modrinthIndexes.length}):`);
modrinthIndexes.forEach(localization => {
console.log(` ${localization}`);
});
const curseForgeData = await fetchData('https://api.curseforge.com/v1/categories?gameId=432', {'x-api-key': 'cf-api-key'});
const translationIndexes = [];
curseForgeData.data.forEach(item => {
if (![12, 17, 6552].includes(item.classId)) return;
let category = `"resourcify.categories.${item.name.toLowerCase().replaceAll(" ", "_")}": "${capitalizeWords(item.name)}",`
if (!translationIndexes.includes(category) && !modrinthIndexes.includes(category)) {
translationIndexes.push(category);
}
});
console.log(`CurseForge (${translationIndexes.length}):`);
translationIndexes.forEach(localization => {
console.log(` ${localization}`);
});
}
fetchAndProcessData();