source: trunk/third/sawfish/po/sawfish-xgettext @ 17367

Revision 17367, 5.0 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17366, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2exec rep "$0" "$@"
3!#
4
5;; sawfish-xgettext -- extract i18n strings from lisp scripts
6;; $Id: sawfish-xgettext,v 1.1.1.3 2002-03-20 04:59:39 ghudson Exp $
7
8;; This file is part of sawfish.
9
10;; sawfish is free software; you can redistribute it and/or modify it
11;; under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; sawfish is distributed in the hope that it will be useful, but
16;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with sawfish; see the file COPYING.  If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24(require 'rep.i18n.xgettext)
25(require 'rep.lang.doc)
26
27(defvar *write-c-file* nil)
28
29(define (exit n) (throw 'quit n))
30
31
32;; random hackery
33
34;; from sawfish.ui.widgets.match-window
35(define (beautify-symbol-name symbol)
36  (cond ((stringp symbol) symbol)
37        ((not (symbolp symbol)) (format "%s" symbol))
38        (t
39         (let ((name (copy-sequence (symbol-name symbol))))
40           (while (string-match "[-:]" name)
41             (setq name (concat (substring name 0 (match-start))
42                                ?  (substring name (match-end)))))
43           (aset name 0 (char-upcase (aref name 0)))
44           name))))
45
46;; from sawfish.ui.layouts.keymaps
47(define (beautify-keymap-name symbol)
48  (cond ((stringp symbol) symbol)
49        ((not (symbolp symbol)) (format "%s" symbol))
50        (t
51         (let ((name (copy-sequence (symbol-name symbol))))
52           (when (string-match "-keymap" name)
53             (setq name (substring name 0 (match-start))))
54           (while (string-match "[-:]" name)
55             (setq name (concat (substring name 0 (match-start))
56                                ?  (substring name (match-end)))))
57           (aset name 0 (char-upcase (aref name 0)))
58           name))))
59
60
61;; helper function that groks sawfish specific forms
62
63(define (get-key key args) (and (listp args) (memq key args)))
64
65(define (helper form)
66  (case (car form)
67    ((defcustom)
68     (let ((variable (nth 1 form))
69           (doc (nth 3 form))
70           (keys (nthcdr 4 form)))
71       (let ((tooltip (cadr (get-key ':tooltip keys))))
72         (when tooltip
73           (setq doc (concat doc "\n\n" tooltip))))
74       (let ((type* (cadr (get-key ':type* keys))))
75         (when type*
76           (scan type*)))
77       (let ((options (cadr (get-key ':options keys))))
78         ;; extract `:options (foo bar..)' strings
79         (when (listp options)
80           (mapc (lambda (s)
81                   (when s
82                     (register (symbol-name s)))) options)))
83       (let ((type (cadr (get-key ':type keys))))
84         ;; extract `:type (choice foo bar..)' strings
85         (when (eq (car type) 'choice)
86           (mapc (lambda (s)
87                   (when (symbolp s)
88                     (register (symbol-name s)))) (cdr type)))
89         ;; extract keymap names
90         (when (eq type 'keymap)
91           (register (beautify-keymap-name (symbol-name variable)))))
92       (when (stringp doc)
93         (register doc))))
94
95    ((defgroup)
96     (let ((real-name (nth 2 form)))
97       (when (stringp real-name)
98         (register real-name))))
99
100    ((define-command)
101     (let ((name (nth 1 form))
102           (def (nth 2 form))
103           (keys (nthcdr 3 form)))
104       (when (and (eq (car name) 'quote)
105                  (symbolp (cadr name)))
106         (register (beautify-symbol-name (cadr name))))
107       (if (get-key #:doc keys)
108           (register (cadr (get-key #:doc keys)))
109         (let ((key (or (cadr (get-key #:doc-key keys))
110                        (and (symbolp def)
111                             (doc-file-value-key
112                              def (fluid current-module))))))
113           (when (stringp key)
114             (let ((doc (doc-file-ref key)))
115               (when doc
116                 (register doc))))))
117       (let ((type (car (cdr (get-key #:type keys)))))
118         (when type
119           (scan type)))))
120
121    ((i18n-defvar i18n-define)
122     (let ((name (cadr form))
123           (value (caddr form)))
124       (case name
125         ((match-window-properties)
126          (mapc (lambda (x)
127                  (mapc (lambda (y)
128                          (register (beautify-symbol-name (car y)))) (cddr x)))
129                ;; remove a `(backquote X)'
130                (nth 1 value)))
131
132         ((match-window-x-properties)
133          (mapc (lambda (x)
134                  (register (cdr x)))
135                ;; strip a `(quote X)'
136                (nth 1 value))))
137
138       ;; always rescan as normal, to be sure not to miss anything
139       (scan (cons (if (eq (car form) 'i18n-defvar)
140                       'defvar
141                     'define)
142                   (cdr form)))))
143
144    (t (scan-list form))))
145
146
147;; entry point
148
149(when (get-command-line-option "--help")
150  (write standard-output "\
151Usage: sawfish-xgettext [OPTIONS...] FILES...
152
153Program to extract strings from sawfish Lisp files that should be
154translated.
155
156  --doc-file DOC
157  --c
158  --pot\n")
159  (exit 0))
160
161(when (or (get-command-line-option "-c") (get-command-line-option "--c"))
162  (setq *write-c-file* t))
163(when (or (get-command-line-option "-p") (get-command-line-option "--pot"))
164  (setq *write-c-file* nil))
165
166(let ((doc-file (get-command-line-option "--doc-file" t)))
167  (when doc-file
168    (setq documentation-files (list doc-file))))
169
170(set-helper helper)
171(set-included-definers '())
172(mapc scan-file command-line-args)
173(setq command-line-args '())
174
175(if *write-c-file*
176    (output-c-file)
177  (output-pot-file))
178
179;; Local variables:
180;; major-mode: lisp-mode
181;; End:
Note: See TracBrowser for help on using the repository browser.