Collect translatable strings from scheme source files statically.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3333 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas
2000-12-21 08:53:54 +00:00
parent 9710cb661c
commit 9a16112c4e
26 changed files with 10648 additions and 10347 deletions

View File

@@ -49,7 +49,7 @@ EXTRA_DIST = \
old/xacc-shell.c \
po/.cvsignore \
po/extract-macros.perl.in \
po/guile_strings.txt
po/guile-strings.c
## We borrow guile's convention and use @-...-@ as the substitution
## brackets here, instead of the usual @...@. This prevents autoconf

View File

@@ -1,14 +1,16 @@
# List of files which containing translatable strings.
# Copyright (C) 1995, 1998 Free Software Foundation, Inc.
po/guile_strings.txt
po/guile-strings.c
src/FileDialog.c
src/SplitLedger.c
src/engine/Account.c
src/engine/io-gncbin-r.c
src/engine/Scrub.c
src/engine/io-gncbin-r.c
src/gnc-exp-parser.c
src/gnc-ui-util.c
src/gnome/dialog-account.c
src/gnome/dialog-account-picker.c
src/gnome/dialog-account.c
src/gnome/dialog-budget.c
src/gnome/dialog-commodity.c
src/gnome/dialog-filebox.c
@@ -24,6 +26,7 @@ src/gnome/file-history.c
src/gnome/glade-gnc-dialogs.c
src/gnome/gnc-commodity-edit.c
src/gnome/gnc-datedelta.c
src/gnome/gnc-dateedit.c
src/gnome/print-session.c
src/gnome/reconcile-list.c
src/gnome/window-main.c
@@ -34,5 +37,8 @@ src/guile/gnucash.c
src/register/gnome/gnucash-style.c
src/register/recncell.c
src/register/splitreg.c
src/FileDialog.c
src/SplitLedger.c
src/scm/gnumeric/guile-strings.c
src/scm/guile-strings.c
src/scm/printing/guile-strings.c
src/scm/qif-import/guile-strings.c
src/scm/report/guile-strings.c

2516
po/de.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2518
po/es.po

File diff suppressed because it is too large Load Diff

2675
po/fr.po

File diff suppressed because it is too large Load Diff

2632
po/it.po

File diff suppressed because it is too large Load Diff

2520
po/ja.po

File diff suppressed because it is too large Load Diff

2493
po/ru.po

File diff suppressed because it is too large Load Diff

2905
po/sv.po

File diff suppressed because it is too large Load Diff

View File

@@ -33,7 +33,8 @@
* Dave Peticolas <peticola@cs.ucdavis.edu>
*/
#include <config.h>
#include "config.h"
#include <string.h>
#include <stdlib.h> /* atoi */
#include <ctype.h> /* isdigit */
@@ -41,6 +42,7 @@
#include <time.h>
#include "gnc-dateedit.h"
#include "messages.h"
#include "date.h"

View File

@@ -1,3 +1,4 @@
Makefile
Makefile.in
bootstrap.scm
guile-strings.c

View File

@@ -9,16 +9,21 @@ gnc_autogen_scm_files = \
gnc_regular_scm_files = \
c-interface.scm \
command-line.scm \
commodity-import.scm \
commodity-table.scm \
config-var.scm \
date-utilities.scm \
depend.scm \
doc.scm \
engine-init.scm \
engine-interface.scm \
engine-utilities.scm \
extensions.scm \
graph.scm \
help-topics-index.scm \
hooks.scm \
html-generator.scm \
iso-4217-currencies.scm \
main.scm \
options.scm \
path.scm \
@@ -31,15 +36,11 @@ gnc_regular_scm_files = \
substring-search.scm \
testbed.scm \
text-export.scm \
tip-of-the-day.scm \
tip-list.scm \
tip-of-the-day.scm \
utilities.scm \
xml-generator.scm \
iso-4217-currencies.scm \
engine-init.scm \
commodity-table.scm \
commodity-import.scm \
help-topics-index.scm
xgettext.scm \
xml-generator.scm
gncscm_DATA = ${gnc_autogen_scm_files} ${gnc_regular_scm_files}
@@ -50,6 +51,13 @@ EXTRA_DIST = \
startup-design.txt \
${gnc_regular_scm_files}
guile-strings.c: ${gncscm_DATA}
rm -f guile-strings.c
guile -s ./xgettext.scm ${gncscm_DATA}
CLEANFILES += guile-strings.c
all-local: guile-strings.c
## We borrow guile's convention and use @-...-@ as the substitution
## brackets here, instead of the usual @...@. This prevents autoconf
## from substituting the values directly into the left-hand sides of

