Update Translator.plugin.js

This commit is contained in:
Mirco Wittrien 2024-01-25 09:40:23 +01:00
parent 45dfa62a83
commit cfb392a09f
1 changed files with 589 additions and 590 deletions

View File

@ -2,7 +2,7 @@
* @name Translator * @name Translator
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 2.6.1 * @version 2.6.2
* @description Allows you to translate Messages and your outgoing Messages within Discord * @description Allows you to translate Messages and your outgoing Messages within Discord
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -14,9 +14,7 @@
module.exports = (_ => { module.exports = (_ => {
const changeLog = { const changeLog = {
"added": {
"Microsoft Translate": "Added"
}
}; };
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class { return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
@ -262,7 +260,7 @@ module.exports = (_ => {
type: "Switch", type: "Switch",
plugin: _this, plugin: _this,
keys: ["general", key], keys: ["general", key],
label: _this.labels[`general_${key}`], label: _this.labels[`general_${key}`] || _this.defaults.general[key].description,
tag: BDFDB.LibraryComponents.FormComponents.FormTags.H5, tag: BDFDB.LibraryComponents.FormComponents.FormTags.H5,
value: _this.settings.general[key] value: _this.settings.general[key]
})), })),
@ -392,7 +390,8 @@ module.exports = (_ => {
addTranslateButton: {value: true, popout: false}, addTranslateButton: {value: true, popout: false},
usePerChatTranslation: {value: true, popout: false}, usePerChatTranslation: {value: true, popout: false},
sendOriginalMessage: {value: false, popout: true}, sendOriginalMessage: {value: false, popout: true},
showOriginalMessage: {value: false, popout: true} showOriginalMessage: {value: false, popout: true},
useSpoilerInOriginal: {value: false, popout: false, description: "Use Spoilers instead of Quotes for the original Message Text"}
}, },
choices: {}, choices: {},
exceptions: { exceptions: {
@ -458,7 +457,7 @@ module.exports = (_ => {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["general", key], keys: ["general", key],
label: this.labels[`general_${key}`], label: this.labels[`general_${key}`] || this.defaults.general[key].description,
value: this.settings.general[key] value: this.settings.general[key]
})); }));
@ -685,7 +684,7 @@ module.exports = (_ => {
if (this.isTranslationEnabled(e.instance.props.channel.id) && e2.methodArguments[0].value) { if (this.isTranslationEnabled(e.instance.props.channel.id) && e2.methodArguments[0].value) {
e2.stopOriginalMethodCall(); e2.stopOriginalMethodCall();
this.translateText(e2.methodArguments[0].value, messageTypes.SENT, (translation, input, output) => { this.translateText(e2.methodArguments[0].value, messageTypes.SENT, (translation, input, output) => {
translation = !translation ? e2.methodArguments[0].value : (this.settings.general.sendOriginalMessage ? (translation + "\n\n> *" + e2.methodArguments[0].value.split("\n").join("*\n> *") + "*") : translation); translation = !translation ? e2.methodArguments[0].value : (this.settings.general.sendOriginalMessage ? (translation + (!this.settings.general.useSpoilerInOriginal ? ("\n\n> *" + e2.methodArguments[0].value.split("\n").join("*\n> *") + "*").replace(/> \*\*\n/g, "> \n") : `\n\n||${e2.methodArguments[0].value}||`)) : translation);
e2.originalMethod(Object.assign({}, e2.methodArguments[0], {value: translation})); e2.originalMethod(Object.assign({}, e2.methodArguments[0], {value: translation}));
}); });
return Promise.resolve({ return Promise.resolve({
@ -880,12 +879,12 @@ module.exports = (_ => {
let oldStrings = orignalContent.split(/\n{0,1}__________________ __________________ __________________\n{0,1}/); let oldStrings = orignalContent.split(/\n{0,1}__________________ __________________ __________________\n{0,1}/);
let strings = translation.split(/\n{0,1}__________________ __________________ __________________\n{0,1}/); let strings = translation.split(/\n{0,1}__________________ __________________ __________________\n{0,1}/);
let oldContent = this.settings.general.showOriginalMessage && (oldStrings.shift() || "").trim(); let oldContent = this.settings.general.showOriginalMessage && (oldStrings.shift() || "").trim();
let content = (strings.shift() || "").trim() + (oldContent ? `\n\n${oldContent}` : ""); let content = (strings.shift() || "").trim() + (oldContent ? (!this.settings.general.useSpoilerInOriginal ? ("\n\n> *" + oldContent.split("\n").join("*\n> *") + "*").replace(/> \*\*\n/g, "> \n") : `\n\n||${oldContent}||`) : "");
let embeds = {}; let embeds = {};
for (let i in message.embeds) { for (let i in message.embeds) {
message.embeds[i].message_id = message.id; message.embeds[i].message_id = message.id;
let oldEmbedString = this.settings.general.showOriginalMessage && (oldStrings.shift() || "").trim(); let oldEmbedString = this.settings.general.showOriginalMessage && (oldStrings.shift() || "").trim();
embeds[message.embeds[i].id] = (strings.shift() || message.embeds[i].rawDescription).trim() + (oldEmbedString ? `\n\n${oldEmbedString}` : ""); embeds[message.embeds[i].id] = (strings.shift() || message.embeds[i].rawDescription).trim() + (oldEmbedString ? (!this.settings.general.useSpoilerInOriginal ? ("\n\n> *" + oldEmbedString.split("\n").join("*\n> *") + "*").replace(/> \*\*\n/g, "> \n") : `\n\n||${oldEmbedString}||`) : "");
} }
translatedMessages[message.id] = {content, embeds, input, output}; translatedMessages[message.id] = {content, embeds, input, output};
BDFDB.MessageUtils.rerenderAll(true); BDFDB.MessageUtils.rerenderAll(true);