feat: added script for reversing back to file stricture

This commit is contained in:
obvTiger 2025-01-16 16:45:56 +01:00
parent be686e28ff
commit c3eab13c11

37
reverse.js Normal file
View file

@ -0,0 +1,37 @@
const fs = require("fs");
const path = require("path");
const inputFile = "translations.generated.json";
const outputDir = "./reversed";
function ensureDirectoryExists(dirPath) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}
function reverseTranslations() {
const translations = JSON.parse(fs.readFileSync(inputFile, "utf8"));
ensureDirectoryExists(outputDir);
Object.entries(translations).forEach(([key, content]) => {
const pathSegments = key.split(".");
const fileName = pathSegments.pop() + ".json";
const dirPath = path.join(outputDir, ...pathSegments);
ensureDirectoryExists(dirPath);
const filePath = path.join(dirPath, fileName);
fs.writeFileSync(filePath, JSON.stringify(content, null, 4), "utf8");
});
console.log(
`Translations have been reversed into directory structure at: ${outputDir}`
);
}
reverseTranslations();