From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Bruno Haible Newsgroups: gmane.emacs.devel Subject: Re: PO files and Emacs Date: Tue, 12 Mar 2002 18:20:40 +0100 (CET) Sender: emacs-devel-admin@gnu.org Message-ID: <15502.14568.540497.141332@honolulu.ilog.fr> References: <15502.1402.523363.275174@honolulu.ilog.fr> <5xsn75zssf.fsf@kfs2.cua.dk> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="VNgOCYQRmB" Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1015953707 26925 80.91.224.249 (12 Mar 2002 17:21:47 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 12 Mar 2002 17:21:47 +0000 (UTC) Cc: Eli Zaretskii , Karl Eichwalder , rms@gnu.org, emacs-devel@gnu.org, sanvila@unex.es, neil@darlow.co.uk, handa@etl.go.jp, schwab@suse.de Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16kpy7-00070A-00 for ; Tue, 12 Mar 2002 18:21:47 +0100 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16kq0M-0005kU-00 for ; Tue, 12 Mar 2002 18:24:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16kpxw-0004hQ-00; Tue, 12 Mar 2002 12:21:36 -0500 Original-Received: from sceaux.ilog.fr ([193.55.64.10]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16kpwT-0004Yn-00; Tue, 12 Mar 2002 12:20:05 -0500 Original-Received: from ftp.ilog.fr (ftp.ilog.fr [193.55.64.11]) by sceaux.ilog.fr (8.11.6/8.11.6) with SMTP id g2CHI1B17428; Tue, 12 Mar 2002 18:18:02 +0100 (MET) Original-Received: from laposte.ilog.fr ([193.55.64.65]) by ftp.ilog.fr (NAVGW 2.5.1.16) with SMTP id M2002031218195903508 ; Tue, 12 Mar 2002 18:19:59 +0100 Original-Received: from honolulu.ilog.fr ([172.17.4.208]) by laposte.ilog.fr (8.11.6/8.11.5) with ESMTP id g2CHJul08752; Tue, 12 Mar 2002 18:19:56 +0100 (MET) Original-Received: (from haible@localhost) by honolulu.ilog.fr (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id SAA14828; Tue, 12 Mar 2002 18:20:40 +0100 Original-To: storm@cua.dk In-Reply-To: <5xsn75zssf.fsf@kfs2.cua.dk> X-Mailer: VM 6.72 under 21.1 (patch 8) "Bryce Canyon" XEmacs Lucid Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:1880 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1880 --VNgOCYQRmB Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit > IMO, the commentary in the po.el file is *very* sparse, and it is hard > to see when this file is needed, and for what purpose... Take this one. --VNgOCYQRmB Content-Type: text/x-elisp; charset=UTF-8 Content-Description: po.el Content-Disposition: attachment; filename="po.el" Content-Transfer-Encoding: quoted-printable ;;; po.el --- basic support of PO translation files -*- coding: utf-8; = -*- ;; Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. ;; Authors: Fran=C3=A7ois Pinard , ;; Greg McGary , ;; Bruno Haible . ;; This file is part of GNU Emacs. ;; GNU Emacs 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. ;; GNU Emacs 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. ;;; Commentary: ;; Basic support for viewing PO files. ;; Usage: ;; (autoload 'po-find-file-coding-system "po") ;; (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\." ;; 'po-find-file-coding-system) ;;; Code: ; Make the cpnnn codesets available. (if (not (string-match "XEmacs\\|Lucid" emacs-version)) (mapc #'codepage-setup (mapcar #'car (cp-supported-codepages)))) (defconst po-content-type-charset-alist '(; Note: Emacs 21 doesn't support all encodings, thus the missing en= tries. (ASCII . undecided) (ANSI_X3.4-1968 . undecided) (US-ASCII . undecided) (ISO-8859-1 . iso-8859-1) (ISO_8859-1 . iso-8859-1) (ISO-8859-2 . iso-8859-2) (ISO_8859-2 . iso-8859-2) (ISO-8859-3 . iso-8859-3) (ISO_8859-3 . iso-8859-3) (ISO-8859-4 . iso-8859-4) (ISO_8859-4 . iso-8859-4) (ISO-8859-5 . iso-8859-5) (ISO_8859-5 . iso-8859-5) ;(ISO-8859-6 . ??) ;(ISO_8859-6 . ??) (ISO-8859-7 . iso-8859-7) (ISO_8859-7 . iso-8859-7) (ISO-8859-8 . iso-8859-8) (ISO_8859-8 . iso-8859-8) (ISO-8859-9 . iso-8859-9) (ISO_8859-9 . iso-8859-9) ;(ISO-8859-13 . ??) ;(ISO_8859-13 . ??) (ISO-8859-15 . iso-8859-15) ; requires Emacs 21 (ISO_8859-15 . iso-8859-15) ; requires Emacs 21 (KOI8-R . koi8-r) ;(KOI8-U . ??) (CP437 . cp437) ; requires Emacs 20 (CP775 . cp775) ; requires Emacs 20 (CP850 . cp850) ; requires Emacs 20 (CP852 . cp852) ; requires Emacs 20 (CP855 . cp855) ; requires Emacs 20 ;(CP856 . ??) (CP857 . cp857) ; requires Emacs 20 (CP861 . cp861) ; requires Emacs 20 (CP862 . cp862) ; requires Emacs 20 (CP864 . cp864) ; requires Emacs 20 (CP865 . cp865) ; requires Emacs 20 (CP866 . cp866) ; requires Emacs 21 (CP869 . cp869) ; requires Emacs 20 ;(CP874 . ??) ;(CP922 . ??) ;(CP932 . ??) ;(CP943 . ??) ;(CP949 . ??) ;(CP950 . ??) ;(CP1046 . ??) ;(CP1124 . ??) ;(CP1129 . ??) (CP1250 . cp1250) ; requires Emacs 20 (CP1251 . cp1251) ; requires Emacs 20 (CP1252 . iso-8859-1) ; approximation (CP1253 . cp1253) ; requires Emacs 20 (CP1254 . iso-8859-9) ; approximation (CP1255 . iso-8859-8) ; approximation ;(CP1256 . ??) (CP1257 . cp1257) ; requires Emacs 20 (GB2312 . cn-gb-2312) ; also named 'gb2312' in XEmacs 21 or Emacs = 21 ; also named 'euc-cn' in Emacs 20 or Emacs 2= 1 (EUC-JP . euc-jp) (EUC-KR . euc-kr) ;(EUC-TW . ??) (BIG5 . big5) ;(BIG5-HKSCS . ??) ;(GBK . ??) ;(GB18030 . ??) (SHIFT_JIS . shift_jis) ;(JOHAB . ??) (TIS-620 . tis-620) ; requires Emacs 20 or Emacs 21 (VISCII . viscii) ; requires Emacs 20 or Emacs 21 (UTF-8 . utf-8) ; requires Mule-UCS in Emacs 20, or Emacs 21= ) "How to convert a GNU libc/libiconv canonical charset name as seen in= Content-Type into a Mule coding system.") (defun po-find-charset (filename) "Return PO file charset value." (interactive) (let ((charset-regexp =09 "^\"Content-Type: text/plain;[ \t]*charset=3D\\(.*\\)\\\\n\"") =09(short-read nil)) ;; Try the first 4096 bytes. In case we cannot find the charset va= lue ;; within the first 4096 bytes (the PO file might start with a long= ;; comment) try the next 4096 bytes repeatedly until we'll know for= sure ;; we've checked the empty header entry entirely. (while (not (or short-read (re-search-forward "^msgid" nil t))) (save-excursion (goto-char (point-max)) =09(let ((pair (insert-file-contents-literally filename nil =09=09=09=09=09=09 (1- (point)) =09=09=09=09=09=09 (1- (+ (point) 4096))))) =09 (setq short-read (< (nth 1 pair) 4096))))) (cond (short-read nil) =09 ((re-search-forward charset-regexp nil t) (match-string 1)) =09 ;; We've found the first msgid; maybe, only a part of the msgstr =09 ;; value was loaded. Load the next 1024 bytes; if charset still =09 ;; isn't available, give up. =09 (t (save-excursion =09 (goto-char (point-max)) =09 (insert-file-contents-literally filename nil =09=09=09=09=09 (1- (point)) =09=09=09=09=09 (1- (+ (point) 1024)))) =09 (if (re-search-forward charset-regexp nil t) =09=09 (match-string 1)))))) (defun po-find-file-coding-system-guts (operation filename) "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset.= Called through file-coding-system-alist, before the file is visited for= real." (and (eq operation 'insert-file-contents) (file-exists-p filename) (po-with-temp-buffer =09 (let* ((coding-system-for-read 'no-conversion) (charset (or (po-find-charset filename) "ascii")) (charset-upper (intern (upcase charset))) (charset-lower (intern (downcase charset)))) (list (or (cdr (assq charset-upper po-content-type-charset-a= list)) (if (memq charset-lower (coding-system-list)) charset-lower 'no-conversion))))))) ;;;###autoload (defun po-find-file-coding-system (arg-list) "\ Return a Mule (DECODING . ENCODING) pair, according to PO file charset.= Called through file-coding-system-alist, before the file is visited for= real." (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))= ) ;; This is for XEmacs. ;(defun po-find-file-coding-system (operation filename) ; "\ ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset= . ;Called through file-coding-system-alist, before the file is visited fo= r real." ; (po-find-file-coding-system-guts operation filename)) --VNgOCYQRmB-- _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel