Listen to last source or target again
theottm opened this issue · 0 comments
Hi, thanks for the very cool package!
I often want to listen to the translation again and again. But I find it inconvenient to go to switch to the *Google Translate*
buffer. So I wrote a small utility to trigger the listening form the last translation.
It relies on getting the data put in the text properties of the Listen
buttons. So it is kind of bound to the default UI, which is not so good. I would rather have a UI independent version, but it doesn't seem like the data of the last translation gets saved somewhere else. What do you think ? Did I miss something ?
Anyway here is the code if someone is interested in using this.
;; Replay sound of last translation
(defun google-translate-listen-again--from-button-at-point ()
(let ((language (get-text-property (point) 'language))
(text (get-text-property (point) 'text)))
(google-translate-listen-translation language text)))
(defun google-translate-listen-again--goto-first-button ()
(beginning-of-buffer)
(search-forward "Listen"))
(defun google-translate-listen-again--goto-second-button ()
(beginning-of-buffer)
(search-forward "Listen")
(search-forward "Listen"))
(defun google-translate-listen-again--after-goto (goto-func)
(with-current-buffer "*Google Translate*"
(save-excursion
(funcall goto-func)
(google-translate-listen-again--from-button-at-point))))
(defun google-translate-listen-again-source ()
(interactive)
(google-translate-listen-again--after-goto
#'google-translate-listen-again--goto-first-button))
(defun google-translate-listen-again-target ()
(interactive)
(google-translate-listen-again--after-goto
#'google-translate-listen-again--goto-second-button))
You can then just bind google-translate-listen-again-source/target to a key to quickly listen to the last translation.