Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations + Convert to ESM #32

Merged
merged 40 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5eef912
Create access_token.json
ImpulseDevMomentum Jul 1, 2024
b8c813a
Create channel_update_types.json
ImpulseDevMomentum Jul 1, 2024
29abfbe
Create emoji_update_types.json
ImpulseDevMomentum Jul 1, 2024
b9c698c
Create ignore_options.json
ImpulseDevMomentum Jul 1, 2024
fa88766
Create log_categories.json
ImpulseDevMomentum Jul 1, 2024
df4d273
Create log_formats.json
ImpulseDevMomentum Jul 1, 2024
7e82534
Create dashboard.json
ImpulseDevMomentum Jul 1, 2024
60ecfd6
Create initialReactor.json
ImpulseDevMomentum Jul 1, 2024
8e59f2d
Create premium.json
ImpulseDevMomentum Jul 1, 2024
ff8ce90
Create quarkEvents.json
ImpulseDevMomentum Jul 1, 2024
e5c9316
Create time.json
ImpulseDevMomentum Jul 1, 2024
c65bee7
Update command_responses.json
ImpulseDevMomentum Jul 1, 2024
116eda0
Update gui_constants.json
ImpulseDevMomentum Jul 1, 2024
dfe4d55
Update channelEvents.json
ImpulseDevMomentum Jul 1, 2024
f4fc1d5
Update generalEvents.json
ImpulseDevMomentum Jul 1, 2024
489999c
Update modlog.json
ImpulseDevMomentum Jul 1, 2024
3317372
Update serverActions.json
ImpulseDevMomentum Jul 1, 2024
294eb86
Update voiceEvents.json
ImpulseDevMomentum Jul 1, 2024
caaea21
Merge pull request #28 from ayyneya/main
thatkev Jul 3, 2024
181b833
Merge pull request #27 from lis0ownik/patch-19
thatkev Jul 3, 2024
4be4a20
Merge pull request #26 from lis0ownik/patch-18
thatkev Jul 3, 2024
e381461
Merge pull request #25 from lis0ownik/patch-17
thatkev Jul 3, 2024
0a1b3de
Merge pull request #24 from lis0ownik/patch-22
thatkev Jul 3, 2024
1fa6d97
Merge pull request #23 from lis0ownik/patch-21
thatkev Jul 3, 2024
bee5f9c
Merge pull request #22 from lis0ownik/patch-20
thatkev Jul 3, 2024
2dec1f2
Merge pull request #21 from lis0ownik/patch-7
thatkev Jul 3, 2024
ed04677
Merge pull request #20 from lis0ownik/patch-6
thatkev Jul 3, 2024
8bff4fb
Merge pull request #19 from lis0ownik/patch-5
thatkev Jul 3, 2024
c79f40a
Merge pull request #18 from lis0ownik/patch-10
thatkev Jul 3, 2024
abdfe9e
Merge pull request #17 from lis0ownik/patch-9
thatkev Jul 3, 2024
5ba2086
Merge pull request #16 from lis0ownik/patch-8
thatkev Jul 3, 2024
445ec0a
Merge pull request #15 from lis0ownik/patch-16
thatkev Jul 3, 2024
06e7887
Merge pull request #14 from lis0ownik/patch-15
thatkev Jul 3, 2024
c7d041a
Merge pull request #13 from lis0ownik/patch-11
thatkev Jul 3, 2024
3f38ca5
Merge pull request #12 from lis0ownik/patch-12
thatkev Jul 3, 2024
ef73ab3
Merge pull request #11 from lis0ownik/patch-13
thatkev Jul 3, 2024
472f0f0
Merge pull request #10 from lis0ownik/patch-14
thatkev Jul 3, 2024
59779bf
convert to ESM
Starman3787 Sep 14, 2024
af86b40
convert scripts to esm
Starman3787 Sep 14, 2024
e9bca56
Merge branch 'main' into development
Starman3787 Sep 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 75 additions & 57 deletions .github/scripts/compare-languages.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,92 @@
const fs = require('fs');
const path = require('path');
import { readFileSync, readdirSync, statSync } from "fs";
import { join, relative } from "path";

function readJson(filePath) {
const rawData = fs.readFileSync(filePath, 'utf8');
return JSON.parse(rawData);
const rawData = readFileSync(filePath, "utf8");
return JSON.parse(rawData);
}

function getAllJsonFiles(directory) {
let jsonFiles = [];
const files = fs.readdirSync(directory);

files.forEach(file => {
const fullPath = path.join(directory, file);
if (fs.statSync(fullPath).isDirectory()) {
jsonFiles = jsonFiles.concat(getAllJsonFiles(fullPath));
} else if (file.endsWith('.json')) {
jsonFiles.push(fullPath);
}
});

return jsonFiles;
let jsonFiles = [];
const files = readdirSync(directory);

files.forEach((file) => {
const fullPath = join(directory, file);
if (statSync(fullPath).isDirectory()) {
jsonFiles = jsonFiles.concat(getAllJsonFiles(fullPath));
} else if (file.endsWith(".json")) {
jsonFiles.push(fullPath);
}
});

return jsonFiles;
}

function compareJsonFiles(enUsDir, otherLangDir) {
const enUsFiles = getAllJsonFiles(enUsDir);
const otherLangFiles = getAllJsonFiles(otherLangDir);

const enUsFilesRelative = enUsFiles.map(file => path.relative(enUsDir, file));
const otherLangFilesRelative = otherLangFiles.map(file => path.relative(otherLangDir, file));

const missingFiles = enUsFilesRelative.filter(file => !otherLangFilesRelative.includes(file));

const missingKeys = {};

enUsFilesRelative.forEach(file => {
if (otherLangFilesRelative.includes(file)) {
const enUsJson = readJson(path.join(enUsDir, file));
const otherLangJson = readJson(path.join(otherLangDir, file));

const missingKeysInFile = Object.keys(enUsJson).filter(key => !otherLangJson.hasOwnProperty(key));
if (missingKeysInFile.length > 0) {
missingKeys[file] = missingKeysInFile;
}
}
});

return { missingFiles, missingKeys };
const enUsFiles = getAllJsonFiles(enUsDir);
const otherLangFiles = getAllJsonFiles(otherLangDir);

const enUsFilesRelative = enUsFiles.map((file) => relative(enUsDir, file));
const otherLangFilesRelative = otherLangFiles.map((file) =>
relative(otherLangDir, file)
);

const missingFiles = enUsFilesRelative.filter(
(file) => !otherLangFilesRelative.includes(file)
);

const missingKeys = {};

enUsFilesRelative.forEach((file) => {
if (otherLangFilesRelative.includes(file)) {
const enUsJson = readJson(join(enUsDir, file));
const otherLangJson = readJson(join(otherLangDir, file));

const missingKeysInFile = Object.keys(enUsJson).filter(
(key) => !otherLangJson.hasOwnProperty(key)
);
if (missingKeysInFile.length > 0) {
missingKeys[file] = missingKeysInFile;
}
}
});

return { missingFiles, missingKeys };
}

function compareAllLanguages(baseDir) {
const enUsDir = path.join(baseDir, 'en_us');
const languages = fs.readdirSync(baseDir).filter(dir => fs.statSync(path.join(baseDir, dir)).isDirectory() && dir !== 'en_us');

const report = {};

languages.forEach(lang => {
const langDir = path.join(baseDir, lang);
const { missingFiles, missingKeys } = compareJsonFiles(enUsDir, langDir);
report[lang] = { missingFiles, missingKeys };
});

return report;
const enUsDir = join(baseDir, "en_us");
const languages = readdirSync(baseDir).filter(
(dir) => statSync(join(baseDir, dir)).isDirectory() && dir !== "en_us"
);

const report = {};

languages.forEach((lang) => {
const langDir = join(baseDir, lang);
const { missingFiles, missingKeys } = compareJsonFiles(enUsDir, langDir);
report[lang] = { missingFiles, missingKeys };
});

return report;
}

const baseDirectory = './bot/';
const baseDirectory = "./bot/";
const comparisonReport = compareAllLanguages(baseDirectory);

for (const [lang, report] of Object.entries(comparisonReport)) {
console.log(`Language: ${lang}`);
console.log(` Missing files: ${report.missingFiles.length > 0 ? report.missingFiles.join(', ') : 'None'}`);
console.log(` Missing keys: ${Object.keys(report.missingKeys).length > 0 ? JSON.stringify(report.missingKeys, null, 2) : 'None'}`);
console.log();
console.log(`Language: ${lang}`);
console.log(
` Missing files: ${
report.missingFiles.length > 0 ? report.missingFiles.join(", ") : "None"
}`
);
console.log(
` Missing keys: ${
Object.keys(report.missingKeys).length > 0
? JSON.stringify(report.missingKeys, null, 2)
: "None"
}`
);
console.log();
}
60 changes: 31 additions & 29 deletions .github/scripts/validate-json.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
const fs = require('fs');
const path = require('path');
import { readdirSync, statSync, readFileSync } from "fs";
import { join } from "path";

const baseDirectory = './bot';
const baseDirectory = "./bot";

let foundErrors = false;

function validateJSONFiles(directory) {
try {
const files = fs.readdirSync(directory);
try {
const files = readdirSync(directory);

files.forEach(file => {
const filePath = path.join(directory, file);
const stat = fs.statSync(filePath);
files.forEach((file) => {
const filePath = join(directory, file);
const stat = statSync(filePath);

if (stat.isDirectory()) {
validateJSONFiles(filePath);
} else if (file.endsWith('.json')) {
console.log(`Validating ${filePath}...`);
try {
const data = fs.readFileSync(filePath, 'utf8');
JSON.parse(data);
} catch (err) {
console.error(`Error processing ${filePath}: ${err.message}`);
foundErrors = true;
}
}
});
} catch (err) {
console.error(`Error reading directory ${directory}: ${err.message}`);
process.exit(1);
}
if (stat.isDirectory()) {
validateJSONFiles(filePath);
} else if (file.endsWith(".json")) {
console.log(`Validating ${filePath}...`);
try {
const data = readFileSync(filePath, "utf8");
JSON.parse(data);
} catch (err) {
console.error(`Error processing ${filePath}: ${err.message}`);
foundErrors = true;
}
}
});
} catch (err) {
console.error(`Error reading directory ${directory}: ${err.message}`);
process.exit(1);
}
}

validateJSONFiles(baseDirectory);

if (foundErrors) {
console.error("Validation errors found in some JSON files. Please check the logs above.");
process.exit(1);
console.error(
"Validation errors found in some JSON files. Please check the logs above."
);
process.exit(1);
} else {
console.log("All JSON files validated successfully.");
process.exit(0);
console.log("All JSON files validated successfully.");
process.exit(0);
}
Loading
Loading