New Python backend.

This commit is contained in:
Bruno Haible 2002-02-06 12:58:55 +00:00
parent 86aac5792a
commit f34964a1d7
11 changed files with 1436 additions and 8 deletions

View File

@ -1,3 +1,7 @@
2002-02-02 Bruno Haible <bruno@clisp.org>
* gettext.texi (Python): Update.
2002-02-03 Eli Zaretskii <eliz@is.elta.co.il>
Bruno Haible <bruno@clisp.org>

View File

@ -6566,7 +6566,7 @@ not used by the gettext emulation
emulate. Bug: uses only the first found .mo file, not all of them
@item Extractor
pygettext.py
@code{xgettext}
@item Formatting with positions
@code{'...%(ident)d...' % @{ 'ident': value @}}

View File

@ -1,3 +1,17 @@
2002-02-02 Bruno Haible <bruno@clisp.org>
* x-python.h: New file.
* x-python.c: New file.
* xgettext.c: Include x-python.h.
(main): Call x_python_extract_all, x_python_keyword.
(language_to_scanner): Add Python rule.
(extension_to_language): Add Python rule.
* Makefile.am (noinst_HEADERS): Add x-python.h.
(INCLUDES): Add -I$(top_srcdir)/libuniname.
(LIBUNINAME): New variable.
(xgettext_SOURCES): Add x-python.c.
(xgettext_LDADD): Add $(LIBUNINAME).
2002-02-03 Bruno Haible <bruno@clisp.org>
* msgfmt.c (check_header_entry): Terminate the error strings with

View File

@ -32,7 +32,8 @@ po.h open-po.h read-po.h str-list.h write-po.h dir-list.h file-list.h \
po-gram-gen.h po-hash-gen.h msgl-charset.h msgl-equal.h msgl-iconv.h \
msgl-ascii.h msgl-cat.h msgl-english.h msgfmt.h msgunfmt.h read-mo.h \
write-mo.h read-java.h write-java.h po-time.h plural-table.h format.h \
xgettext.h x-c.h x-po.h x-lisp.h x-elisp.h x-librep.h x-java.h x-ycp.h x-rst.h
xgettext.h x-c.h x-po.h x-python.h x-lisp.h x-elisp.h x-librep.h x-java.h \
x-ycp.h x-rst.h
EXTRA_DIST = FILES project-id \
gnu/gettext/DumpResource.java gnu/gettext/GetURL.java
@ -41,8 +42,8 @@ localedir = $(datadir)/locale
jardir = $(datadir)/gettext
projectsdir = $(pkgdatadir)/projects
INCLUDES = -I. -I$(srcdir) -I.. -I../lib -I$(top_srcdir)/lib -I../intl \
-I$(top_srcdir)/intl
INCLUDES = -I. -I$(srcdir) -I.. -I$(top_srcdir)/libuniname \
-I../lib -I$(top_srcdir)/lib -I../intl -I$(top_srcdir)/intl
DEFS = -DLOCALEDIR=\"$(localedir)\" -DGETTEXTJAR=\"$(jardir)/gettext.jar\" \
-DLIBDIR=\"$(libdir)\" -DPROJECTSDIR=\"$(projectsdir)\" @DEFS@
LDADD = ../lib/libgettextlib.la @LTLIBINTL@
@ -75,6 +76,9 @@ $(COMMON_SOURCE) read-po.c write-po.c msgl-ascii.c msgl-iconv.c msgl-equal.c \
msgl-cat.c msgl-english.c file-list.c msgl-charset.c po-time.c plural.c \
plural-table.c $(FORMAT_SOURCE)
# x-python needs table of Unicode character names.
LIBUNINAME = ../libuniname/libuniname.a
# Source dependencies.
gettext_SOURCES = gettext.c
ngettext_SOURCES = ngettext.c
@ -83,7 +87,8 @@ msgfmt_SOURCES = msgfmt.c write-mo.c write-java.c plural-eval.c
msgmerge_SOURCES = msgmerge.c
msgunfmt_SOURCES = msgunfmt.c read-mo.c read-java.c
xgettext_SOURCES = xgettext.c \
x-c.c x-po.c x-lisp.c x-elisp.c x-librep.c x-java.l x-ycp.c x-rst.c
x-c.c x-po.c x-python.c x-lisp.c x-elisp.c x-librep.c x-java.l x-ycp.c \
x-rst.c
msgattrib_SOURCES = msgattrib.c
msgcat_SOURCES = msgcat.c
msgcomm_SOURCES = msgcomm.c
@ -113,7 +118,7 @@ msgcmp_LDADD = libgettextsrc.la
msgfmt_LDADD = libgettextsrc.la
msgmerge_LDADD = libgettextsrc.la
msgunfmt_LDADD = libgettextsrc.la
xgettext_LDADD = libgettextsrc.la
xgettext_LDADD = libgettextsrc.la $(LIBUNINAME)
msgattrib_LDADD = libgettextsrc.la
msgcat_LDADD = libgettextsrc.la
msgcomm_LDADD = libgettextsrc.la

