guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie seeks guiding hands.


From: Rob Browning
Subject: Re: Newbie seeks guiding hands.
Date: 21 Mar 2001 23:39:36 -0600
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Martin Grabmueller <address@hidden> writes:

> Currently, Guile does not bother with i18n at all.  There were
> discussions and plans about supporting multibyte strings internally
> a while ago, but I think so far there was no consensus about how to
> handle things like that.  Error messages are not localized at all.

In gnucash, we publish the C function gettext at the guile level via
g-wrap as gnc:gettext (though you could just as easily use
gh_new_procedure directly -- probably more easily, really), and then
we just manage things with the normal gettext infrastructure.

We also have:

  (define _ gnc:gettext)
  (define-syntax N_
    (syntax-rules ()
      ((_ x) x)))

and Dave has implemented a scanner that extracts all our gettextized
strings from our .scm files.  I'll reproduce it below, but I'm not too
familiar with it, so if you have further questions, you should
probably ask Dave -- <address@hidden>.

Hope this helps...

;; Find translatable strings in guile files

(define (expand-newlines string out-port)
  (define (output-prefix-newlines chars)
    (if (and (pair? chars) (char=? (car chars) #\newline))
        (begin
          (display "\\n" out-port)
          (output-prefix-newlines (cdr chars)))
        chars))

  (let loop ((chars (string->list string))
             (accum '()))
    (cond
     ((null? chars)
      (if (not (null? accum))
          (write (list->string (reverse accum)) out-port)))
     ((char=? (car chars) #\newline)
      (write (list->string (reverse accum)) out-port)
      (display "\"" out-port)
      (set! chars (output-prefix-newlines chars))
      (display "\"" out-port)
      (if (not (null? chars))
          (display "\n  " out-port))
      (loop chars '()))
     (else
      (loop (cdr chars) (cons (car chars) accum))))))

(define (write-string string out-port)
  (display "_(" out-port)
  (expand-newlines string out-port)
  (display ")\n" out-port))

(define (find-strings-in-item item out-port in-port)
  (define (find-internal rest)
    (cond
     ((and (list? rest)                    ; if it's a list
           (= (length rest) 2)             ; of length 2
           (symbol? (car rest))            ; starting with a symbol
           (string? (cadr rest))           ; and ending with a string
           (or (eqv? '_ (car rest))        ; and the symbol is _
               (eqv? 'N_ (car rest))       ; or N_
               (eqv? 'gnc:_ (car rest))))  ; or gnc:_
      (write-string (cadr rest) out-port)) ; then write it out

     ((pair? rest)                         ; otherwise, recurse
      (find-internal (car rest))
      (find-internal (cdr rest)))))

  (find-internal item))

(define (find-strings in-port out-port)
  (do ((item (read in-port) (read in-port)))
      ((eof-object? item) #t)
    (find-strings-in-item item out-port in-port)))

(let ((out-port (open "guile-strings.c" (logior O_WRONLY O_CREAT O_TRUNC)))
      (in-files (cdr (command-line))))
  (for-each (lambda (file)
              (call-with-input-file file (lambda (port)
                                           (find-strings port out-port))))
            in-files))

-- 
Rob Browning <address@hidden> PGP=E80E0D04F521A094 532B97F5D64E3930



reply via email to

[Prev in Thread] Current Thread [Next in Thread]