stuff
This commit is contained in:
parent
eb051e876e
commit
790ab47b7a
|
@ -7792,6 +7792,66 @@ module.exports = (_ => {
|
|||
BDFDB.DevUtils.listenStop = function () {
|
||||
if (typeof BDFDB.DevUtils.listen.p == "function") BDFDB.DevUtils.listen.p();
|
||||
};
|
||||
BDFDB.DevUtils.generateLanguageStrings = function (strings, useBackup = false) {
|
||||
const languages = Object.keys(BDFDB.ObjectUtils.filter(BDFDB.LanguageUtils.Languages, n => n.discord)).filter(n => !n.startsWith("en-")).sort();
|
||||
let translations = {};
|
||||
strings = BDFDB.ObjectUtils.sort(strings);
|
||||
let text = Object.keys(strings).map(k => strings[k]).join("\n\n");
|
||||
|
||||
let gt = (lang, callback) => {
|
||||
let googleTranslateWindow = BDFDB.WindowUtils.open(BDFDB, `https://translate.google.com/#en/${lang}/${encodeURIComponent(text)}`, {
|
||||
onLoad: _ => {
|
||||
googleTranslateWindow.executeJavaScriptSafe(`
|
||||
require("electron").ipcRenderer.sendTo(${BDFDB.LibraryRequires.electron.remote.getCurrentWindow().webContents.id}, "GTO-translation", [
|
||||
(document.querySelector("[data-language-to-translate-into] span") || {}).innerText,
|
||||
(document.querySelector("h2 ~ [lang]") || {}).lang
|
||||
]);
|
||||
`);
|
||||
}
|
||||
});
|
||||
BDFDB.WindowUtils.addListener(BDFDB, "GTO-translation", (event, messageData) => {
|
||||
BDFDB.WindowUtils.close(googleTranslateWindow);
|
||||
BDFDB.WindowUtils.removeListener(BDFDB, "GTO-translation");
|
||||
callback(messageData[0]);
|
||||
});
|
||||
};
|
||||
let gt2 = (lang, callback) => {
|
||||
BDFDB.LibraryRequires.request(`https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${lang}&dt=t&dj=1&source=input&q=${encodeURIComponent(text)}`, (error, response, result) => {
|
||||
if (!error && result && response.statusCode == 200) {
|
||||
try {callback(JSON.parse(result).sentences.map(n => n && n.trans).filter(n => n).join(""));}
|
||||
catch (err) {callback("");}
|
||||
}
|
||||
else {
|
||||
if (response.statusCode == 429) {
|
||||
BDFDB.NotificationUtils.toast("Too many requests. Switching to backup.", {type: "error"});
|
||||
translate(strings, true);
|
||||
}
|
||||
else {
|
||||
BDFDB.NotificationUtils.toast("Failed to translate text.", {type: "error"});
|
||||
callback("");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
let next = lang => {
|
||||
if (!lang) {
|
||||
let result = Object.keys(translations).sort().map(l => `\n\t\t\t\t\tcase "${l}":${l.length > 2 ? "\t" : "\t\t"}// ${BDFDB.LanguageUtils.languages[l].name}\n\t\t\t\t\t\treturn {${translations[l].map((s, i) => `\n\t\t\t\t\t\t\t${Object.keys(strings)[i]}:${"\t".repeat(10 - ((Object.keys(strings)[i].length + 1) / 4))}"${s}"\n\t\t\t\t\t\t`).join("\n")}};`).join("");
|
||||
result += `\n\t\t\t\t\tdefault:\t\t// English\n\t\t\t\t\t\treturn {${Object.keys(strings).map(s => `\n\t\t\t\t\t\t\t${s}:${"\t".repeat(10 - ((s.length + 1) / 4))}"${strings[s]}"\n\t\t\t\t\t\t`).join("\n")}};`
|
||||
console.log(result);
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text: result});
|
||||
}
|
||||
else (useBackup ? gt : gt2)(lang, translation => {
|
||||
console.log(lang);
|
||||
if (!translation) {
|
||||
console.warn("no translation");
|
||||
languages.push(lang);
|
||||
}
|
||||
else translations[lang] = translation.split("\n\n");
|
||||
next(languages.shift());
|
||||
});
|
||||
};
|
||||
next(languages.shift());
|
||||
};
|
||||
BDFDB.DevUtils.req = InternalBDFDB.getWebModuleReq();
|
||||
|
||||
window.BDFDB_Global = BDFDB;
|
||||
|
|
|
@ -2758,36 +2758,36 @@
|
|||
"be": {"name":"Belarusian", "id":"be", "ownlang":"Беларуская"},
|
||||
"bn": {"name":"Bengali", "id":"bn", "ownlang":"বাংলা"},
|
||||
"bs": {"name":"Bosnian", "id":"bs", "ownlang":"Босански"},
|
||||
"bg": {"name":"Bulgarian", "id":"bg", "ownlang":"български"},
|
||||
"bg": {"name":"Bulgarian", "id":"bg", "ownlang":"български", "discord":true},
|
||||
"my": {"name":"Burmese", "id":"my", "ownlang":"မြန်မာစာ"},
|
||||
"ca": {"name":"Catalan", "id":"ca", "ownlang":"Català"},
|
||||
"ceb": {"name":"Cebuano", "id":"ceb", "ownlang":"Bisaya"},
|
||||
"ny": {"name":"Chichewa", "id":"ny", "ownlang":"Nyanja"},
|
||||
"zh": {"name":"Chinese", "id":"zh", "ownlang":"中文"},
|
||||
"zh": {"name":"Chinese", "id":"zh", "ownlang":"中文", "discord":true},
|
||||
"zh-HK": {"name":"Chinese (Hong Kong)", "id":"zh-HK", "ownlang":"香港中文"},
|
||||
"zh-CN": {"name":"Chinese (Simplified)", "id":"zh-CN", "ownlang":"简体中文"},
|
||||
"zh-TW": {"name":"Chinese (Traditional)", "id":"zh-TW", "ownlang":"繁體中文"},
|
||||
"zh-TW": {"name":"Chinese (Traditional)", "id":"zh-TW", "ownlang":"繁體中文", "discord":true},
|
||||
"co": {"name":"Corsican", "id":"co", "ownlang":"Corsu"},
|
||||
"hr": {"name":"Croatian", "id":"hr", "ownlang":"Hrvatski"},
|
||||
"hr": {"name":"Croatian", "id":"hr", "ownlang":"Hrvatski", "discord":true},
|
||||
"cs": {"name":"Czech", "id":"cs", "ownlang":"Čeština"},
|
||||
"da": {"name":"Danish", "id":"da", "ownlang":"Dansk"},
|
||||
"nl": {"name":"Dutch", "id":"nl", "ownlang":"Nederlands"},
|
||||
"da": {"name":"Danish", "id":"da", "ownlang":"Dansk", "discord":true},
|
||||
"nl": {"name":"Dutch", "id":"nl", "ownlang":"Nederlands", "discord":true},
|
||||
"en": {"name":"English", "id":"en", "ownlang":"English"},
|
||||
"en-GB": {"name":"English (UK)", "id":"en-GB", "ownlang":"English (UK)"},
|
||||
"en-US": {"name":"English (US)", "id":"en-US", "ownlang":"English (US)"},
|
||||
"en-GB": {"name":"English (UK)", "id":"en-GB", "ownlang":"English (UK)", "discord":true},
|
||||
"en-US": {"name":"English (US)", "id":"en-US", "ownlang":"English (US)", "discord":true},
|
||||
"eo": {"name":"Esperanto", "id":"eo", "ownlang":"Esperanto"},
|
||||
"et": {"name":"Estonian", "id":"et", "ownlang":"Eesti"},
|
||||
"fil": {"name":"Filipino", "id":"fil", "ownlang":"Wikang Filipino"},
|
||||
"fi": {"name":"Finnish", "id":"fi", "ownlang":"Suomi"},
|
||||
"fr": {"name":"French", "id":"fr", "ownlang":"Français"},
|
||||
"fi": {"name":"Finnish", "id":"fi", "ownlang":"Suomi", "discord":true},
|
||||
"fr": {"name":"French", "id":"fr", "ownlang":"Français", "discord":true},
|
||||
"fr-CA": {"name":"French (Canadian)", "id":"fr-CA", "ownlang":"Français Canadien"},
|
||||
"fy": {"name":"Frisian", "id":"fy", "ownlang":"Frysk"},
|
||||
"gl": {"name":"Galician", "id":"gl", "ownlang":"Galego"},
|
||||
"ka": {"name":"Georgian", "id":"ka", "ownlang":"ქართული"},
|
||||
"de": {"name":"German", "id":"de", "ownlang":"Deutsch"},
|
||||
"de": {"name":"German", "id":"de", "ownlang":"Deutsch", "discord":true},
|
||||
"de-AT": {"name":"German (Austria)", "id":"de-AT", "ownlang":"Österreichisch Deutsch"},
|
||||
"de-CH": {"name":"German (Switzerland)", "id":"de-CH", "ownlang":"Schweizerdeutsch"},
|
||||
"el": {"name":"Greek", "id":"el", "ownlang":"Ελληνικά"},
|
||||
"el": {"name":"Greek", "id":"el", "ownlang":"Ελληνικά", "discord":true},
|
||||
"gu": {"name":"Gujarati", "id":"gu", "ownlang":"ગુજરાતી"},
|
||||
"ht": {"name":"Haitian Creole", "id":"ht", "ownlang":"Kreyòl Ayisyen"},
|
||||
"ha": {"name":"Hausa", "id":"ha", "ownlang":"حَوْسَ"},
|
||||
|
@ -2796,26 +2796,26 @@
|
|||
"iw": {"name":"Hebrew (Israel)", "id":"iw", "ownlang":"עברית"},
|
||||
"hi": {"name":"Hindi", "id":"hi", "ownlang":"हिन्दी"},
|
||||
"hmn": {"name":"Hmong", "id":"hmn", "ownlang":"lol Hmongb"},
|
||||
"hu": {"name":"Hungarian", "id":"hu", "ownlang":"Magyar"},
|
||||
"hu": {"name":"Hungarian", "id":"hu", "ownlang":"Magyar", "discord":true},
|
||||
"is": {"name":"Icelandic", "id":"is", "ownlang":"Íslenska"},
|
||||
"ig": {"name":"Igbo", "id":"ig", "ownlang":"Asụsụ Igbo"},
|
||||
"id": {"name":"Indonesian", "id":"id", "ownlang":"Bahasa Indonesia"},
|
||||
"ga": {"name":"Irish", "id":"ga", "ownlang":"Gaeilge"},
|
||||
"it": {"name":"Italian", "id":"it", "ownlang":"Italiano"},
|
||||
"ja": {"name":"Japanese", "id":"ja", "ownlang":"日本語"},
|
||||
"it": {"name":"Italian", "id":"it", "ownlang":"Italiano", "discord":true},
|
||||
"ja": {"name":"Japanese", "id":"ja", "ownlang":"日本語", "discord":true},
|
||||
"jv": {"name":"Javanese", "id":"jv", "ownlang":"ꦧꦱꦗꦮ"},
|
||||
"jw": {"name":"Javanese (Javanese)", "id":"jw", "ownlang":"ꦧꦱꦗꦮ"},
|
||||
"kn": {"name":"Kannada", "id":"kn", "ownlang":"ಕನ್ನಡ"},
|
||||
"kk": {"name":"Kazakh", "id":"kk", "ownlang":"Қазақ Tілі"},
|
||||
"km": {"name":"Khmer", "id":"km", "ownlang":"ភាសាខ្មែរ"},
|
||||
"rw": {"name":"Kinyarwanda", "id":"rw", "ownlang":"Ikinyarwanda"},
|
||||
"ko": {"name":"Korean", "id":"ko", "ownlang":"한국어"},
|
||||
"ko": {"name":"Korean", "id":"ko", "ownlang":"한국어", "discord":true},
|
||||
"ku": {"name":"Kurdish", "id":"ku", "ownlang":"کوردی"},
|
||||
"ky": {"name":"Kyrgyz", "id":"ky", "ownlang":"кыргызча"},
|
||||
"lo": {"name":"Lao", "id":"lo", "ownlang":"ພາສາລາວ"},
|
||||
"la": {"name":"Latin", "id":"la", "ownlang":"Latina"},
|
||||
"lv": {"name":"Latvian", "id":"lv", "ownlang":"Latviešu"},
|
||||
"lt": {"name":"Lithuanian", "id":"lt", "ownlang":"Lietuvių"},
|
||||
"lt": {"name":"Lithuanian", "id":"lt", "ownlang":"Lietuvių", "discord":true},
|
||||
"lb": {"name":"Luxembourgish", "id":"lb", "ownlang":"Lëtzebuergesch"},
|
||||
"mk": {"name":"Macedonian", "id":"mk", "ownlang":"Mакедонски"},
|
||||
"mg": {"name":"Malagasy", "id":"mg", "ownlang":"Malagasy"},
|
||||
|
@ -2828,18 +2828,18 @@
|
|||
"mn": {"name":"Mongolian", "id":"mn", "ownlang":"Монгол Хэл"},
|
||||
"my": {"name":"Myanmar (Burmese)", "id":"my", "ownlang":"မြန်မာл Хэл"},
|
||||
"ne": {"name":"Nepali", "id":"ne", "ownlang":"नेपाली"},
|
||||
"no": {"name":"Norwegian", "id":"no", "ownlang":"Norsk"},
|
||||
"no": {"name":"Norwegian", "id":"no", "ownlang":"Norsk", "discord":true},
|
||||
"or": {"name":"Odia", "id":"or", "ownlang":"ଓଡ଼ିଆ"},
|
||||
"pap": {"name":"Papiamento", "id":"pap", "ownlang":"Papiamentu"},
|
||||
"ps": {"name":"Pashto", "id":"ps", "ownlang":"پښتو"},
|
||||
"fa": {"name":"Persian", "id":"fa", "ownlang":"فارسی"},
|
||||
"pl": {"name":"Polish", "id":"pl", "ownlang":"Polski"},
|
||||
"pl": {"name":"Polish", "id":"pl", "ownlang":"Polski", "discord":true},
|
||||
"pt": {"name":"Portuguese", "id":"pt", "ownlang":"Português"},
|
||||
"pt-BR": {"name":"Portuguese (Brazil)", "id":"pt-BR", "ownlang":"Português do Brasil"},
|
||||
"pt-BR": {"name":"Portuguese (Brazil)", "id":"pt-BR", "ownlang":"Português do Brasil", "discord":true},
|
||||
"pt-PT": {"name":"Portuguese (Portugal)", "id":"pt-PT", "ownlang":"Português do Portugal"},
|
||||
"pa": {"name":"Punjabi", "id":"pa", "ownlang":"पंजाबी"},
|
||||
"ro": {"name":"Romanian", "id":"ro", "ownlang":"Română"},
|
||||
"ru": {"name":"Russian", "id":"ru", "ownlang":"Pусский"},
|
||||
"ro": {"name":"Romanian", "id":"ro", "ownlang":"Română", "discord":true},
|
||||
"ru": {"name":"Russian", "id":"ru", "ownlang":"Pусский", "discord":true},
|
||||
"sm": {"name":"Samoan", "id":"sm", "ownlang":"Gagana Sāmoa"},
|
||||
"gd": {"name":"Scottish Gaelic", "id":"gd", "ownlang":"Gàidhlig"},
|
||||
"sr": {"name":"Serbian", "id":"sr", "ownlang":"Српски"},
|
||||
|
@ -2850,25 +2850,25 @@
|
|||
"sk": {"name":"Slovak", "id":"sk", "ownlang":"Slovenčina"},
|
||||
"sl": {"name":"Slovenian", "id":"sl", "ownlang":"Slovenščina"},
|
||||
"so": {"name":"Somali", "id":"so", "ownlang":"Soomaali"},
|
||||
"es": {"name":"Spanish", "id":"es", "ownlang":"Español"},
|
||||
"es": {"name":"Spanish", "id":"es", "ownlang":"Español", "discord":true},
|
||||
"es-419": {"name":"Spanish (Latin America)", "id":"es-419", "ownlang":"Español latinoamericano"},
|
||||
"su": {"name":"Sundanese", "id":"su", "ownlang":"Basa Sunda"},
|
||||
"sw": {"name":"Swahili", "id":"sw", "ownlang":"Kiswahili"},
|
||||
"sv": {"name":"Swedish", "id":"sv", "ownlang":"Svenska"},
|
||||
"sv": {"name":"Swedish", "id":"sv", "ownlang":"Svenska", "discord":true},
|
||||
"tl": {"name":"Tagalog", "id":"tl", "ownlang":"Wikang Tagalog"},
|
||||
"tg": {"name":"Tajik", "id":"tg", "ownlang":"тоҷикӣ"},
|
||||
"ta": {"name":"Tamil", "id":"ta", "ownlang":"தமிழ்"},
|
||||
"tt": {"name":"Tatar", "id":"tt", "ownlang":"татарча"},
|
||||
"te": {"name":"Telugu", "id":"te", "ownlang":"తెలుగు"},
|
||||
"th": {"name":"Thai", "id":"th", "ownlang":"ภาษาไทย"},
|
||||
"tr": {"name":"Turkish", "id":"tr", "ownlang":"Türkçe"},
|
||||
"th": {"name":"Thai", "id":"th", "ownlang":"ภาษาไทย", "discord":true},
|
||||
"tr": {"name":"Turkish", "id":"tr", "ownlang":"Türkçe", "discord":true},
|
||||
"tk": {"name":"Turkmen", "id":"tk", "ownlang":"Türkmençe"},
|
||||
"udm": {"name":"Udmurt", "id":"udm", "ownlang":"удмурт кыл"},
|
||||
"uk": {"name":"Ukrainian", "id":"uk", "ownlang":"Yкраїнський"},
|
||||
"uk": {"name":"Ukrainian", "id":"uk", "ownlang":"Yкраїнський", "discord":true},
|
||||
"ur": {"name":"Urdu", "id":"ur", "ownlang":"اُردُو"},
|
||||
"ug": {"name":"Uyghur", "id":"ug", "ownlang":"ئۇيغۇر تىلى"},
|
||||
"uz": {"name":"Uzbek", "id":"uz", "ownlang":"اوزبیک"},
|
||||
"vi": {"name":"Vietnamese", "id":"vi", "ownlang":"Tiếng Việt Nam"},
|
||||
"vi": {"name":"Vietnamese", "id":"vi", "ownlang":"Tiếng Việt Nam", "discord":true},
|
||||
"cy": {"name":"Welsh", "id":"cy", "ownlang":"Cymraeg"},
|
||||
"xh": {"name":"Xhosa", "id":"xh", "ownlang":"Xhosa"},
|
||||
"yi": {"name":"Yiddish", "id":"yi", "ownlang":"ייִדיש ייִדיש"},
|
||||
|
|
|
@ -722,7 +722,8 @@ module.exports = (_ => {
|
|||
catch (err) {callback("");}
|
||||
}
|
||||
else {
|
||||
BDFDB.NotificationUtils.toast("Failed to translate text. Translation Server is down or Request Limit per Hour is reached. Try another Translate Engine.", {type: "error"});
|
||||
if (response.statusCode == 429) BDFDB_Global.NotificationUtils.toast("Failed to translate text. Request Limit per Hour is reached. Choose another Translate Engine.", {type: "error"});
|
||||
else BDFDB.NotificationUtils.toast("Failed to translate text. Translation Server might be down. Try another Translate Engine.", {type: "error"});
|
||||
callback("");
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue