On Mon, Feb 13, 2012 at 1:47 PM, Jambunathan K <kjambunathan@gmail.com> wrote:

Rustom

Try this:

(defun translate-to-hindi (filename)
 (interactive "fFile to be translated: ")
 (with-temp-buffer
   (switch-to-buffer (current-buffer))
   (setq buffer-file-coding-system 'utf-8)
   (set-input-method "devanagari-itrans" t)
   (execute-kbd-macro
    (with-temp-buffer
      (insert-file-contents filename)
      (buffer-string)))

   (write-file
    (concat (file-name-sans-extension filename)
            "-hi" (file-name-extension filename t)))))


One question about the code above:
Why do you need the switch-to-buffer?
I tried removing it -- does not work
The doc for switch-to-buffer warns against using it in lisp suggesting set-buffer instead.
I tried that -- does not work. My current code is this:

(defvar input-method "devanagari-itrans")
(defun translate-to-hindi (filename)
 (interactive "fFile to be translated: ")
 (let ((inp (with-temp-buffer
        (insert-file-contents filename)
        (buffer-string)))
       (out-file-name (concat (file-name-sans-extension filename)
                   "-hi" (file-name-extension filename t))))
   (with-temp-buffer
     (switch-to-buffer (current-buffer))
     (setq buffer-file-coding-system 'utf-8)
     (set-input-method input-method t)
     (execute-kbd-macro inp)
     (write-file out-file-name))))