From c3eab13c11c1e59d4dbd0f21d6617c0537800fb8 Mon Sep 17 00:00:00 2001 From: obvTiger Date: Thu, 16 Jan 2025 16:45:56 +0100 Subject: [PATCH] feat: added script for reversing back to file stricture --- reverse.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 reverse.js diff --git a/reverse.js b/reverse.js new file mode 100644 index 0000000..6b5c6f0 --- /dev/null +++ b/reverse.js @@ -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();