From 79a9069debe67d099f9fc7c9725f3df01f50131f Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Fri, 3 Jan 2025 10:24:50 +0100
Subject: [PATCH] Add `t` hotkey for post translations (#33441)

---
 app/javascript/mastodon/components/status.jsx                | 1 +
 .../mastodon/features/keyboard_shortcuts/index.jsx           | 4 ++++
 app/javascript/mastodon/features/status/index.jsx            | 5 +++++
 app/javascript/mastodon/features/ui/index.jsx                | 1 +
 app/javascript/mastodon/locales/en.json                      | 1 +
 5 files changed, 12 insertions(+)

diff --git a/app/javascript/mastodon/components/status.jsx b/app/javascript/mastodon/components/status.jsx
index a2759b834..2be3b9428 100644
--- a/app/javascript/mastodon/components/status.jsx
+++ b/app/javascript/mastodon/components/status.jsx
@@ -384,6 +384,7 @@ class Status extends ImmutablePureComponent {
       toggleHidden: this.handleHotkeyToggleHidden,
       toggleSensitive: this.handleHotkeyToggleSensitive,
       openMedia: this.handleHotkeyOpenMedia,
+      onTranslate: this.handleTranslate,
     };
 
     let media, statusAvatar, prepend, rebloggedByText;
diff --git a/app/javascript/mastodon/features/keyboard_shortcuts/index.jsx b/app/javascript/mastodon/features/keyboard_shortcuts/index.jsx
index e34295848..285f0ea7c 100644
--- a/app/javascript/mastodon/features/keyboard_shortcuts/index.jsx
+++ b/app/javascript/mastodon/features/keyboard_shortcuts/index.jsx
@@ -66,6 +66,10 @@ class KeyboardShortcuts extends ImmutablePureComponent {
                 <td><kbd>enter</kbd>, <kbd>o</kbd></td>
                 <td><FormattedMessage id='keyboard_shortcuts.enter' defaultMessage='to open status' /></td>
               </tr>
+              <tr>
+                <td><kbd>t</kbd></td>
+                <td><FormattedMessage id='keyboard_shortcuts.translate' defaultMessage='to translate a post' /></td>
+              </tr>
               <tr>
                 <td><kbd>e</kbd></td>
                 <td><FormattedMessage id='keyboard_shortcuts.open_media' defaultMessage='to open media' /></td>
diff --git a/app/javascript/mastodon/features/status/index.jsx b/app/javascript/mastodon/features/status/index.jsx
index 8da3d7e11..4b9e035a5 100644
--- a/app/javascript/mastodon/features/status/index.jsx
+++ b/app/javascript/mastodon/features/status/index.jsx
@@ -474,6 +474,10 @@ class Status extends ImmutablePureComponent {
     this.handleToggleMediaVisibility();
   };
 
+  handleHotkeyTranslate = () => {
+    this.handleTranslate(this.props.status);
+  };
+
   handleMoveUp = id => {
     const { status, ancestorsIds, descendantsIds } = this.props;
 
@@ -650,6 +654,7 @@ class Status extends ImmutablePureComponent {
       toggleHidden: this.handleHotkeyToggleHidden,
       toggleSensitive: this.handleHotkeyToggleSensitive,
       openMedia: this.handleHotkeyOpenMedia,
+      onTranslate: this.handleHotkeyTranslate,
     };
 
     return (
diff --git a/app/javascript/mastodon/features/ui/index.jsx b/app/javascript/mastodon/features/ui/index.jsx
index 052ac0ac5..bfc540a33 100644
--- a/app/javascript/mastodon/features/ui/index.jsx
+++ b/app/javascript/mastodon/features/ui/index.jsx
@@ -126,6 +126,7 @@ const keyMap = {
   toggleHidden: 'x',
   toggleSensitive: 'h',
   openMedia: 'e',
+  onTranslate: 't',
 };
 
 class SwitchingColumnsArea extends PureComponent {
diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json
index 2a4258a7d..cf5834835 100644
--- a/app/javascript/mastodon/locales/en.json
+++ b/app/javascript/mastodon/locales/en.json
@@ -457,6 +457,7 @@
   "keyboard_shortcuts.toggle_hidden": "Show/hide text behind CW",
   "keyboard_shortcuts.toggle_sensitivity": "Show/hide media",
   "keyboard_shortcuts.toot": "Start a new post",
+  "keyboard_shortcuts.translate": "to translate a post",
   "keyboard_shortcuts.unfocus": "Unfocus compose textarea/search",
   "keyboard_shortcuts.up": "Move up in the list",
   "lightbox.close": "Close",