* Re: French->English translation?
2008-01-21 0:53 French->English translation? kj
@ 2008-01-22 21:35 ` Sebastian Tennant
[not found] ` <mailman.6424.1201037768.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Tennant @ 2008-01-22 21:35 UTC (permalink / raw)
To: help-gnu-emacs
Quoth kj <socyl@987jk.com.invalid>:
> Are there any language translation modules for Emacs?
Not that I know of.
> I'm thinking of something analogous to ispell but instead of providing
> help with spelling, it provides possible translations in the selected
> target language. I'm particularly interested in tools to help me when
> I write French. (I need more than spelling help in French; oftentimes
> I don't know or can't remember the word in French for what I want to
> say.)
I know the feeling. My solution is to use dict and my own little Emacs
interface. It's nothing like ispell of course, but it does provide
pretty rapid and convenient dictionary access in Emacs (with keyword
highlighting, automatic activating of an input method and multiple
specified dictionary search functionality). Not bad for a couple of
dozen lines, even if I do say so myself!
Assuming you're running an apt-based Linux distro, do:
$ apt-get install dict dict-freedict-eng-fra dict-freedict-fra-eng
This provides the 'dict' command-line program and two dictionaries;
English -> French and French -> English.
Add the lines:
server localhost
pager -
to /etc/dictd/dict.conf.
You've installed the dictionaries locally (so you don't need network
access for it to work) and Emacs is going to be our pager.
Now add the following to your ~/.emacs:
----------------8<----------------8<----------------8<----------------8<
;;; dict.el
(defun dict (host databases strategy word)
(interactive "sHost: \nsDatabase(s): \nsStrategy: \nsWord: ")
;; set up buffer
(set-buffer (get-buffer-create "*dict*"))
(text-mode) (erase-buffer) (setq font-lock-keywords-case-fold-search t)
;; highlight command-line
(font-lock-add-keywords nil '(("^\\$ .*$" 0 font-lock-keyword-face prepend)))
;; highlight word
(let ((match-string word))
(and (equal strategy "prefix") (setq match-string (concat word "[a-z]*")))
(font-lock-add-keywords nil `((,match-string . font-lock-variable-name-face))))
;; force font-lock-mode
(font-lock-mode 1)
;; construct separate queries for each database in databases
(let ((database-list (split-string databases)))
(mapc (lambda (d)
(let ((commstr (concat " -h " host " -d " d " -s " strategy " " word)))
(insert (format "$ dict%s\n" commstr))
(apply 'call-process "dict" nil t nil (split-string commstr))
(insert "\n")))
database-list))
;; display
(goto-char (point-min))
(view-mode)
(display-buffer "*dict*"))
;;; $ dict -h localhost -D to see what dictionaries are installed locally
;;; search French dictionaries (English -> French and French -> English)
(defun fw (word)
(interactive
(with-temp-buffer
(activate-input-method "french-postfix")
(list (read-from-minibuffer "Word: " nil nil nil nil nil t))))
(let (strat)
(if current-prefix-arg (setq strat "prefix") (setq strat "exact"))
(dict "localhost" "fd-fra-eng fd-eng-fra" strat word)))
----------------8<----------------8<----------------8<----------------8<
We have defined two functions:
dict - a 'generic' interface to dict
fw - a French specific 'shortcut' interface to dict, via our dict
When fw is called without a prefix argument, only exact matches are
returned. When fw is called with a prefix argument, words that _begin_
to match are returned.
So, for example, without prefix argument:
M-x fw aim <RET>
----------------------------------------------------
$ dict -h localhost -d fd-fra-eng -s exact aim
No matches found for "aim"
$ dict -h localhost -d fd-eng-fra -s exact aim
From English-French Freedict dictionary [fd-eng-fra]:
aim [eim]
avoir pour but; viser
but; dessein
se démener
peiner
----------------------------------------------------
And with a prefix argument:
C-u M-x fw aim <RET>
----------------------------------------------------
$ dict -h localhost -d fd-fra-eng -s prefix aim
From French-English Freedict dictionary [fd-fra-eng]:
aimable [ɛmabl]
affable; friendly; good‐natured; kind
dainty; kind; nice; pretty
From French-English Freedict dictionary [fd-fra-eng]:
aimer [ɛme]
love
appreciate; like
From French-English Freedict dictionary [fd-fra-eng]:
aimer mieux [ɛmemjø]
prefer
$ dict -h localhost -d fd-eng-fra -s prefix aim
From English-French Freedict dictionary [fd-eng-fra]:
aim [eim]
avoir pour but; viser
but; dessein
se démener
peiner
----------------------------------------------------
There's a 'proper' emacs interface to dict called dictem.el, but it
struck me as unecessarily complicated. Also, my interface queries each
of a list of specific dictionaries in turn which dictem.el doesn't
provide for.
IMHO it's a serious limitation of dict that it only allows you to
specify _one_ particular dictionary on the command line, not two or
three or four, and if no dictionaries are specified it searches _all_ of
the dictionaries on the server, which, in my experience, is rarely what
you want.
Anyway, hope it helps.
Sebastian
^ permalink raw reply [flat|nested] 3+ messages in thread