From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.devel Subject: Re: IRC client for Emacs Date: Thu, 22 Aug 2002 16:13:42 +0900 Sender: emacs-devel-admin@gnu.org Message-ID: <85d5d3b0-9de7-4e33-afd6-431aeb53c8cf@deisui.org> References: <873ctot40n.fsf@emacswiki.org> <20020809223753.955308.FMU31823@piglet.prv.splode.com> <200208110355.g7B3tOo06247@wijiji.santafe.edu> <877kixtg8w.fsf@emacswiki.org> <20020811160610.424772.FMU9022@piglet.prv.splode.com> <87fzxhs1ia.fsf@emacswiki.org> <200208151954.g7FJsut07968@wijiji.santafe.edu> <20020820143817.816033.FMU965@piglet.prv.splode.com> <200208210153.g7L1r4W10188@wijiji.santafe.edu> <20020820190744.375246.FMU965@piglet.prv.splode.com> <200208220156.g7M1uvx10414@wijiji.santafe.edu> <20020821193900.557945.FMU965@piglet.prv.splode.com> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart_Thu_Aug_22_16:13:42_2002-1" X-Trace: main.gmane.org 1030000447 13502 127.0.0.1 (22 Aug 2002 07:14:07 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 22 Aug 2002 07:14:07 +0000 (UTC) Cc: rms@gnu.org, alex@emacswiki.org, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17hmAQ-0003Vf-00 for ; Thu, 22 Aug 2002 09:14:06 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17hmdB-0003Cl-00 for ; Thu, 22 Aug 2002 09:43:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17hmBP-0006xm-00; Thu, 22 Aug 2002 03:15:08 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17hm8U-0006tF-00 for emacs-devel@gnu.org; Thu, 22 Aug 2002 03:12:06 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17hm8R-0006sm-00 for emacs-devel@gnu.org; Thu, 22 Aug 2002 03:12:05 -0400 Original-Received: from g96069.scn-net.ne.jp ([210.231.96.69] helo=deisui.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17hm8N-0006sL-00; Thu, 22 Aug 2002 03:12:00 -0400 Original-Received: from deisui.org (aquair [127.0.0.1]) by deisui.org (8.12.5/8.12.5/Debian-1) with ESMTP id g7M7DhCJ006025; Thu, 22 Aug 2002 16:13:44 +0900 X-Now-Playing: DIMENTION ZERO's _SILENT NIGHT FEVER_: "NOT EVEN DEAD" Original-To: Noah Friedman X-Face: ki?-"~Ovqy(#SEZ2FpdUK,3>)p.@}$.vl{eIZ-Uy43$&[S1#'y{hX&A3T@xA)u0!_4Lg.vA ^{d(.VU0(X#Zf,~9Kha_$nl7W/(b9r;]%_&:OUA@g0LF'S2<%~T X-Attribution: DU In-Reply-To: <20020821193900.557945.FMU965@piglet.prv.splode.com> (Noah Friedman's message of "Wed, 21 Aug 2002 19:39:00 -0700 (PDT)") Original-Lines: 284 User-Agent: T-gnus/6.15.7 (based on Oort Gnus v0.07) (revision 02) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:6755 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:6755 --Multipart_Thu_Aug_22_16:13:42_2002-1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable >>>>> In <20020821193900.557945.FMU965@piglet.prv.splode.com>=20 >>>>> Noah Friedman wrote: > Persistent hashtables might be useful for other things (such as BBDB), so > they seem worth considering for reasons beyond localization. Why don't you consider reading *.mo files themselves? Even now gettext 0.11.5 has a support to Emacs Lisp. I have used my gettext.el for that purpose in my IRC client (Liece) for several years. Here is the example: ;; Before evaluating the following expressions, it is needed to run ;; ./prepare.sh (attached below) to generate prog.mo in the current ;; directory and to type M-x load-file gettext.el (also, attached below). (setenv "LANG" "fr") =3D> "fr" (bind-text-domain "prog" ".") =3D> (("prog" . "/home/ueno/fr/LC_MESSAGES/prog.mo")) (dgettext "prog" "'Your command, please?', asked the waiter.") =3D> "=ABVotre commande, s'il vous plait=BB, dit le gar=E7on." --Multipart_Thu_Aug_22_16:13:42_2002-1 Content-Type: text/plain; charset=ISO-8859-1; Content-Disposition: attachment; filename="prepare.sh" Content-Transfer-Encoding: quoted-printable cat < fr.po msgid "" msgstr "" "Content-Type: text/plain; charset=3DISO-8859-1\n" "Plural-Forms: nplurals=3D2; plural=3D(n > 1);\n" msgid "'Your command, please?', asked the waiter." msgstr "=ABVotre commande, s'il vous plait=BB, dit le gar=E7on." # Reverse the arguments. #, elisp-format msgid "%s is replaced by %s." msgstr "%2$s remplace %1$s." EOF mkdir -p fr/LC_MESSAGES msgfmt -o fr/LC_MESSAGES/prog.mo fr.po --Multipart_Thu_Aug_22_16:13:42_2002-1 Content-Type: application/octet-stream; type=emacs-lisp Content-Disposition: attachment; filename="gettext.el" Content-Transfer-Encoding: 7bit ;;; gettext.el --- GNU gettext interface ;; Copyright (C) 1999-2002 Daiki Ueno ;; Author: Daiki Ueno ;; Keywords: i18n ;; This file is not part of any package. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Code: (defvar gettext-gmo-endian 1234) (defvar gettext-message-domain-to-catalog-alist nil) (defvar gettext-default-message-domain "emacs") (defvar gettext-default-mime-charset 'x-ctext) (defvar gettext-default-locale "C") (defconst gettext-msgid-regexp "msgid\\s-*\"") (defconst gettext-msgstr-regexp "msgstr\\s-*\"") (defvar gettext-mime-charset-coding-system-alist (let ((coding-systems (coding-system-list 'base-only)) mime-charset alist) (while coding-systems (if (and (setq mime-charset (coding-system-get (car coding-systems) 'mime-charset)) (not (assq mime-charset alist))) (setq alist (cons (cons mime-charset (car coding-systems)) alist))) (setq coding-systems (cdr coding-systems))) alist)) (defmacro gettext-hex-char-to-integer (character) `(if (and (>= ,character ?0) (<= ,character ?9)) (- ,character ?0) (let ((ch (logior ,character 32))) (if (and (>= ch ?a) (<= ch ?f)) (- ch (- ?a 10)) (error "Invalid hex digit `%c'" ch))))) (defun gettext-hex-string-to-integer (hex-string) (let ((hex-num 0)) (while (not (equal hex-string "")) (setq hex-num (+ (* hex-num 16) (gettext-hex-char-to-integer (string-to-char hex-string))) hex-string (substring hex-string 1))) hex-num)) (defun gettext-gmo-read-32bit-word () (let ((word (string-to-list (buffer-substring (point) (+ (point) 4))))) (forward-char 4) (apply #'format "%02x%02x%02x%02x" (mapcar (lambda (ch) (logand 255 ch)) (if (= gettext-gmo-endian 1234) (nreverse word) word))))) (defmacro gettext-gmo-header-revision (header) `(aref header 0)) (defmacro gettext-gmo-header-nn (header) `(aref header 1)) (defmacro gettext-gmo-header-oo (header) `(aref header 2)) (defmacro gettext-gmo-header-tt (header) `(aref header 3)) (defmacro gettext-gmo-header-ss (header) `(aref header 4)) (defmacro gettext-gmo-header-hh (header) `(aref header 5)) (defmacro gettext-gmo-read-header () (cons 'vector (make-list 6 '(gettext-hex-string-to-integer (gettext-gmo-read-32bit-word))))) (defun gettext-gmo-collect-strings (nn) (let (strings pos len off) (dotimes (i nn) (setq len (gettext-hex-string-to-integer (gettext-gmo-read-32bit-word)) off (gettext-hex-string-to-integer (gettext-gmo-read-32bit-word)) pos (point)) (goto-char (1+ off)) (push (buffer-substring (point) (+ (point) len)) strings) (goto-char pos)) (nreverse strings))) (defun gettext-read-mime-charset (&optional header) "Return the MIME charset of PO file." (with-temp-buffer (insert header) (goto-char (point-min)) (let ((case-fold-search t)) (if (re-search-forward "^\"Content-Type: *text/plain;[ \t]*charset=\\([^\\]+\\)" nil t) (intern (downcase (buffer-substring (match-beginning 1) (match-end 1)))))))) (defun gettext-mapcar* (function &rest args) "Apply FUNCTION to successive cars of all ARGS. Return the list of results." (let (result) (while (not (memq nil args)) (push (apply function (mapcar #'car args)) result) (setq args (mapcar #'cdr args))) (nreverse result))) (defun gettext-load-message-catalogue (file) (with-temp-buffer (let ((coding-system-for-read 'binary) header strings charset coding-system gettext-obarray oott) (insert-file-contents file) (set-buffer-multibyte nil) (goto-char (point-min)) (when (looking-at "\x95\x04\x12\xde") (setq gettext-gmo-endian 4321)) (forward-char 4) (setq header (gettext-gmo-read-header) strings (gettext-mapcar* #'cons (progn (goto-char (1+ (gettext-gmo-header-oo header))) (gettext-gmo-collect-strings (gettext-gmo-header-nn header))) (progn (goto-char (1+ (gettext-gmo-header-tt header))) (gettext-gmo-collect-strings (gettext-gmo-header-nn header)))) charset (or (gettext-read-mime-charset (cdr (assoc "" strings))) gettext-default-mime-charset) gettext-obarray (make-vector (* 2 (gettext-gmo-header-nn header)) 0)) (unless (setq coding-system (cdr (assq charset gettext-mime-charset-coding-system-alist))) (error "Unknown MIME-charset is used in `%s'" file)) (while strings (set (intern (car (car strings)) gettext-obarray) (decode-coding-string (cdr (car strings)) coding-system)) (setq strings (cdr strings))) gettext-obarray))) ;;;###autoload (defun dgettext (domain string) "Look up STRING in the default message domain and return its translation." (let ((oott (assoc domain gettext-message-domain-to-catalog-alist))) (when (stringp (cdr oott)) (setcdr oott (gettext-load-message-catalogue (cdr oott)))) (or (symbol-value (intern-soft string (or (cdr oott) (make-vector 1 0)))) string))) ;;;###autoload (defun gettext (string) "Look up STRING in the default message domain and return its translation." (dgettext gettext-default-message-domain string)) ;;;###autoload (defun bind-text-domain (domain pathname) "Associate a pathname with a message domain." (let* ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES") (getenv "LANG") gettext-default-locale)) (language (progn (string-match "\\([^_.]+\\)\\(_[^.]+\\)?\\(\\.[^@]+\\)?" lang) (match-string 1 lang))) (territory (match-string 2 lang)) (code-set (match-string 3 lang)) (lang-path (if lang (delq nil (list (if (and territory code-set) (concat language territory code-set)) (if territory (concat language territory)) (if code-set (concat language code-set)) language)))) (file (concat domain ".mo")) catalog) (while (and (setq lang (car lang-path)) (setq catalog (expand-file-name file (concat pathname "/" lang "/LC_MESSAGES"))) (not (file-exists-p catalog))) (setq lang-path (cdr lang-path))) (when (file-exists-p catalog) ;;(file-exists-p (setq catalog (expand-file-name file pathname))) (push (cons domain catalog) gettext-message-domain-to-catalog-alist)))) (provide 'gettext) ;;; gettext.el ends here --Multipart_Thu_Aug_22_16:13:42_2002-1 Content-Type: text/plain; charset=US-ASCII -- Daiki Ueno --Multipart_Thu_Aug_22_16:13:42_2002-1--