feat: added script for reversing back to file stricture
This commit is contained in:
parent
be686e28ff
commit
c3eab13c11
1 changed files with 37 additions and 0 deletions
37
reverse.js
Normal file
37
reverse.js
Normal 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();
|
Loading…
Add table
Add a link
Reference in a new issue