1191
src/x-python.c Normal file

File diff suppressed because it is too large Load Diff

32
src/x-python.h Normal file
View File

@ -0,0 +1,32 @@
/* xgettext Python backend.
Copyright (C) 2002 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program 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.
This program 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 this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define EXTENSIONS_PYTHON \
{ "py", "Python" }, \
#define SCANNERS_PYTHON \
{ "Python", extract_python, &formatstring_python }, \
/* Scan a Python file and add its translatable strings to mdlp. */
extern void extract_python PARAMS ((FILE *fp, const char *real_filename,
const char *logical_filename,
msgdomain_list_ty *mdlp));
extern void x_python_keyword PARAMS ((const char *keyword));
extern void x_python_extract_all PARAMS ((void));

View File

@ -59,6 +59,7 @@
#include "x-c.h"
#include "x-po.h"
#include "x-python.h"
#include "x-lisp.h"
#include "x-elisp.h"
#include "x-librep.h"
@ -223,6 +224,7 @@ main (argc, argv)
break;
case 'a':
x_c_extract_all ();
x_python_extract_all ();
x_lisp_extract_all ();
x_elisp_extract_all ();
x_librep_extract_all ();
@ -277,6 +279,7 @@ main (argc, argv)
if (optarg == NULL || *optarg != '\0')
{
x_c_keyword (optarg);
x_python_keyword (optarg);
x_lisp_keyword (optarg);
x_elisp_keyword (optarg);
x_librep_keyword (optarg);
@ -1244,13 +1247,13 @@ language_to_extractor (name)
{
SCANNERS_C
SCANNERS_PO
SCANNERS_PYTHON
SCANNERS_LISP
SCANNERS_ELISP
SCANNERS_LIBREP
SCANNERS_JAVA
SCANNERS_YCP
SCANNERS_RST
{ "Python", extract_c, &formatstring_python },
/* Here will follow more languages and their scanners: awk, perl,
etc... Make sure new scanners honor the --exclude-file option. */
};
@ -1287,6 +1290,7 @@ extension_to_language (extension)
{
EXTENSIONS_C
EXTENSIONS_PO
EXTENSIONS_PYTHON
EXTENSIONS_LISP
EXTENSIONS_ELISP
EXTENSIONS_LIBREP

View File

@ -1,3 +1,9 @@
2002-02-02 Bruno Haible <bruno@clisp.org>
* xgettext-18: New file.
* lang-python: New file.
* Makefile.am (TESTS): Add xgettext-18, lang-python.
2002-02-02 Bruno Haible <bruno@clisp.org>
* Makefile.am (INCLUDES): Add -I../lib. Needed for builds with

View File

@ -45,6 +45,7 @@ TESTS = gettext-1 gettext-2 \
xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \
xgettext-7 xgettext-8 xgettext-9 xgettext-10 xgettext-11 xgettext-12 \
xgettext-13 xgettext-14 xgettext-15 xgettext-16 xgettext-17 \
xgettext-18 \
format-c-1 format-c-2 \
format-elisp-1 format-elisp-2 \
format-java-1 format-java-2 \
@ -54,7 +55,7 @@ TESTS = gettext-1 gettext-2 \
format-pascal-1 format-pascal-2 \
format-ycp-1 format-ycp-2 \
plural-1 plural-2 \
lang-c lang-c++ lang-objc lang-clisp lang-elisp lang-librep lang-java lang-pascal lang-ycp lang-po lang-rst \
lang-c lang-c++ lang-objc lang-python lang-clisp lang-elisp lang-librep lang-java lang-pascal lang-ycp lang-po lang-rst \
rpath-1a rpath-1b \
rpath-2aaa rpath-2aab rpath-2aac rpath-2aad \
rpath-2aba rpath-2abb rpath-2abc rpath-2abd \

87
tests/lang-python Executable file
View File

@ -0,0 +1,87 @@
#! /bin/sh
# Test of gettext facilities in the Python language.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="$tmpfiles prog.py"
cat <<\EOF > prog.py
import gettext
gettext.textdomain('prog')
gettext.bindtextdomain('prog', '.')
print gettext.gettext("'Your command, please?', asked the waiter.")
print gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \
% { 'oldCurrency': "FF", 'newCurrency' : "EUR" }
EOF
tmpfiles="$tmpfiles prog.pot"
: ${XGETTEXT=xgettext}
${XGETTEXT} -o prog.pot --omit-header --no-location prog.py
tmpfiles="$tmpfiles prog.ok"
cat <<EOF > prog.ok
msgid "'Your command, please?', asked the waiter."
msgstr ""
#, python-format
msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} prog.ok prog.pot || exit 1
tmpfiles="$tmpfiles fr.po"
cat <<\EOF > fr.po
msgid ""
msgstr ""
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "'Your command, please?', asked the waiter."
msgstr "«Votre commande, s'il vous plait», dit le garçon."
# Reverse the arguments.
#, python-format
msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
msgstr "%(newCurrency)s remplace %(oldCurrency)s."
EOF
tmpfiles="$tmpfiles fr.po.new"
: ${MSGMERGE=msgmerge}
${MSGMERGE} -q -o fr.po.new fr.po prog.pot
: ${DIFF=diff}
${DIFF} fr.po fr.po.new || exit 1
tmpfiles="$tmpfiles fr"
test -d fr || mkdir fr
test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
: ${MSGFMT=msgfmt}
${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
tmpfiles="$tmpfiles prog.ok prog.out"
: ${DIFF=diff}
cat <<\EOF > prog.ok
«Votre commande, s'il vous plait», dit le garçon.
EUR remplace FF.
EOF
# Test for presence of python version 2.0 or newer.
(python -V) >/dev/null 2>/dev/null \
|| { echo "SKIP: lang-python"; rm -fr $tmpfiles; exit 77; }
case `python -c 'import sys; print sys.hexversion >= 0x20000F0'` in
1) ;;
*) echo "SKIP: lang-python"; rm -fr $tmpfiles; exit 77;;
esac
LANGUAGE= LC_ALL=fr_FR python prog.py > prog.out || exit 1
${DIFF} prog.ok prog.out || exit 1
rm -fr $tmpfiles
exit 0

