Code Monkey home page Code Monkey logo

youdao-dictionary.el's Introduction

Youdao Dictionary interface for Emacs

http://melpa.org/packages/youdao-dictionary-badge.svg http://stable.melpa.org/packages/youdao-dictionary-badge.svg

youdao-dictionary is a simple Youdao Dictionary (有道词典) interface for Emacs.

Installation

Install youdao-dictionary from MELPA with:

M-x package-install RET youdao-dictionary RET

Setup

Youdao discontinued the free API earlier this year (2023), so this package is no longer ready to use out of the box. You will need to apply for an API on your own.

You can set your api key and secret in ~/.authinfo.gpg or ~/.authinfo, e.g,

machine openapi.youdao.com login 应用ID password 应用秘钥

Alternatively, you can set them in your config, e.g,

;; Change 应用ID and 应用秘钥 to yours
(setq youdao-dictionary-app-key "应用ID"
      youdao-dictionary-secret-key "应用秘钥")

Usage

youdao-dictionary-search-at-point
Search word at point and display result with buffer
youdao-dictionary-search-at-point+
Search word at point and display result with popup-tip
youdao-dictionary-search-at-point-tooltip
Search word at point and display result with tooltip
youdao-dictionary-search-at-point-posframe
Search word at point and display result with posframe
youdao-dictionary-search-from-input
Search word from input and display result with buffer
youdao-dictionary-search-and-replace
Search word at point and display result with popup-menu, replace word with selected translation.
youdao-dictionary-play-voice-at-point
Play voice of word at point (by @snyh)
youdao-dictionary-play-voice-from-input
Play voice of word from input (by @snyh)

Customization

youdao-dictionary-posframe-tip-face
Face for posframe buffer, defaut to inherit tooltip

Sample configuration

;; Enable Cache
(setq url-automatic-caching t)

