[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Erbot-cvs] erbot/contrib translate.el
From: |
Vivek Dasmohapatra |
Subject: |
[Erbot-cvs] erbot/contrib translate.el |
Date: |
Thu, 18 May 2006 17:47:46 +0000 |
CVSROOT: /sources/erbot
Module name: erbot
Branch:
Changes by: Vivek Dasmohapatra <address@hidden> 06/05/18 17:47:46
Modified files:
contrib : translate.el
Log message:
Another attempt at getting the encoding right - libtranslate "helpfully"
tries to encode output according to your locale. Empirically, the
settings
used seem to work. I have no idea why it's so touchy about LC_CTYPE.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/erbot/erbot/contrib/translate.el.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: erbot/contrib/translate.el
diff -u erbot/contrib/translate.el:1.3 erbot/contrib/translate.el:1.4
--- erbot/contrib/translate.el:1.3 Wed May 17 06:23:05 2006
+++ erbot/contrib/translate.el Thu May 18 17:47:46 2006
@@ -191,8 +191,7 @@
;; call-process should use utf-8, that's what libtranslate wants: hence
;; we set process-coding-system-alist.
;; -----------------------------------------------------------------------
- (let ( (process-coding-system-alist '(("." . utf-8)))
- (from-lang (format "%s" from))
+ (let ( (from-lang (format "%s" from))
(to-lang (format "%s" to))
(translation nil) ;; translated text, or libtranslate error
(code nil) ;; cons of (origin-lang . dest-lang)
@@ -212,15 +211,27 @@
(error "Sorry, unicode support for %s is not yet complete."
(translate-full-name to-lang)) )
( t
- (with-temp-buffer
- (insert text)
- (setq status
- (call-process-region (point-min) (point-max) translate-program
- :delete-input (current-buffer) nil
- "-f" from "-t" to)
- translation (buffer-string)) )) )
- (if (/= 0 status)
- (error "%d - %s" status translation))
- translation))
+ (with-temp-buffer
+ (let ( (lang (getenv "LANG"))
+ (lc-ctype (getenv "LC_CTYPE"))
+ (coding-system-for-read 'utf-8)
+ (coding-system-for-write 'utf-8)
+ (process-coding-system-alist '("." . utf-8)) )
+ (insert text)
+ (setenv "LANG" "en_GB.UTF-8")
+ (setenv "LC_CTYPE" "ja_JP.UTF-8") ;; seems to work. here be dragons
+ (setq status
+ (call-process-region (point-min) (point-max)
+ translate-program
+ :delete-input (current-buffer) nil
+ "-f" from "-t" to)
+ translation (buffer-substring-no-properties (point-min)
+ (point-max)))
+ (setenv "LANG" lang)
+ (setenv "LC_CTYPE" lc-ctype)
+ )) ))
+ (if (/= 0 status)
+ (error "%d - %s" status translation))
+ translation )) ;
-(provide 'translate)
\ No newline at end of file
+(provide 'translate)