84
tests/xgettext-18 Executable file
View File

@ -0,0 +1,84 @@
#!/bin/sh
# Test of Python support.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="$tmpfiles xg-test18.py"
cat <<\EOF > xg-test18.py
# interpret_ansic = true, interpret_unicode = false
_("abc\
\\def\'ghi\"jkl\a\b\f\n\r\t\v x\040x\x7ey\u0142\U00010123\N{LATIN SMALL LETTER Z}");
# interpret_ansic = false, interpret_unicode = false
_(r"abc\
\\def\'ghi\"jkl\a\b\f\n\r\t\v x\040x\x7ey\u0142\U00010123\N{LATIN SMALL LETTER Z}");
# interpret_ansic = true, interpret_unicode = true
_(u"abc\
\\def\'ghi\"jkl\a\b\f\n\r\t\v x\040x\x7ey\u0142\U00010123\N{LATIN SMALL LETTER Z}");
# interpret_ansic = false, interpret_unicode = true
_(ur"abc\
\\def\'ghi\"jkl\a\b\f\n\r\t\v x\040x\x7ey\u0142\U00010123\N{LATIN SMALL LETTER Z}");
EOF
tmpfiles="$tmpfiles xg-test18.err xg-test18.tmp xg-test18.pot"
: ${XGETTEXT=xgettext}
${XGETTEXT} --add-comments --no-location -o xg-test18.tmp xg-test18.py 2>xg-test18.err
test $? = 0 || { cat xg-test18.err; rm -fr $tmpfiles; exit 1; }
grep -v 'POT-Creation-Date' < xg-test18.tmp > xg-test18.pot
tmpfiles="$tmpfiles xg-test18.ok"
cat <<\EOF > xg-test18.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. interpret_ansic = true, interpret_unicode = false
msgid ""
"abc\\def'ghi\"jkl\b\f\n"
"\r\t x x~y\\u0142\\U00010123\\N{LATIN SMALL LETTER Z}"
msgstr ""
#. interpret_ansic = false, interpret_unicode = false
msgid ""
"abc\\\n"
"\\\\def\\'ghi\\\"jkl\\a\\b\\f\\n\\r\\t\\v x\\040x\\x7ey\\u0142\\U00010123\\N"
"{LATIN SMALL LETTER Z}"
msgstr ""
#. interpret_ansic = true, interpret_unicode = true
msgid ""
"abc\\def'ghi\"jkl\b\f\n"
"\r\t x x~ył𐄣z"
msgstr ""
#. interpret_ansic = false, interpret_unicode = true
msgid ""
"abc\\\n"
"\\\\def\\'ghi\\\"jkl\\a\\b\\f\\n\\r\\t\\v x\\040x\\x7eył\\U00010123\\N{LATIN "
"SMALL LETTER Z}"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-test18.ok xg-test18.pot
result=$?
rm -fr $tmpfiles
exit $result