The Ultimate offline Dictionary with Dictd
Installation dict in Arch Linux
-
dictd installation Follow instruction here.
123sudo pacamn -S dictd -
Install dictionary database for AUR repository (search dictd).
123pacaur -y dict-devils dict-foldoc dict-gcide dict-wikt-en-all dict-wnThere are list of bilingual dictionaries from freedict are available from AUR.
-
Gather offline dictionary databases There is a old tutorial about how to set it up, but ftp server for all the dictionary databases are down permanently. After a long research, I found that you can retrieve them from file watch, some of which are pre-formatted.
12345./configuremakemake dbNote 1: If encounter following error when execute make. just to go to dictfmt.c file (line 467, or whatever line it prompts) add ; after skip:, inspired from here.
123456789makegcc -Wall -DHAVE_CONFIG_H -I. -g -O -o dictfmt dictfmt.cdictfmt.c: In function ‘main’:dictfmt.c:467:2: error: label at end of compound statementskip:^~~~make: *** [Makefile:212: dictfmt] Error 1Note 2: I could not find the law dictionary (dict-bouvier) anywhere; what I ends up doing is the install it on Ubuntun copy the database files over to my Arch Linux.
12345#Installing English Thesaurus database (moby-thesaurus):sudo apt-get install dict-moby-thesaurussudo apt-get install dict-buovier -
update dictd.conf
123456# ...database web1913 { data "/opt/public/dict-dbs/jargon.dict.dz"index "/opt/public/dict-dbs/jargon.index" }# ... -
Restart dictd
1234dict -Isudo systemctl restart dictd.service #after any change to dict.conf or dictd.conf files
Dictionary Lookup with Goldendict and dictd server
Once the dictionaries have been installed, and dictd has been configured, goldendict can be configured to access the dictd dictionary databases by following these steps:
- Press F3 to bring up the “Dictionaries” window.
- Click on the “DICT servers” tab
- Click “Add…”
- Click to put a checkmark under “Enabled”
- Double click under “Address” and type: dict://localhost. Make sure to change localhost if dictd is running on another server.
- And finally click “OK”.
Access through web browser
see instruction here, and sample site. a perl CGI one here. WWW Frontends for DICT Servers.
Note: Please configure dict.conf (NOT dictd.conf) according.
Access from Emacs with builtin dictionary.el
There is a dictionary.el is present with XEmacs distribution. M-x dictionary RET
The Resources
Emacs init
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;dict-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (autoload 'dictionary-search "dictionary" "Ask for a word and search it in all dictionaries" t) (autoload 'dictionary-match-words "dictionary" "Ask for a word and search all matching words in the dictionaries" t) (autoload 'dictionary-lookup-definition "dictionary" "Unconditionally lookup the word at point." t) (autoload 'dictionary "dictionary" "Create a new dictionary buffer" t) (autoload 'dictionary-mouse-popup-matching-words "dictionary" "Display entries matching the word at the cursor" t) (autoload 'dictionary-popup-matching-words "dictionary" "Display entries matching the word at the point" t) (autoload 'dictionary-tooltip-mode "dictionary" "Display tooltips for the current word" t) (unless (boundp 'running-xemacs) (autoload 'global-dictionary-tooltip-mode "dictionary" "Enable/disable dictionary-tooltip-mode for all buffers" t)) ;; key bindings for dictionary.el (global-set-key "\C-cs" 'dictionary-search) (global-set-key "\C-cm" 'dictionary-match-words) |
A few notes on the conversion of the CIA world factbook 2002
The following is paraphrased from the world2 package which I retrieved from file watch.
The CIA world factbook 2002 is available in HTML format in different versions at the CIA website http://www.cia.gov/cia/publications/factbook/ . Unfortunately there are no plaintext / rtf / doc versions available from the CIA server.
The HTML versions differ with regard to maps and other graphical elements which are provided in the fullblown version but are missing in the “low bandwidth version” at http://www.cia.gov/cia/publications/factbook/countrylisting.html which was used for the creation of the dict version. In addition to the country listings the 6 appendices found in the full version are included in the dictionary.
downloading of files
The country listings were downloaded using wget:
1 2 3 4 |
wget -r -l1 \ http://www.cia.gov/cia/publications/factbook/countrylisting.html |
The appendices and the copyright info were downloaded manually and saved to files.
conversion to txt
For html to text conversion html2text was used as lynx -dump does not retain the table structure of the text:
1 2 3 4 5 6 |
for i in *.html do html2text -nobs -width 73 $i >$i.txt done |
html2text does a good job with regard to the text layout but the original HTML format leads after conversion to a two coulumn output where both colums have approximately the same width. Not ideal for this application but it works reasonably well.
pre-formatting
In order not to reinvent the wheel the final formatting to dict format was done by dictfmt. Prior to the dictfmt run the country listings as well as the 6 appendices and the copyright info needed to be cleaned up. This was done manually for the appendices and the copyright info as I considered it not worth the trouble to write a program for this task. The country listings were processed by a small custom preprocessor written in python (see convert.py).
convert.py makes a few assumptions where to find its input. If you intend to use it for your own purposes please adapt the configuration section to your needs. Make sure that the appendices and country specific files are located in different directories and that there are no other .txt files in these directories.
convert.py reads the text files in the countries/ and appendices/ directories as well as the copyright file and writes the preformatted result to stdout:
1 2 3 |
python convert.py > world02.txt |
Before exiting the script creates a table of contents.
creating the dict database
you guessed it:
1 2 3 4 5 |
dictfmt -f -u \ http://www.cia.gov/cia/publications/factbook/countrylisting.html \ -s "CIA World Factbook 2002" -f world02 < world02.txt |
finally:
1 2 3 |
dictzip world02.dict |
Webster and Emacs with SDCV
If you just want the Webster’s dictionary, the sdcv is another way with the following steps. adapted from here and the original post: here’s how you do it (at least on a GNU/Linux system).
- Download the Webster’s dictionary in StarDict format. (Apparently it’s not “some strange format”, but a standard format for a digital dictionary.)
- Unzip the files and put them in ~/.stardict/dic, or /usr/share/stardict/dic
-
Install sdcv, a command-line utility for accessing StarDict dictionaries. (On Arch GNU/Linux, follow instruction here. )
123sudo pacman -S sdcv - Don’t go to Melpa for the sdcv package; it’s usable, but slightly broken. Get sdcv-mode from here instead and load it in Emacs.
- Now, with point on a word you want to look up, say M-x sdcv-search and confirm the selection with RET (or just say M-x sdcv-search anywhere and type the word you want to check).
- You can press RET on any word in the definition to look that one up. Sorry for destroying at least a few hours of your life with that tip.
- Relish thy copy of Webster’s in Emacs.
Google Translate to serve as a command-line tool
Direct quote from its official website.
Translate Shell (formerly Google Translate CLI) is a command-line translator powered by Google Translate (default), Bing Translator, Yandex.Translate and Apertium. It gives you easy access to one of these translation engines in your terminal:
1 2 3 |
pacaur -y translate-shell |
Give it a spin:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
trans '世界你好' 世界你好 (Shìjiè nǐ hǎo) Hello World Translations of 世界你好 [ 简体中文 -> English ] 世界你好 Hello World |
Translate Shell can also be used like an interactive shell; input the text to be translated line by line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
trans -shell Translate Shell (:q to quit) > 你好 你好 (Nǐ hǎo) Hello there Definitions of 你好 [ 简体中文 -> English ] interjection Hello! 你好!, 喂! Hi! 嗨!, 你好! Hallo! 你好! 你好 Hello there, Hello, Hi |
Some useful command:
1 2 3 4 5 6 7 8 9 10 |
# id a language trans -id 言 # translate to french trans :fr word # or trans -t fr work # define source trans -s zh "學而不思則罔,思而不學則殆" |
NOV
About the Author:
Beyond 8 hours - Computer, Sports, Family...