unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Bruno Haible <haible@ilog.fr>
Cc: devel-emacs@gnu.org, sanvila@unex.es, neil@darlow.co.uk, handa@etl.go.jp
Subject: Re: PO files and Emacs
Date: Tue, 12 Mar 2002 14:30:06 +0100 (CET)	[thread overview]
Message-ID: <15502.734.892880.44892@honolulu.ilog.fr> (raw)
In-Reply-To: <shlmd1zv94.fsf@tux.gnu.franken.de>

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 420 bytes --]

Karl Eichwalder writes:

> When po.el is installed I'll help to test it.

The version you submitted is 10 months old. Here is the current
version, which includes extensions by Francois Pinard, updates for
Emacs 21 by me, and fixes by yourself and Andreas Schwab. I suggest to
include this one.

And please keep the comments about XEmacs. There would be no point in
making life harder for the XEmacs maintainers.

Bruno


[-- Attachment #2: po.el --]
[-- Type: text/x-elisp, Size: 6537 bytes --]

;;; po.el --- basic support of PO translation files -*- coding: utf-8; -*-

;; Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.

;; Authors: François Pinard <pinard@iro.umontreal.ca>,
;;          Greg McGary <gkm@magilla.cichlid.com>,
;;          Bruno Haible <bruno@clisp.org>.

;; 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.


; 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 entries.
    (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 21
    (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
	 "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")
	(short-read nil))
    ;; Try the first 4096 bytes.  In case we cannot find the charset value
    ;; 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))
	(let ((pair (insert-file-contents-literally filename nil
						    (1- (point))
						    (1- (+ (point) 4096)))))
	  (setq short-read (< (nth 1 pair) 4096)))))
    (cond (short-read nil)
	  ((re-search-forward charset-regexp nil t) (match-string 1))
	  ;; We've found the first msgid; maybe, only a part of the msgstr
	  ;; value was loaded.  Load the next 1024 bytes; if charset still
	  ;; isn't available, give up.
	  (t (save-excursion
	       (goto-char (point-max))
	       (insert-file-contents-literally filename nil
					       (1- (point))
					       (1- (+ (point) 1024))))
	     (if (re-search-forward charset-regexp nil t)
		 (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
	 (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-alist))
                     (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 for real."
;  (po-find-file-coding-system-guts operation filename))


  parent reply	other threads:[~2002-03-12 13:30 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-09 14:11 PO files and Emacs Karl Eichwalder
2002-03-10  5:03 ` Richard Stallman
2002-03-10  5:29   ` Karl Eichwalder
2002-03-11  9:00     ` Richard Stallman
2002-03-11 11:03       ` Eli Zaretskii
2002-03-11 17:54         ` Karl Eichwalder
2002-03-11 19:29           ` Andreas Schwab
2002-03-11 20:02       ` Karl Eichwalder
2002-03-12  5:53         ` Eli Zaretskii
2002-03-12 13:41           ` Bruno Haible
2002-03-12 15:53             ` Kim F. Storm
2002-03-12 16:25               ` Karl Eichwalder
2002-03-12 17:19               ` Bruno Haible
2002-03-12 17:20               ` Bruno Haible
2002-03-15 13:53                 ` Eli Zaretskii
2002-03-16  3:41                   ` Karl Eichwalder
2002-03-12 17:17             ` Eli Zaretskii
2002-03-15 13:54       ` Eli Zaretskii
2002-03-10 11:10   ` Neil Darlow
2002-03-11  5:46     ` Eli Zaretskii
2002-03-11  6:45       ` Karl Eichwalder
2002-03-11  6:53         ` Eli Zaretskii
2002-03-12 13:30 ` Bruno Haible [this message]
2002-03-15 13:29   ` Eli Zaretskii
2002-03-15 18:43     ` Bruno Haible
2002-03-16  4:36       ` Karl Eichwalder
2002-03-16  9:26         ` Eli Zaretskii
2002-03-16 13:05           ` Karl Eichwalder
2002-03-16 17:29             ` Eli Zaretskii
2002-03-16 18:41               ` Karl Eichwalder
2002-03-17  4:35                 ` Eli Zaretskii
2002-03-17  5:26                   ` Karl Eichwalder
2002-03-17 11:40                     ` Patch for GNU gettext (Re: PO files and Emacs) Karl Eichwalder
2002-03-17 11:42                     ` PO files and Emacs Eli Zaretskii
2002-03-16 10:39       ` Alex Schroeder
  -- strict thread matches above, loose matches on Subject: below --
2002-03-12  8:44 Karl Eichwalder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15502.734.892880.44892@honolulu.ilog.fr \
    --to=haible@ilog.fr \
    --cc=devel-emacs@gnu.org \
    --cc=handa@etl.go.jp \
    --cc=neil@darlow.co.uk \
    --cc=sanvila@unex.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).