Skip to content

jiahut/emacs-immersive-translate

 
 

Repository files navigation

immersive-translate: Immersive Bilingual Translation

https://melpa.org/packages/immersive-translate-badge.svg

中文文档

Introductions

Inspired by immersive-translate/immersive-translate, I have implemented similar functionality in Emacs.

Screenshots

elfeed

images/screenshots/elfeed.png

nov

images/screenshots/nov.png

info

images/screenshots/info.png

helpful/help

images/screenshots/help.png

Installation

  1. You need to install curl on your device first. If you want to use the translate-shell backend, you also need to install translate-shell.
  2. M-x package-install RET gptel RET
(require 'immersive-translate)
(add-hook 'elfeed-show-mode-hook #'immersive-translate-setup)
(add-hook 'nov-pre-html-render-hook #'immersive-translate-setup)
;; use Baidu Translation
(setq immersive-translate-backend 'baidu
      immersive-translate-baidu-appid "your-appid")

;; use ChatGPT
;; (setq immersive-translate-backend 'chatgpt
;;       immersive-translate-chatgpt-host "api.openai.com")

;; use translate-shell
;; (setq immersive-translate-backend 'trans)

Usage

  • immersive-translate-buffer

    Translate the current buffer. Note: This may consume a large number of tokens.

  • immersive-translate-paragraph

    Translate the current paragraph.

  • immersive-translate-clear

    Clear all translated text.

  • immersive-translate-auto-mode

    Translate, when enabled, automatically translate the visible portion of the current window.

    Note: Some translation services (e.g. baidu translation) has QPS(Queries Per Second) limits, so it is recommended to use immersive-translate-auto-mode instead of immersive-translate-buffer while using these services.

    • immersive-translate-abort

    Stop all ongoing translation processes in the current buffer.

Customization

  • immersive-translate-backend

    The translation backend used. See API setting for details.

    Currently available translation services:

  • immersive-translate-auto-idle

    After enabling immersive-translate-auto-mode, the Emacs idle time required for the next translation to be executed.

  • immersive-translate-exclude-shr-tag

    The text contained in the tags of this variable will not be translated. This variable applies to all buffers generated by shr.el, such as buffers in elfeed-show-mode, nov-mode, and mu4e-view-mode.

  • immersive-translate-chatgpt-system-prompt

    System prompt used by ChatGPT.

  • immersive-translate-chatgpt-user-prompt

    User prompt used by ChatGPT.

  • immersive-translate-disable-predicates

    When the current paragraph does not need to be translated, return t. These functions in this list do not accept any parameters.

  • immersive-translate-pending-message

    Text displayed before the translation results are returned.

  • immersive-translate-failed-message

    Text displayed when translation fails.

See M-x customize-group RET immersive-translate RET for details.

API setting

The translation service of this plugin requires you to apply for the corresponding API key of the service in order to use it. For more details, please refer to Translation Service API Application

This plugin retrieves the user’s key through the built-in auth-source.el.

  1. ChatGPT

    Assuming your immersive-translate-chatgpt-host is “api.openai.com” and the API key is 123456, add the following text to ~/.authinfo:

    machine api.openai.com login apikey password 123456
        
  2. Baidu Translate

    Assuming your immersive-translate-baidu-appid is “foobar” and the API key is 123456, add the following text to ~/.authinfo:

    machine fanyi-api.baidu.com login foobar password 123456
        
  3. DeepL

    Assuming your API key is 123456, add the following text to ~/.authinfo:

    machine deepl.com login apikey password 123456
        

Add a new translation backend (PRs welcome!)

Add online translation service

If you want to add new translation services, you can check the variables immersive-translate-curl-get-translation-alist and immersive-translate-curl-get-args-alist.

The function in the variable immersive-translate-curl-get-args-alist is used to construct the input parameters required when making a request.

The function in the variable immersive-translate-curl-get-translation-alist is used to parse the translation results returned by curl.

Add local translation services

See immersive-translate-trans.el

About

Immersive-translate provides bilingual simultaneous display and translation of any text in Emacs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 100.0%