From: Bruno Haible Date: Mon, 24 Feb 2003 10:49:59 +0000 (+0000) Subject: Support for plural forms in xgettext --language=Python. X-Git-Tag: v0.12~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3bfe25c25e5d49659b3214987fa6a40fceb8f29;p=thirdparty%2Fgettext.git Support for plural forms in xgettext --language=Python. --- diff --git a/NEWS b/NEWS index 16f770b93..7c666ffa1 100644 --- a/NEWS +++ b/NEWS @@ -12,11 +12,26 @@ Version 0.12-pre1 - February 2003 program maintainers. xgettext, accordingly, has a new option --msgid-bugs-address. -* xgettext now also supports Smalltalk and PHP. +* Programming languages support: -* A new C++ class, called gnu::autosprintf, makes it possible to use C format - strings in C++. This is needed for proper internationalization of C++ - programs. + - C++ + + A new C++ class, called gnu::autosprintf, makes it possible to use + C format strings in C++. This is needed for proper internationalization + of C++ programs. + + - Smalltalk + + xgettext now also supports Smalltalk. + + - PHP + + xgettext now also supports PHP. + + - Python + + "xgettext --language=Python" now supports the plural handling functions + ngettext, dngettext, ungettext (introduced in Python 2.3). * A new include file libgettextpo, with public header file "gettext-po.h", provides functions for reading PO files into memory. It is useful for @@ -31,11 +46,13 @@ Version 0.12-pre1 - February 2003 xgettext has a new option --from-code that specifies the encoding of the source files. The resulting POT files are UTF-8 encoded. -* msgmerge has a new option -N/--no-fuzzy-matching that inhibits the fuzzy - search for untranslated messages. +* Tools for translators: + + - msgmerge has a new option -N/--no-fuzzy-matching that inhibits the fuzzy + search for untranslated messages. -* msgattrib has new options --only-file and --ignore-file that cause the - specified attribute manipulation to apply to selected messages only. + - msgattrib has new options --only-file and --ignore-file that cause the + specified attribute manipulation to apply to selected messages only. * Compatibility with automake-1.7. diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 9f2bbf8f8..16012276e 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,7 @@ +2003-02-22 Bruno Haible + + * gettext.texi (Python): Mention ngettext. + 2003-02-22 Bruno Haible * Makefile.am (MOSTLYCLEANFILES): No need to clean the unused indices. diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index 40dba0745..0bd82c335 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -7469,7 +7469,9 @@ python @code{_('abc')} etc. @item gettext/ngettext functions -@code{gettext.gettext}, @code{gettext.dgettext}, also @code{ugettext} +@code{gettext.gettext}, @code{gettext.dgettext}, +@code{gettext.ngettext}, @code{gettext.dngettext}, +also @code{ugettext}, @code{ungettext} @item textdomain @code{gettext.textdomain} function, or diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 592ecb121..439703e7c 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,8 @@ +2003-02-22 Bruno Haible + + * x-python.c (init_keywords): Add u*gettext variants and plural + handling functions added in Python 2.3. + 2003-02-22 Bruno Haible * Makefile.am (installdirs): Remove dependency, redundant with diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 5efd314d6..74e9a78b2 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -1,5 +1,5 @@ /* xgettext Python backend. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2002. @@ -126,7 +126,11 @@ init_keywords () if (default_keywords) { x_python_keyword ("gettext"); + x_python_keyword ("ugettext"); x_python_keyword ("dgettext:2"); + x_python_keyword ("ngettext:1,2"); + x_python_keyword ("ungettext:1,2"); + x_python_keyword ("dngettext:2,3"); x_python_keyword ("_"); default_keywords = false; } diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index fc1995fc5..d093c0923 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,10 @@ +2003-02-22 Bruno Haible + + * lang-python-1: Renamed from lang-python. Make it work with Python + 2.3. + * lang-python-2: New file. + * Makefile.am (TESTS): Remove lang-python, add lang-python-[12]. + 2003-02-20 Bruno Haible * msgfilter-1: Remove SKIP: messages, now emitted by the Makefile. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 64f8ad46d..0d76e1e35 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -60,7 +60,7 @@ TESTS = gettext-1 gettext-2 \ format-tcl-1 format-tcl-2 \ format-ycp-1 format-ycp-2 \ plural-1 plural-2 \ - lang-c lang-c++ lang-objc lang-python lang-clisp \ + lang-c lang-c++ lang-objc lang-python-1 lang-python-2 lang-clisp \ lang-elisp lang-librep lang-smalltalk lang-java lang-gawk lang-pascal \ lang-ycp lang-tcl lang-php lang-po \ lang-rst diff --git a/gettext-tools/tests/lang-python-2 b/gettext-tools/tests/lang-python-2 new file mode 100755 index 000000000..ef14e0eb4 --- /dev/null +++ b/gettext-tools/tests/lang-python-2 @@ -0,0 +1,107 @@ +#! /bin/sh + +# Test of gettext facilities (including plural handling) in the Python +# language. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles prog.py" +cat <<\EOF > prog.py +import sys +import gettext + +n = int(sys.argv[1]) + +gettext.textdomain('prog') +gettext.bindtextdomain('prog', '.') + +print gettext.gettext("'Your command, please?', asked the waiter.") +print gettext.ngettext("a piece of cake","%(count)d pieces of cake",n) \ + % { 'count': n } +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 < prog.ok +msgid "'Your command, please?', asked the waiter." +msgstr "" + +#, python-format +msgid "a piece of cake" +msgid_plural "%(count)d pieces of cake" +msgstr[0] "" +msgstr[1] "" + +#, 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." + +# Les gateaux allemands sont les meilleurs du monde. +#, python-format +msgid "a piece of cake" +msgid_plural "%(count)d pieces of cake" +msgstr[0] "un morceau de gateau" +msgstr[1] "%(count)d morceaux de gateau" + +# 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 + +# Test for presence of python version 2.3 or newer. +(python -V) >/dev/null 2>/dev/null \ + || { rm -fr $tmpfiles; exit 77; } +case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in + 1 | True) ;; + *) rm -fr $tmpfiles; exit 77;; +esac + +tmpfiles="$tmpfiles prog.ok prog.out" +: ${DIFF=diff} +cat <<\EOF > prog.ok +«Votre commande, s'il vous plait», dit le garçon. +2 morceaux de gateau +EUR remplace FF. +EOF + +LANGUAGE= LC_ALL=fr_FR python prog.py 2 > prog.out || exit 1 +${DIFF} prog.ok prog.out || exit 1 + +rm -fr $tmpfiles + +exit 0