;; Example Key binding
(global-set-key (kbd "C-c y") 'youdao-dictionary-search-at-point)

;; Integrate with popwin-el (https://github.com/m2ym/popwin-el)
;; (push "*Youdao Dictionary*" popwin:special-display-config)

;; Set file path for saving search history
;; (setq youdao-dictionary-search-history-file "~/.emacs.d/.youdao")

;; Enable Chinese word segmentation support (支持中文分词)
;; (setq youdao-dictionary-use-chinese-word-segmentation t)

Notes: A external Chinese word segmentation tool (e.g. 结巴分词) is needed to enable Chinese word segmentation support. For more info, see chinese-word-at-point.el#prerequisite.

Related tools

ydcv
YouDao Console Version in Python (youdao-dictionary.el is inspired by it)
fanyi
A translate tool in your command line (supports both Youdao and iciba)
go-translate
Powerful translator on Emacs. Supports multiple translation engines such as Google, Bing, deepL, StarDict, Youdao.
bing-dict
Minimalists’ English-Chinese Bing dictionary

youdao-dictionary.el's People

Contributors

et2010 avatar lujun9972 avatar seagle0128 avatar snyh avatar vritser avatar xiaogema avatar xuchunyang avatar yanghaoxie avatar yangsheng6810 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

youdao-dictionary.el's Issues

第二次查找的时候报错

Contacting host: fanyi.youdao.com:80
byte-code: Invalid date: 06-Sep-2045 07:57:42.00 GMT
error in process sentinel: byte-code: Invalid date: 06-Sep-2045 07:57:42.00 GMT
error in process sentinel: Invalid date: 06-Sep-2045 07:57:42.00 GMT
command-execute: Buffer is read-only: #<buffer Messages>

Error message

Dear,

I can only search one time after launching emacs every time. When I search the second time, a error message appeared as:

Contacting host: fanyi.youdao.com:80 byte-code: Invalid date: 13-Jan-2045 01:03:12.00 GMT

What will the problem probably be?
Thanks.

请问兼容 Mac OS/Windows 吗?

如题。

因为我阅读了 README,没有提示系统兼容性的问题。然后我阅读了一下代码,发现有可能需要用到某些系统特性,不知道是否兼容 Mac OS/Windows 呢?

emacs29.3 不兼容

`doom sync

Synchronizing "default" profile...
Regenerating envvars file
✓ Generated ~/.config/emacs/.local/env
x There was an unexpected runtime error
Message: Symbol's function definition is void
Details: (define-namespace)
Backtrace:
(define-namespace youdao-dictionary- (defconst api-url "http://fanyi.youdao.com/openapi.do?keyf...
(eval-buffer #<buffer load-540008> nil "/home/someone/.config/emacs/.local/straight/build-29.3/...
(load-with-code-conversion "/home/someone/.config/emacs/.local/straight/build-29.3/youdao-dictiona...
(load "/home/someone/.config/emacs/.local/straight/build-29.3/youdao-dictionary/youdao-dictionary-...
(progn (load autoloads-file nil 'nomessage))
(if (file-exists-p autoloads-file) (progn (load autoloads-file nil 'nomessage)))
(let ((autoloads-file (straight--autoloads-file package))) (if (file-exists-p autoloads-file) (...
(straight--load-package-autoloads "youdao-dictionary")
(let ((name (symbol-name package))) (add-to-list 'load-path (directory-file-name (straight--bui...
(let ((package (car tail))) (straight-register-package package) (let ((name (symbol-name packag...
(while tail (let ((package (car tail))) (straight-register-package package) (let ((name (symbol...
(let ((tail (cl-delete-duplicates packages :test #'equal))) (while tail (let ((package (car tai...
! Wrote extended backtrace to ~/.config/emacs/.local/state/logs/cli.doom.240507231005.88833.error
! Script was abruptly aborted, leaving Doom in an incomplete state!

  • Run 'doom sync' to repair it.`

Symbol's function definition is void: auth-source-search

之前我的doom emacs跑得很好,今天doom sync -u升级了一下packages后,启动时报错:

Warning (initialization): An error occurred while loading ‘/Users/mls/.emacs.d/.local/etc/@/init.29.elc’:

Symbol's function definition is void: auth-source-search

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

emacs --debug-init输出信息如下:

Debugger entered--Lisp error: (void-function auth-source-search)
  auth-source-search(:host "openapi.youdao.com" :max 1)
  #f(compiled-function () #<bytecode -0xa6e63f4241c3389>)()
  funcall(#f(compiled-function () #<bytecode -0xa6e63f4241c3389>))
  eval((funcall #'#f(compiled-function () #<bytecode -0xa6e63f4241c3389>)))
  custom-initialize-reset(youdao-dictionary-secret-key (funcall #'#f(compiled-function () #<bytecode -0xa6e63f4241c3389>)))
  custom-declare-variable(youdao-dictionary-secret-key (funcall #'#f(compiled-function () #<bytecode -0xa6e63f4241c3389>)) "Youdao dictionary Secret Key. You can get it from ..." :type string)
  byte-code("\300\301\302\303\304DD\305\306\307%\210\300\310\302\303\311DD\312\306\307%\207" [custom-declare-variable youdao-dictionary-secret-key funcall function #f(compiled-function () #<bytecode -0xa6e63f4241c3389>) "Youdao dictionary Secret Key. You can get it from ..." :type string youdao-dictionary-app-key #f(compiled-function () #<bytecode 0x1272cecba93c6b11>) "Youdao dictionary App Key. You can get it from ai...."] 6)
  load("/Users/mls/.emacs.d/.local/etc/@/init.29.elc" noerror nomessage nosuffix)
  (progn (load init-file-name 'noerror 'nomessage 'nosuffix))
  (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix)))
  (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el")))
  (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))
  (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el")))))
  (condition-case error (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir (format "init.%d.elc" emacs-major-version)))) (setq user-init-file t) (if init-file-name (progn (load init-file-name 'noerror 'nomessage 'nosuffix))) (if (eq user-init-file t) (progn (signal 'doom-nosync-error (list init-file-name)))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while loading `%s':\n\n%s%s%s\n\nTo ..." user-init-file (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'(lambda (s) (prin1-to-string s t)) (cdr error) ", ")) :warning) (setq init-file-had-error t)))
  (let ((debug-on-error debug-on-error-initial)) (condition-case error (if init-file-user (progn (let ((init-file-name (file-name-concat doom-profile-dir ...))) (setq user-init-file t) (if init-file-name (progn (load init-file-name ... ... ...))) (if (eq user-init-file t) (progn (signal ... ...))) (setq user-init-file (concat (string-remove-suffix ".elc" user-init-file) ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while loading `%s':\n\n%s%s%s\n\nTo ..." user-init-file (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'(lambda ... ...) (cdr error) ", ")) :warning) (setq init-file-had-error t))) (or (eq debug-on-error debug-on-error-initial) (progn (setq debug-on-error-should-be-set t) (setq debug-on-error-from-init-file debug-on-error))))
  (let ((debug-on-error-from-init-file nil) (debug-on-error-should-be-set nil) (debug-on-error-initial (if (eq init-file-debug t) 'startup init-file-debug)) (inhibit-null-byte-detection t)) (let ((debug-on-error debug-on-error-initial)) (condition-case error (if init-file-user (progn (let ((init-file-name ...)) (setq user-init-file t) (if init-file-name (progn ...)) (if (eq user-init-file t) (progn ...)) (setq user-init-file (concat ... ".el"))))) ((debug error) (display-warning 'initialization (format-message "An error occurred while loading `%s':\n\n%s%s%s\n\nTo ..." user-init-file (get (car error) 'error-message) (if (cdr error) ": " "") (mapconcat #'... (cdr error) ", ")) :warning) (setq init-file-had-error t))) (or (eq debug-on-error debug-on-error-initial) (progn (setq debug-on-error-should-be-set t) (setq debug-on-error-from-init-file debug-on-error)))) (if debug-on-error-should-be-set (progn (setq debug-on-error debug-on-error-from-init-file))))
  startup--load-user-init-file@init-doom(#f(compiled-function () #<bytecode 0x155f396c086439>) #f(compiled-function () #<bytecode -0x1f3c61addc1ff775>) t)
  apply(startup--load-user-init-file@init-doom (#f(compiled-function () #<bytecode 0x155f396c086439>) #f(compiled-function () #<bytecode -0x1f3c61addc1ff775>) t))
  startup--load-user-init-file(#f(compiled-function () #<bytecode 0x155f396c086439>) #f(compiled-function () #<bytecode -0x1f3c61addc1ff775>) t)
  command-line()
  normal-top-level()

这是什么情况?请教。

BTW:我似乎没有哪里设置使用了youdao-dictionary的地方。

New release?

Any plans to release a new version here on GitHub?

Contacting host: fanyi.youdao.com:80 ERROR

I am having problems to contact to the dictionary server

Contacting host: fanyi.youdao.com:80
prog1: JSON readtable error: 60
Contacting host: fanyi.youdao.com:80
progn: Problem connecting to the server
Contacting host: fanyi.youdao.com:80
progn: Problem connecting to the server
Contacting host: fanyi.youdao.com:80
progn: Problem connecting to the server
Contacting host: melpa.org:80

Contacting host: fanyi.youdao.com:80
youdao-dictionary--parse-response: JSON readtable error: 60
Contacting host: fanyi.youdao.com:80
youdao-dictionary--parse-response: JSON readtable error: 60
Contacting host: fanyi.youdao.com:80
error in process filter: youdao-dictionary--parse-response: JSON readtable error: 60
error in process filter: JSON readtable error: 60

My Emacs version:
GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2023-08-30, modified by Debian

能否支持拼写纠错

如果搜索的英文单词拼写错误,在网页版会显示:

image

但在emacs里会显示:

image

可以让结果跟网页版一致吗?google-translate.el 也会提示拼写错误的。谢谢!

请教关于有道词典异步获取的问题

作者您好,我正在使用您开发的有道词典插件,功能非常好用。我现在有一个个人计划,现有一个生词表,通过org-capture捕获光标下的单词,并且通过您的youdao-dictionary进行翻译,将一些有用的信息插入到生词表中(例如english,词性,中文)。目前我已经可以正确获取我所需要的信息,但是在使用org-capture是出现了问题,问题如下:

captureError

我猜测可能是因为youdao-dictionary是异步请求的,所以在capture获取时没有立即获取到就返回了错误的信息。

下面是我的capture模板

capture-template

下面是我获取对应信息的函数

capture-function

由于我个人水平有限,请教下您如何在capture时做一个小延迟,让youdao-dictionary有返回值后再获取捕获的结果

youdao-dictionary-search-from-input 每次打开新buffer

该函数每次都产生一个新buffer, 当查询多次时会覆盖无辜的window。
多次查询时候应该检查是否已经存在查询结果的buffer, 如果已经存在,就把查询的结果覆盖到此buffer上。

启用代理后不能查词

    (setq url-proxy-services    
        '(("http"     . "localhost:8087")  
          ("https"     . "localhost:8087")    
          ("ftp"     . "localhost:8087")   
          ("no_proxy" . "localhost,127.0.0.1,baidu.com,fanyi.youdao.com")))  

启用上面的代理设置后, 就不能查词了.

Contacting host: localhost:8087   
youdao-dictionary--request: Problem connecting to the server

不能访问服务器了

Contacting host: fanyi.youdao.com:80
youdao-dictionary--parse-response: Problem connecting to the server

feature request:能否支持用posframe来显示结果

能否支持posframe显示呢?
目前支持的问题:
popup,在有些时候会出现显示不对齐(如中英文配置不对齐、开启fill-column-indicator模式后)
tooltip 只能在UI下使用,terminal模式无法使用

emacs 26.x 可以使用posframe, 在UI和terminal模式都可以比较好的支持

使用 pos-tip 模式时,tooltip 显示结果不完全

当使用 pos-tip 模式显示结果时,有时最下面一行的字会有一部分出框。

default

我对 pos-tip 不太了解, 不知道和字体有没有关系。

这一情况仅在使用emacs图形界面时发生,当使用系统(仅在linux下测试)图形界面时没有这一问题。暂时的解决办法就是用系统图形界面:

(setq x-gtk-use-system-tooltips t)

default

feature request: 用pos-tip来显示结果

非常感谢这么好用的软件!希望能够增加用 pos-tip 来显示查词结果的选项,用popup显示的结果有时会和buffer内容混在一起,很乱,就像这样:

default

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.