GithubHelp home page GithubHelp logo

sdcv's Introduction

What is sdcv?

Interface for sdcv (StartDict console version).

Translate word by sdcv (console version of Stardict), and display translation use posframe or buffer.

Installation

1. Install Stardict and sdcv

To use this extension, you have to install Stardict and sdcv

Linux
sudo aptitude install stardict sdcv -y
MacOS
brew install stardict sdcv

2. Install posframe extension

You can install get it from: https://raw.githubusercontent.com/tumashu/posframe/master/posframe.el

3. Require sdcv.el

Put sdcv.el and posframe.el to your load-path.

And add the following to your .emacs startup file.

(require 'sdcv)

Configuration

(setq sdcv-say-word-p t)               ;say word after translation

(setq sdcv-dictionary-data-dir "startdict_dictionary_directory") ;setup directory of stardict dictionary

(setq sdcv-dictionary-simple-list    ;setup dictionary list for simple search
      '("懒虫简明英汉词典"
        "懒虫简明汉英词典"
        "KDic11万英汉词典"))

(setq sdcv-dictionary-complete-list     ;setup dictionary list for complete search
      '(
        "懒虫简明英汉词典"
        "英汉汉英专业词典"
        "XDICT英汉辞典"
        "stardict1.3英汉辞典"
        "WordNet"
        "XDICT汉英辞典"
        "Jargon"
        "懒虫简明汉英词典"
        "FOLDOC"
        "新世纪英汉科技大词典"
        "KDic11万英汉词典"
        "朗道汉英字典5.0"
        "CDICT5英汉辞典"
        "新世纪汉英科技大词典"
        "牛津英汉双解美化版"
        "21世纪双语科技词典"
        "quick_eng-zh_CN"
        ))

After completing the above configuration, please execute the command sdcv-check to confirm that the dictionary settings is correct, otherwise sdcv will not work because there is no dictionary file in sdcv-dictionary-data-dir.

Usage

Below are commands you can use:

Command Description
sdcv-search-pointer Search around word and display with buffer.
sdcv-search-pointer+ Search around word and display with tooltip.
sdcv-search-input Search input word and display with buffer.
sdcv-search-input+ Search input word and display with tooltip.

Tips:

If current mark is active, sdcv commands will translate region string, otherwise translate word around point.

Dictionary

You can download sdcv dictionary from http://download.huzheng.org/dict.org/

sdcv's People

Contributors

chaochaocui avatar cnsunyour avatar ctrl2wei avatar eshrh avatar loyalpartner avatar manateelazycat avatar renwenshan avatar xfa25e avatar yqu212 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sdcv's Issues

Why does this package need both stardict and sdcv?

I'm on Ubuntu 20.04, and stardict has been removed from its apt repo:

$ sudo apt-get install -y stardict
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package stardict is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'stardict' has no installation candidate

But I noticed the following note in the document of this package:

sudo aptitude install stardict sdcv -y

I'm very confused on this guidance, considering that sdcv in itself can work perfectly, why do we must install stardict at the same time?

Regards,
HY

Suggestion: change outline to ewoc

I noticed that sdcv command provides a --json flag. I think that we could drop outline and make a better and more extensible interface with ewoc library.

Since, there is already a json package, we could use it to parse json output of sdcv. This will be much easier to work with and would eliminate problems with regexp matching of heading. Sometimes, font-locking fails to recognize heading. Like here:

sdcv font lock failure

I can submit a PR

Of course, this means that a lot of code should be rewritten, but the functionality would remain the same.

sdcv prints two non-result lines instead of one.

I the following output intended to be as it appears, o rshould it be only in a single line?

$ sdcv --non-interactive [ðə ,ðɪ]
Nothing similar to [ðə, sorry :(
Nothing similar to ,ðɪ], sorry :(

It matters to me, because my rofi script #37 thinks that a translation was found, because the output has more than a single line.

$ sdcv --non-interactive sdcv,sdcv
Nothing similar to sdcv,sdcv, sorry :(

sdcv-pick-word: Invalid function: return

Got this error when running sdcv-search-pointer+.

Running on MacOS, emacs version:

GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin19.5.0, NS appkit-1894.50 Version 10.15.5 (Build 19F101)) of 2020-10-16

spacemacs下显示不出sdcv-search-pointer+的结果

spacemacs下显示不出sdcv-search-pointer+的结果

环境

os: ubuntu16
emacs: 26.2.0
spacemacs: develop分支

sdcv 配置

    (load-file "~/.spacemacs.d/layers/manaul-install/posframe.el")
    (load-file "~/.spacemacs.d/layers/manaul-install/sdcv.el")
    (setq sdcv-say-word-p nil) 		; do not pronounce 
    (setq sdcv-dictionary-data-dir "~/.stardict/dic") 
    (setq sdcv-dictionary-simple-list
          '(
            "21世纪双语科技词典"
            "懒虫简明英汉词典"
            "英汉汉英专业词典"
            "CDICT5英汉辞典"
            )) 
    (setq sdcv-dictionary-complete-list
          '(
            "21世纪双语科技词典"
            "CDICT5英汉辞典"
            "懒虫简明英汉词典"
            "英汉汉英专业词典"
            )) 
    )
  )

