[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Mathias Dahl
Subject: guess-language
Date: Tue, 26 Feb 2008 15:50:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

For a small hack I needed to make a guess about what language a text is
written in.  This in order to automatically set the correct `predictive'
dictionary.  I could not find any existing elisp code that did the same
thing so I wrote it myself.

I present to you `guess-language':

(defun guess-language ()
  "Guess in what language text after point is written in.
In a very simple manner, guess in what language text after point
is written in.  It is done by looking for certain words common to
a specific language.  Currently Swedish (sv) and English (en) is
supported.  Returns a symbol."
  (let ((lang-words '((sv . ("det" "att" "och" "en" "som"))
                      (en . ("the" "a" "of" "and" "an" "to"))))
    (catch 'found
      (dolist (lang lang-words)
        (let ((words (cdr lang)))
          (dolist (word words)
              (when (search-forward-regexp (concat "\\<" word "\\>") nil t)
                (throw 'found (car lang))))))))))

It works well for my purposes.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]