-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 unterstützen möchtest | ||
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 für 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 würdest du hier echte Übersetzungen hinzufügen | ||
}); | ||
|
||
// 4. Erstelle das Verzeichnis für 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 für 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 für ${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); |