操作

M-x sdcv-check

正常

M-x sdcv-search-pointer+

不正常

效果

M-x sdcv-search-pointer+

显示如下:

emacs-sdcv-cant-display-result

有无可能增加返回上一页的功能

有时候查询全英文词典,会在词条的解释中出现不认识的单词,此时如果按p去查询这个不认识的单词的话,阅读完这个不认识词的解释后,如果有类似返回上一页的功能,返回原来的词条就显得非常方便,有无可能增加类似的功能呢?

buffer类函数翻译入口问题

sdcv-search-detail里把sdcv-search-witch-dictionary(返回翻译结果的string)作为argument传进了start-process,会出错,两个buffer翻译的函数都用不了了。

(let* ((process
            (start-process
             "sdcv" sdcv-buffer-name sdcv-program
(sdcv-search-witch-dictionary word sdcv-dictionary-complete-list))))

查了一下,Emacs下查词典(StarDict篇) 下的作者提供了一个方案(见第一个评论)。我稍微更改,加上了原本的data-dir选项:

(let* ((process
            (start-process-shell-command
             "sdcv" sdcv-buffer-name 
             (format "%s -n %s %s --data-dir=%s"
                     sdcv-program
                     (mapconcat (lambda (dict)
                                  (concat "-u '" dict "'"))
                                sdcv-dictionary-complete-list " ")
                     word
                     sdcv-dictionary-data-dir)
             )))

这样子倒是可以,但既然两个posframe翻译函数走的是sdcv-search-with-simple -> sdcv-search-witch-dictionary -> sdcv-translate-result,那buffer的翻译函数也走这个会比较一致吧。所以我改成了:

(with-current-buffer (get-buffer-create sdcv-buffer-name)
    (setq buffer-read-only nil)
    (erase-buffer)
    (setq sdcv-current-translate-object word)
    (insert (sdcv-translate-result 
             word
             sdcv-dictionary-complete-list))
    (sdcv-goto-sdcv)
    (sdcv-mode-reinit)
)

你看看哪个比较好,我提一个PR?这个翻译很好用,谢谢!

sdcv-search-pointer returns empty *SDCV* buffer

I use latest sdcv.el. My Emacs config is DOOM emacs and emacs version is 28.

sdcv-search-pointer+ works properly and shows a childframe with some content, but sdcv-search-pointer shows an empty SDCV buffer, not sure why..

Display wrong encode characters

Long time ago i use it normally. I've just upgraded to new version recently, characters are encoded wrongly as image below
Screenshot from 2020-06-09 15-04-33
I searched commit log and saw the encode was fixed to zh_CN. I try changing it to en_US and it works like a charm.
Can you add an option for customize this LANG env.

sdcv failed to work on Ubuntu 20.04.

On Ubuntu 20.04, I installed the latest sdcv and added some dictionaries as shown below:

werner@X10DAi:~$ sdcv -v
Console version of Stardict, version 0.5.3
werner@X10DAi:~$ sdcv -l
Dictionary's name   Word count
懒虫简明英汉词典    452185
Webster's Third New International Dictionary, Unabridged (En-En)    296190

The Emacs configuration for sdcv is as follows:

(use-package sdcv
  :demand t
  :straight (:host github :repo "manateelazycat/sdcv")
  :config
  ;https://github.com/manateelazycat/sdcv#configuration
  (setq ;sdcv-say-word-p t        ;say word after translation
        sdcv-dictionary-data-dir "~/.stardict/dic" ;setup directory of stardict dictionary
        sdcv-dictionary-simple-list    ;setup dictionary list for simple search
        '("Webster's Third New International Dictionary, Unabridged (En-En)"
          "懒虫简明英汉词典"
          )

        sdcv-dictionary-complete-list ;setup dictionary list for complete search
        '("Webster's Third New International Dictionary, Unabridged (En-En)"
          "懒虫简明英汉词典"
        )))

