Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] add support for copying the translated text #7

Open
yuchen-lea opened this issue Mar 12, 2024 · 2 comments
Open

[feature request] add support for copying the translated text #7

yuchen-lea opened this issue Mar 12, 2024 · 2 comments

Comments

@yuchen-lea
Copy link

It would be very helpful for taking notes.

@tasteSoGood
Copy link

tasteSoGood commented May 30, 2024

@yuchen-lea Modify the function immersive-translate-paragraph to:

(defun immersive-translate-paragraph ()
  "Translate the current paragraph."
  (interactive)
  (save-excursion
    (unless (immersive-translate-disable-p)
      (when-let* ((paragraph (immersive-translate-join-lin
                              (immersive-translate--get-paragraph)))
                  (content (if (eq immersive-translate-backend 'chatgpt)
                               (immersive-translate-chatgpt-create-prompt paragraph)
                             paragraph))
                  (ov t))
        (immersive-translate-end-of-paragraph)
        (if (immersive-translate--cache-p content)
            (let ((translation (immersive-translate--cache-get content)))
              (progn
                (kill-new translation) ;; copy the translated result to kill-ring
                (immersive-translate--add-ov translation)))
          (setq ov (make-overlay (1- (point)) (point)))
          (overlay-put ov
                       'after-string
                       immersive-translate-pending-message)
          (immersive-translate-do-translate content))))))

while overlay shows, the translation results will copy to the kill-ring instantly.

@yuchen-lea
Copy link
Author

Thanks for the suggestion, but I prefer that the translated text could be manually selected and then copied like the original text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants