【求助】go-translate 自定义函数 中->英 翻译被符号截断

想定义一个函数,借助go-translate来达到批量将注释由中文翻译到英文,或者将英文注释翻译为中文。 目前是想先在单行实现注释的中文转英文。

函数代码:

(defun translate-comment-and-replace ()
  "Translate the comment on the current line and replace only the comment with the translated result."
  (interactive)
  ;; 获取光标所在行的内容
  (let* ((line-content (thing-at-point 'line t))
         ;; 提取注释部分(以 `;;` 或 `//` 或其他注释符号开头的部分)
         (comment (if (string-match ".*\\(;+\\|//\\|#\\)\\(.*\\)" line-content)
                      (match-string 2 line-content)
                    nil))
         ;; 提取非注释部分
         (non-comment (if comment
                          (replace-regexp-in-string (concat "\\(;+\\|//\\|#\\)" comment) "" line-content)
                        line-content)))
    ;; 显示提取后的注释内容
    (when comment
      (message "提取的注释内容为: %s" comment)
      ;; 自定义 ChatGPT 提示,用于翻译注释内容
      (let ((gt-chatgpt-user-prompt-template
             (lambda (text _)
               (format "请将下列注释翻译成英文,并只返回翻译结果:%s" text))))
        ;; 调用 go-translate 进行翻译,并使用 :replace 渲染器
        (gt-start (gt-translator
                   :engines (gt-chatgpt-engine :cache nil)
                   ;; 使用 gt-insert-render 只插入一次翻译结果
                   :render (gt-insert-render
                            :type 'replace
                            :rfmt (lambda (translated-text)
                                    ;; 显示翻译后的结果
                                    (message "翻译后的内容为: %s" translated-text)
                                    ;; 插入翻译结果
                                    translated-text))))))))

预期效果如下:

翻译前:

测试一 ;; 你好,世界

翻译后:

测试一 ;; Hello,World

实际效果如下:

翻译后:

测试一 ;; 你好,World

去掉逗号则正常翻译,除逗号外的其他符号,包括空格都会导致截断。

利用 message 检查,提取后的注释部分还是完整的 你好,世界 ,传递给chatgpt的却只有 世界 ,导致翻译结果不全。