lorniu / go-translate

Translator on Emacs. Supports multiple engines such as Google, Bing, deepL, ChatGPT, StarDict, Youdao and so on.
GNU General Public License v3.0
275 stars 37 forks source link

Could it be possible to add structured translation result into `gts-task`? #29

Closed rayw000 closed 2 years ago

rayw000 commented 2 years ago

I'm trying to write a render something like

(defclass popup-and-select-render (gts-render) ())

(cl-defmethod gts-out ((_ popup-and-select-render) task)
  (with-slots (ecode result) task
    (if ecode
        (user-error "%s" result)
      ;; do something with a structured translation list
      )))

Is there a slot of gts-task which provides structured translation result list? It could be something like

'((google "<original text>" "<translated text>")
  (google-rpc "<original text>" "<translated text>")
  (bing "<original text>" "<translated text>"))

I didn't find one. It would be useful when popping a selectable list to users and letting them choose their favorite one to insert into a buffer.

Thank you!

lorniu commented 2 years ago

You should override gts-me-out if choosing from one translate.

Then you can get all translate task/results like this:

(defmethod gts-me-out ((_ popup-and-select-render) translator task)
  (when (= (oref translator state) 3)
    (cl-loop for task in (oref translator task-queue)
             for result = (format "%s" (oref task result))
             for from = (oref task from)
             for to = (oref task to)
             ...
    )))

Code like this.