Skip to content

Commit

Permalink
feat(Translator): add context menu item (needs testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Socketlike committed Aug 21, 2024
1 parent 5bccffd commit c0c724f
Show file tree
Hide file tree
Showing 2 changed files with 2,262 additions and 2,606 deletions.
14 changes: 14 additions & 0 deletions plugins/Translator/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { APIMessage } from 'discord-api-types/v9';

import { Injector, webpack } from 'replugged';
import { fluxDispatcher, i18n, messages, toast } from 'replugged/common';
import { ContextMenu } from 'replugged/components';
import { ContextMenuTypes } from 'replugged/types';

import { TranslateButton, TranslateIcon, TranslateOffIcon, TranslatedTag } from './components';
import { config, events, logger } from './util';
Expand Down Expand Up @@ -86,6 +88,18 @@ export const start = async (): Promise<void> => {
: void translateMessage(message),
}));

injector.utils.addMenuItem(ContextMenuTypes.Message, ({ message }: { message: APIMessage }) => (
<ContextMenu.MenuItem
id='translate-message'
label={originalCache.has(message.id) ? 'Untranslate' : 'Translate'}
action={() =>
originalCache.has(message.id)
? untranslateMessage(message.id)
: void translateMessage(message)
}
/>
));

injector.instead(messages, 'sendMessage', async (args, orig) => {
if (config.get('sendTranslateEnabled'))
args[1].content = (await _translate(args[1].content, true)).text;
Expand Down
Loading

0 comments on commit c0c724f

Please sign in to comment.