With the point on a word, say, "you", I issue the command `M-x sdcv-search-point RET', but nothing returned:

image

Any hints for this problem?

Regards,
HY

cannot install stardict with brew

macos: brew install stardict sdcv
Return:
Warning: No available formula with the name "stardict"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

辞典文件夹路径问题

系统:manjaro
Emacs 版本:28.1
配置:Doom Emacs

之前是直接用

(package! sdcv)

进行安装的,发现是非常久的远古版本但还是能正常使用,之后用

(package! sdcv
  :recipe (:host github :repo "manateelazycat/sdcv"))

安装新版,发现无法正常使用,报错辞典文件夹不存在,参照 这个问答 把文件夹路径改成

(setq sdcv-dictionary-data-dir (expand-file-name "~/.stardict/dic"))

才能正常工作……

rofi (dmenu) script

Good evening,

I want to contribute a rofi script which makes use of sdcv.

#!/bin/sh

# Name    : sdcv-rofi
# About   : This is a rofi script to translate words and phrases with sdcv.
# Version : 2024-05-29
# License : MIT;
# Author  : Schimon Jehudah Zackary;

version="0.1"

if [ "$1" = "--help" ] ; then
  echo "Translate words or phrases and copy the results to clipboard."
  echo "rofi and sdcv and xclip or xsel or wl-paste must be installed."
  exit 0
elif [ "$1" = "--version" ] ; then
  echo "sdcv-dmenu version $version"
  exit 0
fi

case $XDG_SESSION_TYPE in
  x11 | tty | /dev/pts/1)
    if [ -x "$(command -v xsel)" ]; then
      clipboard=$(xsel)
    elif [ -x "$(command -v xclip)" ]; then
      clipboard=$(xclip -out)
    else
      echo "xclip is required to use clipboard."
    fi
    ;;
  wayland)
    if [ -x "$(command -v wl-paste)" ]; then
      clipboard=$(wl-paste --primary)
    else
      echo "wl-paste is required to use clipboard."
    fi
    ;;
  *)
    echo "Could not determine display server."
    echo "Defaulting to xclip."
    if [ -x "$(command -v xclip)" ]; then
      clipboard=$(xclip -out)
    else
      echo "wl-paste is required to use clipboard."
    fi
    ;;
esac

sdcv_translate() {
  chosen_option=$(echo -e "$clipboard\nClose" | rofi -dmenu -i -p "sdcv" -mesg "Enter a word or phrase to translate.");
  
  if [ -z "$chosen_option" ] || [ "$chosen_option" == "Close" ]; then
    exit 0
  else
    phrase=$chosen_option;
  fi
  
  #translation=$(sdcv --non-interactive --exact-search --use-dict="Babylon English-Hebrew" $phrase);
  #chosen_option=$(echo -e "Copy\nClose" | sed 's/<[^>]*>//g' | rofi -dmenu -i -p "Translation" -mesg $translation);
  message=$(sdcv --non-interactive $phrase | head -n 1);
  translation=$(sdcv --non-interactive $phrase | sed 1d);
  # 
  # Report to sdcv
  # $ sdcv --non-interactive [ðə ,ðɪ]
  # Nothing similar to [ðə, sorry :(
  # Nothing similar to ,ðɪ], sorry :(
  # 
  if [ -z "$translation" ]; then
    chosen_option=$(echo -e "Translate\nClose" | sed 's/<[^>]*>//g' | rofi -dmenu -i -p "sdcv" -mesg "$message");
  else
    chosen_option=$(echo -e "Close\n\n$translation\n\nCopy The Whole Entry" | sed 's/<[^>]*>//g' | rofi -dmenu -i -p "Translation" -mesg "$message Select a line to copy.");
  fi
  
  if [ "$chosen_option" == "Translate" ]; then
    sdcv_translate
  elif [ -z "$chosen_option" ] || [ "$chosen_option" == "Close" ]; then
    exit 0
  elif [ "$chosen_option" == "Copy The Whole Entry" ]; then
    # FIXME Result is copied into a single line
    echo $translation | xclip -in -selection clipboard;
  else
    echo $chosen_option | xclip -in -selection clipboard;
  fi
}

sdcv_translate

I have made this script after one of my favourite StarDict software package size has surpassed a 100MB, and which motivated me to find and alternative. I have found sdcv and then made a rofii script.

I suggest to add this script to this repository or to a new repository of manateelazycat/sdcv-rofi.

Kind regards,
Schimon

unicode parsing problem?

My emacs buffer or posframe does not correctly display special characters or symbols (ex. '\u2022' instead of bullet symbol) unlike in the picture from your README.
When I run sdcv command from the shell inside emacs, it does print correctly. What might be wrong? any suggestion?
Thanks

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.