172 lines
No EOL
6.8 KiB
JavaScript
172 lines
No EOL
6.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Script to add missing remote URL translation keys to all language files
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
const languagesDir = './src/languages';
|
|
|
|
// The new keys to add in English
|
|
const newKeys = {
|
|
remoteUrlTab: "🌐 Remote URL",
|
|
remoteUrlInfo: "Enter a URL to fetch and translate:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Fetch & Translate"
|
|
};
|
|
|
|
// Translations for each language
|
|
const translations = {
|
|
ar: {
|
|
remoteUrlTab: "🌐 رابط بعيد",
|
|
remoteUrlInfo: "أدخل رابط لجلبه وترجمته:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 جلب وترجمة"
|
|
},
|
|
bn: {
|
|
remoteUrlTab: "🌐 দূরবর্তী URL",
|
|
remoteUrlInfo: "একটি URL প্রবেশ করান যা আনতে এবং অনুবাদ করতে:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 আনুন এবং অনুবাদ করুন"
|
|
},
|
|
de: {
|
|
remoteUrlTab: "🌐 Externe URL",
|
|
remoteUrlInfo: "Geben Sie eine URL ein, um sie abzurufen und zu übersetzen:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Abrufen & Übersetzen"
|
|
},
|
|
es: {
|
|
remoteUrlTab: "🌐 URL Remota",
|
|
remoteUrlInfo: "Ingresa una URL para obtener y traducir:",
|
|
remoteUrlPlaceholder: "https://ejemplo.com",
|
|
fetchAndTranslate: "🌐 Obtener y Traducir"
|
|
},
|
|
fr: {
|
|
remoteUrlTab: "🌐 URL Distante",
|
|
remoteUrlInfo: "Entrez une URL à récupérer et traduire:",
|
|
remoteUrlPlaceholder: "https://exemple.com",
|
|
fetchAndTranslate: "🌐 Récupérer et Traduire"
|
|
},
|
|
hi: {
|
|
remoteUrlTab: "🌐 दूरस्थ URL",
|
|
remoteUrlInfo: "लाने और अनुवाद करने के लिए एक URL दर्ज करें:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 लाएं और अनुवाद करें"
|
|
},
|
|
id: {
|
|
remoteUrlTab: "🌐 URL Jarak Jauh",
|
|
remoteUrlInfo: "Masukkan URL untuk diambil dan diterjemahkan:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Ambil & Terjemahkan"
|
|
},
|
|
ja: {
|
|
remoteUrlTab: "🌐 リモートURL",
|
|
remoteUrlInfo: "取得して翻訳するURLを入力してください:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 取得して翻訳"
|
|
},
|
|
ko: {
|
|
remoteUrlTab: "🌐 원격 URL",
|
|
remoteUrlInfo: "가져와서 번역할 URL을 입력하세요:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 가져와서 번역"
|
|
},
|
|
mr: {
|
|
remoteUrlTab: "🌐 दूरस्थ URL",
|
|
remoteUrlInfo: "आणण्यासाठी आणि भाषांतर करण्यासाठी URL प्रविष्ट करा:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 आणा आणि भाषांतर करा"
|
|
},
|
|
pt: {
|
|
remoteUrlTab: "🌐 URL Remota",
|
|
remoteUrlInfo: "Digite uma URL para buscar e traduzir:",
|
|
remoteUrlPlaceholder: "https://exemplo.com",
|
|
fetchAndTranslate: "🌐 Buscar e Traduzir"
|
|
},
|
|
ru: {
|
|
remoteUrlTab: "🌐 Удаленный URL",
|
|
remoteUrlInfo: "Введите URL для загрузки и перевода:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Загрузить и Перевести"
|
|
},
|
|
sw: {
|
|
remoteUrlTab: "🌐 URL ya Mbali",
|
|
remoteUrlInfo: "Ingiza URL ya kuleta na kutafsiri:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Leta na Tafsiri"
|
|
},
|
|
te: {
|
|
remoteUrlTab: "🌐 రిమోట్ URL",
|
|
remoteUrlInfo: "తీసుకురావడానికి మరియు అనువదించడానికి URL ని నమోదు చేయండి:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 తీసుకురండి & అనువదించండి"
|
|
},
|
|
tr: {
|
|
remoteUrlTab: "🌐 Uzak URL",
|
|
remoteUrlInfo: "Getirmek ve çevirmek için bir URL girin:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 Getir ve Çevir"
|
|
},
|
|
ur: {
|
|
remoteUrlTab: "🌐 ریموٹ URL",
|
|
remoteUrlInfo: "لانے اور ترجمہ کرنے کے لیے URL داخل کریں:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 لائیں اور ترجمہ کریں"
|
|
},
|
|
"zh-tw": {
|
|
remoteUrlTab: "🌐 遠端網址",
|
|
remoteUrlInfo: "輸入要擷取和翻譯的網址:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 擷取並翻譯"
|
|
},
|
|
zh: {
|
|
remoteUrlTab: "🌐 远程网址",
|
|
remoteUrlInfo: "输入要获取和翻译的网址:",
|
|
remoteUrlPlaceholder: "https://example.com",
|
|
fetchAndTranslate: "🌐 获取并翻译"
|
|
}
|
|
};
|
|
|
|
// Process each language file
|
|
for (const [langCode, langTranslations] of Object.entries(translations)) {
|
|
const filePath = path.join(languagesDir, `${langCode}.js`);
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
|
|
// Find the position to insert new keys (before the closing })
|
|
const insertPosition = content.lastIndexOf('};');
|
|
|
|
if (insertPosition === -1) {
|
|
console.error(`Could not find export structure in ${filePath}`);
|
|
continue;
|
|
}
|
|
|
|
// Find the last non-empty line before the closing }
|
|
const beforeClosing = content.substring(0, insertPosition).trimEnd();
|
|
|
|
// Check if any of the new keys already exist
|
|
const hasNewKeys = Object.keys(langTranslations).some(key =>
|
|
content.includes(`${key}:`));
|
|
|
|
if (hasNewKeys) {
|
|
console.log(`✅ ${langCode}: Keys already present, skipping`);
|
|
continue;
|
|
}
|
|
|
|
// Build the new keys string
|
|
const newKeysString = Object.entries(langTranslations)
|
|
.map(([key, value]) => `\t${key}: "${value}",`)
|
|
.join('\n');
|
|
|
|
// Insert the new keys
|
|
const newContent = beforeClosing + ',\n' + newKeysString + '\n};';
|
|
|
|
fs.writeFileSync(filePath, newContent, 'utf8');
|
|
console.log(`✅ ${langCode}: Added remote URL translation keys`);
|
|
} else {
|
|
console.error(`File not found: ${filePath}`);
|
|
}
|
|
}
|
|
|
|
console.log('\n🎉 Finished adding remote URL translation keys to all language files!'); |