Skip to content

Commit

Permalink
Update convertWordsToI18n.js
Browse files Browse the repository at this point in the history
  • Loading branch information
arteck authored Sep 27, 2024
1 parent c6c80d8 commit 4eedcca
Showing 1 changed file with 46 additions and 25 deletions.
71 changes: 46 additions & 25 deletions admin/convertWordsToI18n.js
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);

0 comments on commit 4eedcca

Please sign in to comment.