From 4eedcca9a7f0e4b3ee73e09aff38331dd9c0a559 Mon Sep 17 00:00:00 2001 From: arteck <6681528+arteck@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:42:49 +0200 Subject: [PATCH] Update convertWordsToI18n.js --- admin/convertWordsToI18n.js | 71 ++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/admin/convertWordsToI18n.js b/admin/convertWordsToI18n.js index 1032fdff..40c2a105 100644 --- a/admin/convertWordsToI18n.js +++ b/admin/convertWordsToI18n.js @@ -1,34 +1,55 @@ const fs = require('fs'); const path = require('path'); -// 1. Importiere die words.js Datei -const { words } = require('./words.js'); - -// 2. Definiere die Zielsprachen und Dateien -const languages = ['en', 'de']; // Sprachen, die du untersttzen mchtest -const translations = { - en: {}, - de: {} +// Beispielhaftes systemDictionary +const systemDictionary = { + 'bluelink adapter settings': { + 'en': 'Adapter settings for bluelink', + 'de': 'Adaptereinstellungen für bluelink', + 'ru': 'Настройки адаптера для bluelink', + 'pt': 'Configurações do adaptador para bluelink', + 'nl': 'Adapterinstellingen voor bluelink', + 'fr': "Paramètres d'adaptateur pour bluelink", + 'it': "Impostazioni dell'adattatore per bluelink", + 'es': 'Ajustes del adaptador para bluelink', + 'pl': 'Ustawienia adaptera dla bluelink', + 'zh-cn': 'bluelink的适配器设置' + } }; -// 3. Automatisch bersetzungen fr die Sprachen anlegen (hier nur als Beispiel) -Object.keys(words).forEach(key => { - translations.en[key] = words[key]; // Englisch bleibt gleich - translations.de[key] = words[key]; // In einer echten App wrdest du hier echte bersetzungen hinzufgen -}); -// 4. Erstelle das Verzeichnis fr die Lokalisierungen -const localesDir = path.join(__dirname, 'locales'); -if (!fs.existsSync(localesDir)) { - fs.mkdirSync(localesDir); -} +// Funktion zur Konvertierung von systemDictionary in eine Ordnerstruktur mit translations.json +function convertToI18n(systemDictionary) { + const translations = {}; + + // Iteriere durch alle Schlüssel im systemDictionary + for (const [key, values] of Object.entries(systemDictionary)) { + // Iteriere durch alle Sprachen für jeden Schlüssel + for (const [lang, translation] of Object.entries(values)) { + if (!translations[lang]) { + translations[lang] = {}; + } + translations[lang][key] = translation; + } + } -// 5. Schreibe die JSON-Dateien fr jede Sprache -languages.forEach(lang => { - const filePath = path.join(localesDir, `${lang}.json`); - fs.writeFileSync(filePath, JSON.stringify(translations[lang], null, 2), 'utf8'); - console.log(`bersetzungen fr ${lang} gespeichert in ${filePath}`); -}); + // Speicher die Übersetzungen in separaten Ordnern mit translations.json + const localesDir = path.join(__dirname, 'i18n'); + if (!fs.existsSync(localesDir)) { + fs.mkdirSync(localesDir); + } -console.log("Konvertierung abgeschlossen."); + // Erstelle einen Ordner pro Sprache und speichere translations.json darin + for (const [lang, translation] of Object.entries(translations)) { + const langDir = path.join(localesDir, lang); // Ordner für die Sprache + if (!fs.existsSync(langDir)) { + fs.mkdirSync(langDir); + } + + const filePath = path.join(langDir, 'translations.json'); + fs.writeFileSync(filePath, JSON.stringify(translation, null, 2), 'utf8'); + console.log(`Übersetzungen für ${lang} gespeichert in ${filePath}`); + } +} +convertToI18n(systemDictionary);