From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sebastian Tennant Newsgroups: gmane.emacs.help Subject: Re: French->English translation? Date: Tue, 22 Jan 2008 23:35:52 +0200 Message-ID: <87tzl5r1af.fsf@moley.moleskin.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1201037803 30490 80.91.229.12 (22 Jan 2008 21:36:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Jan 2008 21:36:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 22 22:37:02 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JHQnf-0003YP-TC for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2008 22:36:56 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JHQnG-0006tV-4t for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2008 16:36:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JHQms-0006pR-NI for help-gnu-emacs@gnu.org; Tue, 22 Jan 2008 16:36:06 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JHQmr-0006nm-QK for help-gnu-emacs@gnu.org; Tue, 22 Jan 2008 16:36:05 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JHQmr-0006nX-12 for help-gnu-emacs@gnu.org; Tue, 22 Jan 2008 16:36:05 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JHQmq-0004Kd-8G for help-gnu-emacs@gnu.org; Tue, 22 Jan 2008 16:36:04 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JHQmm-0008G4-Bu for help-gnu-emacs@gnu.org; Tue, 22 Jan 2008 21:36:00 +0000 Original-Received: from 85.105.17.65 ([85.105.17.65]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Jan 2008 21:36:00 +0000 Original-Received: from sebyte by 85.105.17.65 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Jan 2008 21:36:00 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 159 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 85.105.17.65 User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:KR00tbDgVqHdQt2nX+6Z7W+eY0Q= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50869 Archived-At: Quoth kj : > 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 ---------------------------------------------------- $ 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 ---------------------------------------------------- $ 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