View File

@@ -84,6 +84,9 @@
(define gnc:gettext gnc:gettext-helper))
(define gnc:_ gnc:gettext)
(if (not (defined? '_))
(define _ gnc:gettext))
(define (N_ x) x)
;; This database can be used to store and retrieve translatable

View File

@@ -1,2 +1,3 @@
Makefile
Makefile.in
guile-strings.c

View File

@@ -8,3 +8,10 @@ gncscm_DATA = \
EXTRA_DIST = \
.cvsignore \
${gncscm_DATA}
guile-strings.c: ${gncscm_DATA}
rm -f guile-strings.c
guile -s ../xgettext.scm ${gncscm_DATA}
CLEANFILES += guile-strings.c
all-local: guile-strings.c

View File

@@ -1,2 +1,3 @@
Makefile
Makefile.in
guile-strings.c

View File

@@ -8,3 +8,10 @@ gncscm_DATA = \
EXTRA_DIST = \
.cvsignore \
${gncscm_DATA}
guile-strings.c: ${gncscm_DATA}
rm -f guile-strings.c
guile -s ../xgettext.scm ${gncscm_DATA}
CLEANFILES += guile-strings.c
all-local: guile-strings.c

View File

@@ -1,2 +1,3 @@
Makefile
Makefile.in
guile-strings.c

View File

@@ -16,3 +16,10 @@ EXTRA_DIST = \
.cvsignore \
${gncscm_DATA} \
file-format.txt
guile-strings.c: ${gncscm_DATA}
rm -f guile-strings.c
guile -s ../xgettext.scm ${gncscm_DATA}
CLEANFILES += guile-strings.c
all-local: guile-strings.c

View File

@@ -1,2 +1,3 @@
Makefile
Makefile.in
guile-strings.c

View File

@@ -17,3 +17,10 @@ gncscm_DATA = \
EXTRA_DIST = \
.cvsignore \
${gncscm_DATA}
guile-strings.c: ${gncscm_DATA}
rm -f guile-strings.c
guile -s ../xgettext.scm ${gncscm_DATA}
CLEANFILES += guile-strings.c
all-local: guile-strings.c

View File

@@ -109,11 +109,8 @@
(define (accsum_html-table-footer)
"</TABLE>")
(define string-db (gnc:make-string-database))
(define (column-list)
(map (lambda (key) (string-db 'lookup key))
(list 'account-name 'balance )))
(list (_ "Account Name") (_ "Balance")))
(define (non-zero-at-date-accounts accts date)
(if (null? accts)
@@ -184,7 +181,7 @@
(if (null? accounts)
(set! rept-text
(list "<TR><TD>"
(string-db 'lookup 'no-account)
(_ "You have not selected an account.")
"</TD></TR>"))
(begin
@@ -200,28 +197,22 @@
;; Create HTML
(set! rept-data (acc-sum-table accounts enddate dosubs))))
(list prefix
(if (null? accounts)
rept-text
(list (sprintf #f
(string-db 'lookup
(if dosubs
'report-for-and
'report-for))
(gnc:print-date enddate)
acctname
rept-total)
"<p>\n"))
rept-data
;; rept-total
suffix)))
;; Define the strings
(string-db 'store 'account-name "Account Name")
(string-db 'store 'balance "Balance")
(string-db 'store 'no-account "You have not selected an account.")
(string-db 'store 'report-for "Date: %s<br>Report for %s.<br>Accounts Total: %s")
(string-db 'store 'report-for-and "Date: %s<br>Report for %s and all Sub-Accounts.<br>Accounts Total: %s")
(list
prefix
(if (null? accounts)
rept-text
(list
(sprintf #f
(if dosubs
(_ "Date: %s<br>Report for %s and all Sub-Accounts.<br>Accounts Total: %s")
(_ "Date: %s<br>Report for %s.<br>Accounts Total: %s"))
(gnc:print-date enddate)
acctname
rept-total)
"<p>\n"))
rept-data
;; rept-total
suffix)))
(gnc:define-report
;; version

View File

@@ -175,37 +175,35 @@
gnc:*hello-world-options*)
;; Now we create a string database that will make it easier to
;; internationalize this report. Strings that are stored into
;; this database are registered with another component that
;; can save all such strings into a file suitable for gettext
;; parsing. Strings that are retrieved from the database are
;; automatically translated, if a translation is available.
;; Otherwise, the original string is used.
(define string-db (gnc:make-string-database))
;; Here is a helper function for getting the translation of
;; a boolean value.
(define (hello-world:bool->string value)
(string-db 'lookup (if value 'true 'false)))
;; This is a helper function to generate an html list of account names
;; given an account list option.
(define (account-list accounts)
(let ((names (map gnc:account-get-name accounts)))
(if (null? accounts)
(list "<p>" (string-db 'lookup 'no-accounts) "</p>")
(list "<p>" (string-db 'lookup 'selected-accounts) "</p>"
"<ul>"
(map (lambda (name) (list "<li>" name "</li>")) names)
"</ul>"))))
(list
"<p>"
(_ "There are no selected accounts in the account list option.")
"</p>")
(list
"<p>"
(_ "The accounts selected in the account list option are:")
"</p>"
"<ul>"
(map (lambda (name) (list "<li>" name "</li>")) names)
"</ul>"))))
;; This is a helper function to generate an html list for the list option.
(define (list-option-list values)
(let ((names (map symbol->string values)))
(if (null? values)
(list "<p>" (string-db 'lookup 'no-values) "</p>")
(list "<p>" (string-db 'lookup 'selected-values) "</p>"
(list "<p>"
(_ "You have selected no values in the list option.")
"</p>")
(list "<p>"
(_ "The items selected in the list option are:")
"</p>"
"<ul>"
(map (lambda (name) (list "<li>" name "</li>")) names)
"</ul>"))))
@@ -215,8 +213,8 @@
(string-append "<b>" string "</b>"))
;; Here's a helper function for making some of the paragraphs below.
(define (make-para key . values)
(let ((args (append (list #f (string-db 'lookup key)) values)))
(define (make-para text . values)
(let ((args (append (list #f text) values)))
(html-para (apply sprintf args))))
@@ -240,10 +238,14 @@
(let ((bool-val (op-value "Hello, World!" "Boolean Option"))
(mult-val (op-value "Hello, World!" "Multi Choice Option"))
(string-val (op-value "Hello, World!" "String Option"))
(date-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Just a Date Option")))
(date2-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Time and Date Option")))
(rel-date-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Relative Date Option")))
(combo-date-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Combo Date Option")))
(date-val (gnc:date-option-absolute-time
(op-value "Hello, World!" "Just a Date Option")))
(date2-val (gnc:date-option-absolute-time
(op-value "Hello, World!" "Time and Date Option")))
(rel-date-val (gnc:date-option-absolute-time
(op-value "Hello, World!" "Relative Date Option")))
(combo-date-val (gnc:date-option-absolute-time
(op-value "Hello, World!" "Combo Date Option")))
(num-val (op-value "Hello, World!" "Number Option"))
(color-op (get-op "Hello, World!" "Background Color"))
(accounts (op-value "Hello Again" "An account list option"))
@@ -251,13 +253,14 @@
(crash-val (op-value "Testing" "Crash the report")))
;; Crash if asked to.
(if crash-val (string-length #f));; string-length needs a string
(if crash-val (string-length #f)) ;; string-length needs a string
(let ((time-string (strftime "%X" (localtime (current-time))))
(date-string (strftime "%x" (localtime (car date-val))))
(date-string2 (strftime "%x %X" (localtime (car date2-val))))
(rel-date-string (strftime "%x" (localtime (car rel-date-val))))
(combo-date-string (strftime "%x" (localtime (car combo-date-val)))))
(combo-date-string
(strftime "%x" (localtime (car combo-date-val)))))
;; Here's where we generate the html. A real report would need
;; much more code and involve many more utility functions. See
@@ -267,39 +270,56 @@
(list
(html-start-document-color (gnc:color-option->html color-op))
;; Here we get the title using the string database and 'lookup.
"<h2>" (string-db 'lookup 'title) "</h2>"
;; Here we print the title of the report.
;; Note we invoke the _ function upon this string.
;; The _ function works the same way as in C -- if a
;; translation of the given string is available for the
;; current locale, then the translation is returned,
;; otherwise the original string is returned.
"<h2>" (_ "Hello, World") "</h2>"
;; Here we user our paragraph helper
(make-para 'para-1
(string-append "<tt>" gnc:_share-dir-default_
"/gnucash/scm/report" "</tt>"))
(make-para
(_ "This is a sample GnuCash report. \
See the guile (scheme) source code in %s \
for details on writing your own reports, \
or extending existing reports.")
(string-append "<tt>" gnc:_share-dir-default_
"/gnucash/scm/report" "</tt>"))
(make-para 'para-2
(string-append
"<a href=\"mailto:gnucash-devel@gnucash.org\">"
"<tt>gnucash-devel@gnucash.org</tt></a>")
(string-append
"<a href=\"http://www.gnucash.org\">"
"<tt>www.gnucash.org</tt></a>"))
(make-para
(_ "For help on writing reports, or to contribute your brand \
new, totally cool report, consult the mailing list %s. \
For details on subscribing to that list, see %s.")
(string-append
"<a href=\"mailto:gnucash-devel@gnucash.org\">"
"<tt>gnucash-devel@gnucash.org</tt></a>")
(string-append
"<a href=\"http://www.gnucash.org\">"
"<tt>www.gnucash.org</tt></a>"))
(make-para 'time-string (bold time-string))
(make-para (_ "The current time is %s.") (bold time-string))
(make-para 'bool-string (bold (hello-world:bool->string bool-val)))
(make-para (_ "The boolean option is %s.")
(bold (if bool-val (_ "true") (_ "false"))))
(make-para 'multi-string (bold (symbol->string mult-val)))
(make-para (_ "The multi-choice option is %s.")
(bold (symbol->string mult-val)))
(make-para 'string-string (bold string-val))
(make-para (_ "The string option is %s.") (bold string-val))
(make-para 'date-string (bold date-string))
(make-para (_ "The date option is %s.") (bold date-string))
(make-para 'time-date-string (bold date-string2))
(make-para 'rel-date-string (bold rel-date-string))
(make-para (_ "The date and time option is %s.") (bold date-string2))
(make-para 'combo-date-string (bold combo-date-string))
(make-para (_ "The relative date option is %s.")
(bold rel-date-string))
(make-para 'num-string-1 (bold (number->string num-val)))
(make-para (_ "The combination date option is %s.")
(bold combo-date-string))
(make-para (_ "The number option is %s.")
(bold (number->string num-val)))
;; Here we print the value of the number option formatted as
;; currency. When printing currency values, you should use
@@ -307,7 +327,7 @@
;; report-utilities. This functions will format the number
;; appropriately in the current locale. Don't try to format
;; it yourself -- it will be wrong in other locales.
(make-para 'num-string-2
(make-para (_ "The number option formatted as currency is %s.")
(bold
(gnc:amount->string num-val
(gnc:default-print-info #f))))
@@ -316,70 +336,10 @@
(account-list accounts)
(make-para 'nice-day)
(make-para (_ "Have a nice day!"))
(html-end-document)))))
;; Now we store the actual strings we are going to use and
;; finally define the report. Commands to execute must come
;; after definitions in guile.
;; Here we store the string used for the title of the report.
;; The key 'title will be used to get the string (or the
;; translation of the string) later.
(string-db 'store 'title "Hello, World")
;; Now we store the first paragraph as one entire string. The '%s'
;; in the string will be used to substitute for a filename using
;; sprintf. In general, it is better to use sprintf on a whole
;; sentence or paragraph, than to build up the string using
;; concatentation. When it is translated into other languages,
;; the order of the phrases may need to be changed.
(let ((string (string-append "This is a sample GnuCash report. "
"See the guile (scheme) source code in %s "
"for details on writing your own reports, "
"or extending existing reports.")))
(string-db 'store 'para-1 string))
;; Second paragraph
(let ((string
(string-append
"For help on writing reports, or to contribute your brand "
"new, totally cool report, consult the mailing list %s. "
"For details on subscribing to that list, see %s.")))
(string-db 'store 'para-2 string))
;; Here we create some more phrases used in the report.
(string-db 'store 'time-string "The current time is %s.")
(string-db 'store 'bool-string "The boolean option is %s.")
(string-db 'store 'multi-string "The multi-choice option is %s.")
(string-db 'store 'string-string "The string option is %s.")
(string-db 'store 'date-string "The date option is %s.")
(string-db 'store 'time-date-string "The date and time option is %s.")
(string-db 'store 'rel-date-string "The relative date option is %s.")
(string-db 'store 'combo-date-string "The combination date option is %s.")
(string-db 'store 'num-string-1 "The number option is %s.")
(string-db 'store 'num-string-2
"The number option formatted as currency is %s.")
(string-db 'store 'nice-day "Have a nice day!")
(string-db 'store 'true "true")
(string-db 'store 'false "false")
(string-db 'store 'no-accounts
"There are no selected accounts in the account list option.")
(string-db 'store 'selected-accounts
"The accounts selected in the account list option are:")
(string-db 'store 'no-values
"You have selected no values in the list option.")
(string-db 'store 'selected-values
"The items selected in the list option are:")
;; Here we define the actual report with gnc:define-report
(gnc:define-report

61
src/scm/xgettext.scm Normal file
View File

@@ -0,0 +1,61 @@
;; 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))