Update Translator.plugin.js
This commit is contained in:
parent
5f53f2c0a2
commit
78f2d60a8b
|
@ -2,7 +2,7 @@
|
||||||
* @name Translator
|
* @name Translator
|
||||||
* @author DevilBro
|
* @author DevilBro
|
||||||
* @authorId 278543574059057154
|
* @authorId 278543574059057154
|
||||||
* @version 2.4.1
|
* @version 2.4.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,11 +14,7 @@
|
||||||
|
|
||||||
module.exports = (_ => {
|
module.exports = (_ => {
|
||||||
const changeLog = {
|
const changeLog = {
|
||||||
"added": {
|
|
||||||
"Translated Labels": "Translated the Config Popout to all Discord Languages",
|
|
||||||
"Server Specific Translation": "Same as the Channel Specific Translations just for Servers",
|
|
||||||
"Remember Enable State": "Saves the enable State for Translation States"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -390,19 +386,19 @@ module.exports = (_ => {
|
||||||
};
|
};
|
||||||
for (let m in messageTypes) this.defaults.choices[messageTypes[m]] = {value: Object.keys(languageTypes).reduce((newObj, l) => (newObj[languageTypes[l]] = defaultLanguages[l], newObj), {})};
|
for (let m in messageTypes) this.defaults.choices[messageTypes[m]] = {value: Object.keys(languageTypes).reduce((newObj, l) => (newObj[languageTypes[l]] = defaultLanguages[l], newObj), {})};
|
||||||
|
|
||||||
this.patchedModules = {
|
this.modulePatches = {
|
||||||
before: {
|
before: [
|
||||||
ChannelTextAreaForm: "render",
|
"ChannelTextAreaContainer",
|
||||||
ChannelEditorContainer: "render",
|
"ChannelTextAreaEditor",
|
||||||
Embed: "render"
|
"Embed",
|
||||||
},
|
"MessageReply",
|
||||||
after: {
|
"Messages"
|
||||||
ChannelTextAreaButtons: "type",
|
],
|
||||||
Messages: "type",
|
after: [
|
||||||
MessageReply: "default",
|
"ChannelTextAreaButtons",
|
||||||
MessageContent: "type",
|
"Embed",
|
||||||
Embed: "render"
|
"MessageContent"
|
||||||
}
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.css = `
|
this.css = `
|
||||||
|
@ -654,8 +650,9 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannelTextAreaForm (e) {
|
processChannelTextAreaContainer (e) {
|
||||||
BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {instead: e2 => {
|
if (e.instance.props.type != BDFDB.DiscordConstants.ChannelTextAreaTypes.NORMAL && e.instance.props.type != BDFDB.DiscordConstants.ChannelTextAreaTypes.NORMAL_WITH_ACTIVITY) return;
|
||||||
|
BDFDB.PatchUtils.patch(this, e.instance.props, "onSubmit", {instead: e2 => {
|
||||||
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) => {
|
||||||
|
@ -671,7 +668,7 @@ module.exports = (_ => {
|
||||||
}}, {force: true, noCache: true});
|
}}, {force: true, noCache: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannelEditorContainer (e) {
|
processChannelTextAreaEditor (e) {
|
||||||
if (this.isTranslationEnabled(e.instance.props.channel.id) && isTranslating) e.instance.props.disabled = true;
|
if (this.isTranslationEnabled(e.instance.props.channel.id) && isTranslating) e.instance.props.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,11 +682,11 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessages (e) {
|
processMessages (e) {
|
||||||
e.returnvalue.props.children.props.channelStream = [].concat(e.returnvalue.props.children.props.channelStream);
|
e.instance.props.channelStream = [].concat(e.instance.props.channelStream);
|
||||||
for (let i in e.returnvalue.props.children.props.channelStream) {
|
for (let i in e.instance.props.channelStream) {
|
||||||
let message = e.returnvalue.props.children.props.channelStream[i].content;
|
let message = e.instance.props.channelStream[i].content;
|
||||||
if (message) {
|
if (message) {
|
||||||
if (BDFDB.ArrayUtils.is(message.attachments)) this.checkMessage(e.returnvalue.props.children.props.channelStream[i], message);
|
if (BDFDB.ArrayUtils.is(message.attachments)) this.checkMessage(e.instance.props.channelStream[i], message);
|
||||||
else if (BDFDB.ArrayUtils.is(message)) for (let j in message) {
|
else if (BDFDB.ArrayUtils.is(message)) for (let j in message) {
|
||||||
let childMessage = message[j].content;
|
let childMessage = message[j].content;
|
||||||
if (childMessage && BDFDB.ArrayUtils.is(childMessage.attachments)) this.checkMessage(message[j], childMessage);
|
if (childMessage && BDFDB.ArrayUtils.is(childMessage.attachments)) this.checkMessage(message[j], childMessage);
|
||||||
|
@ -708,61 +705,55 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessageReply (e) {
|
processMessageReply (e) {
|
||||||
if (e.returnvalue && e.returnvalue.props && e.returnvalue.props.children) {
|
if (!e.instance.props.referencedMessage || !translatedMessages[e.instance.props.referencedMessage.message.id]) return;
|
||||||
let referencedMessage = BDFDB.ObjectUtils.get(e, "returnvalue.props.children.props.referencedMessage.message");
|
e.instance.props.referencedMessage = Object.assign({}, e.instance.props.referencedMessage);
|
||||||
if (referencedMessage && translatedMessages[referencedMessage.id]) {
|
e.instance.props.referencedMessage.message = new BDFDB.DiscordObjects.Message(e.instance.props.referencedMessage.message);
|
||||||
e.returnvalue.props.children.props.referencedMessage = Object.assign({}, e.returnvalue.props.children.props.referencedMessage);
|
e.instance.props.referencedMessage.message.content = translatedMessages[e.instance.props.referencedMessage.message.id].content;
|
||||||
e.returnvalue.props.children.props.referencedMessage.message = new BDFDB.DiscordObjects.Message(e.returnvalue.props.children.props.referencedMessage.message);
|
|
||||||
e.returnvalue.props.children.props.referencedMessage.message.content = translatedMessages[referencedMessage.id].content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessageContent (e) {
|
processMessageContent (e) {
|
||||||
if (e.instance.props.message) {
|
if (!e.instance.props.message) return;
|
||||||
let translation = translatedMessages[e.instance.props.message.id];
|
let translation = translatedMessages[e.instance.props.message.id];
|
||||||
if (translation && translation.content) e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
if (translation && translation.content) e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||||
text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.LibraryStrings.to} ${BDFDB.LanguageUtils.getName(translation.output)}`,
|
text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.LibraryStrings.to} ${BDFDB.LanguageUtils.getName(translation.output)}`,
|
||||||
tooltipConfig: {style: "max-width: 400px"},
|
tooltipConfig: {style: "max-width: 400px"},
|
||||||
|
children: BDFDB.ReactUtils.createElement("span", {
|
||||||
|
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated),
|
||||||
children: BDFDB.ReactUtils.createElement("span", {
|
children: BDFDB.ReactUtils.createElement("span", {
|
||||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated),
|
className: BDFDB.disCN.messageedited,
|
||||||
children: BDFDB.ReactUtils.createElement("span", {
|
children: `(${this.labels.translated_watermark})`
|
||||||
className: BDFDB.disCN.messageedited,
|
|
||||||
children: `(${this.labels.translated_watermark})`
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}));
|
})
|
||||||
}
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
processEmbed (e) {
|
processEmbed (e) {
|
||||||
if (e.instance.props.embed && e.instance.props.embed.message_id) {
|
if (!e.instance.props.embed || !e.instance.props.embed.message_id) return;
|
||||||
let translation = translatedMessages[e.instance.props.embed.message_id];
|
let translation = translatedMessages[e.instance.props.embed.message_id];
|
||||||
if (translation && Object.keys(translation.embeds).length) {
|
if (translation && Object.keys(translation.embeds).length) {
|
||||||
if (!e.returnvalue) e.instance.props.embed = Object.assign({}, e.instance.props.embed, {
|
if (!e.returnvalue) e.instance.props.embed = Object.assign({}, e.instance.props.embed, {
|
||||||
rawDescription: translation.embeds[e.instance.props.embed.id],
|
rawDescription: translation.embeds[e.instance.props.embed.id],
|
||||||
originalDescription: e.instance.props.embed.originalDescription || e.instance.props.embed.rawDescription
|
originalDescription: e.instance.props.embed.originalDescription || e.instance.props.embed.rawDescription
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.embeddescription]]});
|
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.embeddescription]]});
|
||||||
if (index > -1) children[index].props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
if (index > -1) children[index].props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||||
text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.getName(translation.output)}`,
|
text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.getName(translation.output)}`,
|
||||||
tooltipConfig: {style: "max-width: 400px"},
|
tooltipConfig: {style: "max-width: 400px"},
|
||||||
|
children: BDFDB.ReactUtils.createElement("span", {
|
||||||
|
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated),
|
||||||
children: BDFDB.ReactUtils.createElement("span", {
|
children: BDFDB.ReactUtils.createElement("span", {
|
||||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated),
|
className: BDFDB.disCN.messageedited,
|
||||||
children: BDFDB.ReactUtils.createElement("span", {
|
children: `(${this.labels.translated_watermark})`
|
||||||
className: BDFDB.disCN.messageedited,
|
|
||||||
children: `(${this.labels.translated_watermark})`
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}));
|
})
|
||||||
}
|
}));
|
||||||
}
|
|
||||||
else if (!e.returnvalue && e.instance.props.embed.originalDescription) {
|
|
||||||
e.instance.props.embed = Object.assign({}, e.instance.props.embed, {rawDescription: e.instance.props.embed.originalDescription});
|
|
||||||
delete e.instance.props.embed.originalDescription;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!e.returnvalue && e.instance.props.embed.originalDescription) {
|
||||||
|
e.instance.props.embed = Object.assign({}, e.instance.props.embed, {rawDescription: e.instance.props.embed.originalDescription});
|
||||||
|
delete e.instance.props.embed.originalDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleTranslation (channelId) {
|
toggleTranslation (channelId) {
|
||||||
|
|
Loading…
Reference in New Issue