This commit is contained in:
Mirco Wittrien 2019-12-10 13:21:59 +01:00
parent aace96c3ff
commit f5d7966512
3 changed files with 86 additions and 16 deletions

View File

@ -6063,6 +6063,7 @@
"ar": {name:"Arabic", id:"ar", ownlang:"اللغة العربية", integrated:false, dic:false},
"hy": {name:"Armenian", id:"hy", ownlang:"Հայերեն", integrated:false, dic:false},
"az": {name:"Azerbaijani", id:"az", ownlang:"آذربایجان دیلی", integrated:false, dic:false},
"ba": {name:"Bashkir", id:"ba", ownlang:"Башҡорт", integrated:false, dic:false},
"eu": {name:"Basque", id:"eu", ownlang:"Euskara", integrated:false, dic:false},
"be": {name:"Belarusian", id:"be", ownlang:"Беларуская", integrated:false, dic:false},
"bn": {name:"Bengali", id:"bn", ownlang:"বাংলা", integrated:false, dic:false},
@ -6071,7 +6072,7 @@
"my": {name:"Burmese", id:"my", ownlang:"မြန်မာစာ", integrated:false, dic:false},
"ca": {name:"Catalan", id:"ca", ownlang:"Català", integrated:false, dic:false},
"ceb": {name:"Cebuano", id:"ceb", ownlang:"Bisaya", integrated:false, dic:false},
"ny": {name:"Chewa", id:"ny", ownlang:"Nyanja", integrated:false, dic:false},
"ny": {name:"Chichewa", id:"ny", ownlang:"Nyanja", integrated:false, dic:false},
"zh-HK": {name:"Chinese (Hong Kong)", id:"zh-HK", ownlang:"香港中文", integrated:false, dic:false},
"zh-CN": {name:"Chinese (Simplified)", id:"zh-CN", ownlang:"简体中文", integrated:false, dic:false},
"zh-TW": {name:"Chinese (Traditional)", id:"zh-TW", ownlang:"繁體中文", integrated:true, dic:false},
@ -6100,7 +6101,8 @@
"ht": {name:"Haitian Creole", id:"ht", ownlang:"Kreyòl Ayisyen", integrated:false, dic:false},
"ha": {name:"Hausa", id:"ha", ownlang:"حَوْسَ", integrated:false, dic:false},
"haw": {name:"Hawaiian", id:"haw", ownlang:"ʻŌlelo Hawaiʻi", integrated:false, dic:false},
"iw": {name:"Hebrew", id:"iw", ownlang:"עברית", integrated:false, dic:false},
"he": {name:"Hebrew", id:"he", ownlang:"עברית", integrated:false, dic:false},
"iw": {name:"Hebrew (Isreal)", id:"iw", ownlang:"עברית", integrated:false, dic:false},
"hi": {name:"Hindi", id:"hi", ownlang:"हिन्दी", integrated:false, dic:false},
"hmn": {name:"Hmong", id:"hmn", ownlang:"lol Hmongb", integrated:false, dic:false},
"hu": {name:"Hungarian", id:"hu", ownlang:"Magyar", integrated:false, dic:false},
@ -6110,7 +6112,8 @@
"ga": {name:"Irish", id:"ga", ownlang:"Gaeilge", integrated:false, dic:false},
"it": {name:"Italian", id:"it", ownlang:"Italiano", integrated:true, dic:true},
"ja": {name:"Japanese", id:"ja", ownlang:"日本語", integrated:true, dic:false},
"jw": {name:"Javanese", id:"jw", ownlang:"ꦧꦱꦗꦮ", integrated:false, dic:false},
"jv": {name:"Javanese", id:"jv", ownlang:"ꦧꦱꦗꦮ", integrated:false, dic:false},
"jw": {name:"Javanese (Javanese)", id:"jw", ownlang:"ꦧꦱꦗꦮ", integrated:false, dic:false},
"kn": {name:"Kannada", id:"kn", ownlang:"ಕನ್ನಡ", integrated:false, dic:false},
"kk": {name:"Kazakh", id:"kk", ownlang:"Қазақ Tілі", integrated:false, dic:false},
"km": {name:"Khmer", id:"km", ownlang:"ភាសាខ្មែរ", integrated:false, dic:false},
@ -6129,10 +6132,12 @@
"mt": {name:"Maltese", id:"mt", ownlang:"Malti", integrated:false, dic:false},
"mi": {name:"Maori", id:"mi", ownlang:"te Reo Māori", integrated:false, dic:false},
"mr": {name:"Marathi", id:"mr", ownlang:"मराठी", integrated:false, dic:false},
"mhr": {name:"Mari", id:"mhr", ownlang:"марий йылме", integrated:false, dic:false},
"mn": {name:"Mongolian", id:"mn", ownlang:"Монгол Хэл", integrated:false, dic:false},
"my": {name:"Myanmar (Burmese)", id:"my", ownlang:"မြန်မာл Хэл", integrated:false, dic:false},
"ne": {name:"Nepali", id:"ne", ownlang:"नेपाली", integrated:false, dic:false},
"no": {name:"Norwegian", id:"no", ownlang:"Norsk", integrated:true, dic:false},
"pap": {name:"Papiamento", id:"pap", ownlang:"Papiamentu", integrated:false, dic:false},
"ps": {name:"Pashto", id:"ps", ownlang:"پښتو", integrated:false, dic:false},
"fa": {name:"Persian", id:"fa", ownlang:"فارسی", integrated:false, dic:false},
"pl": {name:"Polish", id:"pl", ownlang:"Polski", integrated:true, dic:true},
@ -6145,7 +6150,7 @@
"sm": {name:"Samoan", id:"sm", ownlang:"Gagana Sāmoa", integrated:false, dic:false},
"gd": {name:"Scottish Gaelic", id:"gd", ownlang:"Gàidhlig", integrated:false, dic:false},
"sr": {name:"Serbian", id:"sr", ownlang:"Српски", integrated:false, dic:false},
"st": {name:"Sotho", id:"st", ownlang:"Sesotho", integrated:false, dic:false},
"st": {name:"Sesotho", id:"st", ownlang:"Sesotho", integrated:false, dic:false},
"sn": {name:"Shona", id:"sn", ownlang:"Shona", integrated:false, dic:false},
"sd": {name:"Sindhi", id:"sd", ownlang:"سنڌي", integrated:false, dic:false},
"si": {name:"Sinhala", id:"si", ownlang:"සිංහල", integrated:false, dic:false},
@ -6154,13 +6159,17 @@
"so": {name:"Somali", id:"so", ownlang:"Soomaali", integrated:false, dic:false},
"es": {name:"Spanish", id:"es", ownlang:"Español", integrated:true, dic:true},
"es-419": {name:"Spanish (Latin America)", id:"es-419", ownlang:"Español latinoamericano", integrated:false, dic:false},
"su": {name:"Sundanese", id:"su", ownlang:"Basa Sunda", integrated:false, dic:false},
"sw": {name:"Swahili", id:"sw", ownlang:"Kiswahili", integrated:false, dic:false},
"sv": {name:"Swedish", id:"sv", ownlang:"Svenska", integrated:true, dic:true},
"tl": {name:"Tagalog", id:"tl", ownlang:"Wikang Tagalog", integrated:false, dic:false},
"tg": {name:"Tajik", id:"tg", ownlang:"тоҷикӣ", integrated:false, dic:false},
"ta": {name:"Tamil", id:"ta", ownlang:"தமிழ்", integrated:false, dic:false},
"tt": {name:"Tatar", id:"tt", ownlang:"татарча", integrated:false, dic:false},
"te": {name:"Telugu", id:"te", ownlang:"తెలుగు", integrated:false, dic:false},
"th": {name:"Thai", id:"th", ownlang:"ภาษาไทย", integrated:false, dic:false},
"tr": {name:"Turkish", id:"tr", ownlang:"Türkçe", integrated:true, dic:false},
"udm": {name:"Udmurt", id:"udm", ownlang:"удмурт кыл", integrated:false, dic:false},
"uk": {name:"Ukrainian", id:"uk", ownlang:"Yкраїнський", integrated:true, dic:false},
"ur": {name:"Urdu", id:"ur", ownlang:"اُردُو", integrated:false, dic:false},
"uz": {name:"Uzbek", id:"uz", ownlang:"اوزبیک", integrated:false, dic:false},

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
class GoogleTranslateOption {
getName () {return "GoogleTranslateOption";}
getVersion () {return "1.8.2";}
getVersion () {return "1.8.3";}
getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class GoogleTranslateOption {
constructor () {
this.changelog = {
"improved":[["Messages stay translated", "Messages will stay translated even if you switch channels"],["New Engines","New Engines will soon be added to the plugin, since google has become really slow"]],
"improved":[["Messages stay translated", "Messages will stay translated even if you switch channels"],["iTranslate & Yandex","Added iTranslate and Yandex engine, these engines got a montly rate limit, so if they don't work switch back to Google"]],
"fixed":[["Google API","Google ultimately removed their free Google Translate Endpoint, killing any chances of using a free translation API that doesn't have a requests per month limit. I switched to emulating the translate webpage in an invisible browserwindow, sadly this is far slower than the old method, but at least it still works"],["New Chatbar","Translating outgoing messages works again"]]
};
@ -60,7 +60,9 @@ class GoogleTranslateOption {
};
this.translationEngines = {
google: {name:"Google", func:this.googleTranslate, languages: ["af","sq","am","ar","hy","az","eu","be","bn","bs","bg","my","ca","ceb","ny","zh-CN","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","iw","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","ne","no","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","sw","sv","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"]}
google: {name:"Google", func:this.googleTranslate, languages: ["af","sq","am","ar","hy","az","eu","be","bn","bs","bg","my","ca","ceb","ny","zh-CN","co","hr","cs","da","nl","en","eo","et","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","iw","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","ne","no","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","sw","sv","tg","ta","te","th","tr","uk","ur","uz","vi","cy","xh","yi","yo","zu"]},
itranslate: {name:"iTranslate", func:this.iTranslateTranslate, languages: ["af","sq","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","ny","zh-CN","zh-TW","hr","cs","da","nl","en","eo","et","fil","fi","fr","gl","ka","de","el","gu","ht","he","ha","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","ko","lo","la","lv","lt","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","fa","pl","pt-BR","pt-PT","pa","ro","ru","sr","st","si","sk","sl","so","es","su","sw","sv","tg","ta","te","th","tr","uk","ur","uz","vi","we","yi","yo","zu"]},
yandex: {name:"Yandex", func:this.yandexTranslate, languages: ["af","sq","am","ar","hy","az","ba","eu","be","bn","bs","bg","my","ca","ceb","zh","hr","cs","da","nl","en","eo","et","fi","fr","gl","ka","de","el","gu","ht","he","hi","hu","is","id","ga","it","ja","jv","kn","kk","km","ko","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mhr","mn","ne","no","pap","fa","pl","pt","pa","ro","ru","gd","sr","si","sk","sl","es","su","sw","sv","tl","tg","ta","tt","te","th","tr","udm","uk","ur","uz","vi","cy","xh","yi"]}
};
this.css = `
@ -491,10 +493,15 @@ class GoogleTranslateOption {
var input = Object.assign({}, this.languages[this.getLanguageChoice("input", type)]);
var output = Object.assign({}, this.languages[this.getLanguageChoice("output", type)]);
if (translate) {
let timer = 0;
toast = BDFDB.NotificationUtils.toast("Translating. Please wait", {timeout:0});
toast.interval = BDFDB.TimeUtils.interval(() => {
toast.textContent = toast.textContent.indexOf(".....") > -1 ? "Translating. Please wait" : toast.textContent + ".";
},500);
toast.interval = BDFDB.TimeUtils.interval(_ => {
if (timer++ > 40) {
finishTranslation("");
BDFDB.NotificationUtils.toast("Failed to translate text. Try another Translate Engine.", {type:"error"});
}
else toast.textContent = toast.textContent.indexOf(".....") > -1 ? "Translating. Please wait" : toast.textContent + ".";
}, 500);
let specialcase = this.checkForSpecialCase(newtext, input);
if (specialcase) {
input.name = specialcase.name;
@ -516,7 +523,7 @@ class GoogleTranslateOption {
let translator = BDFDB.DataUtils.get(this, "engines", "translator");
if (this.translationEngines[translator] && typeof this.translationEngines[translator].func == "function") {
this.isTranslating = true;
this.translationEngines[translator].func.apply(this, [{input, output, text:newtext, specialcase}, finishTranslation]);
this.translationEngines[translator].func.apply(this, [{input, output, text:newtext, specialcase, engine:this.translationEngines[translator]}, finishTranslation]);
}
else finishTranslation("");
}
@ -541,11 +548,65 @@ class GoogleTranslateOption {
}
iTranslateTranslate (data, callback) {
console.log(data)
BDFDB.LibraryRequires.request("https://www.itranslate.com/themes/itranslate2016/assets/webapp/js/main.js", (error, response, result) => {
console.log(error, response, result);
let translate = _ => {
let xml = new XMLHttpRequest();
xml.open("POST", "https://api.itranslate.com/translate/v1");
xml.send(JSON.stringify({
key: data.engine.APIkey,
source: {
dialect: data.input.id,
text: data.text
},
target: {
dialect: data.output.id
}
}));
xml.onreadystatechange = _ => {
if (xml.status == 200) {
if (xml.readyState == 4) {
try {
let response = JSON.parse(xml.responseText);
if (!data.specialcase && response.source && response.source.detected && this.languages[response.source.detected]) {
data.input.name = this.languages[response.source.detected].name;
data.input.ownlang = this.languages[response.source.detected].ownlang;
}
callback(response.target.text);
}
catch (err) {callback("");}
}
}
else callback("");
}
};
if (data.engine.APIkey) translate();
else BDFDB.LibraryRequires.request("https://www.itranslate.com/themes/itranslate2016/assets/webapp/js/main.js", {gzip: true}, (error, response, result) => {
if (!error && result) {
callback("");
let APIkey = /var API_KEY = "(.+)"/.exec(result);
if (APIkey) {
data.engine.APIkey = APIkey[1];
translate();
}
else callback("");
}
else callback("");
});
}
yandexTranslate (data, callback) {
BDFDB.LibraryRequires.request(`https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20191206T223907Z.52bd512eca953a5b.1ec123ce4dcab3ae859f312d27cdc8609ab280de&text=${encodeURIComponent(data.text)}&lang=${data.specialcase || data.input.id == "auto" ? data.output.id : (data.input.id + "-" + data.output.id)}&options=1`, (error, response, result) => {
if (!error && result) {
result = BDFDB.DOMUtils.create(result);
let translation = result.querySelector("text");
let detected = result.querySelector("detected");
if (translation && detected) {
let detectedlang = detected.getAttribute("lang");
if (!data.specialcase && detectedlang && this.languages[detectedlang]) {
data.input.name = this.languages[detectedlang].name;
data.input.ownlang = this.languages[detectedlang].ownlang;
}
callback(translation.innerText);
}
else callback("");
}
else callback("");
});