]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Support for plural forms in xgettext --language=Python.
authorBruno Haible <bruno@clisp.org>
Mon, 24 Feb 2003 10:49:59 +0000 (10:49 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:14 +0000 (12:10 +0200)
NEWS
gettext-tools/doc/ChangeLog
gettext-tools/doc/gettext.texi
gettext-tools/src/ChangeLog
gettext-tools/src/x-python.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/lang-python-2 [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 16f770b93bdecb145998459e9ef7920368786e5f..7c666ffa1d669e08c5256e4e5f7cca780c923d4d 100644 (file)
--- 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.
 
index 9f2bbf8f8db84800a5bf48a272cb8844a61eb6ab..16012276eee42dca331187f7631a1c80a489d88c 100644 (file)
@@ -1,3 +1,7 @@
+2003-02-22  Bruno Haible  <bruno@clisp.org>
+
+       * gettext.texi (Python): Mention ngettext.
+
 2003-02-22  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (MOSTLYCLEANFILES): No need to clean the unused indices.
index 40dba0745701a66c412e6eee5171227d8c4ec5b4..0bd82c3354f77d360ee26595e768e0082bc9ec58 100644 (file)
@@ -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
index 592ecb12145d1f778dff75b1d11116a2a165a7be..439703e7c9a943789f7b8f2b86ecfc7533f53f87 100644 (file)
@@ -1,3 +1,8 @@
+2003-02-22  Bruno Haible  <bruno@clisp.org>
+
+       * x-python.c (init_keywords): Add u*gettext variants and plural
+       handling functions added in Python 2.3.
+
 2003-02-22  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (installdirs): Remove dependency, redundant with
index 5efd314d65f521bc64331eb3c7b8fd3d6c4ea15f..74e9a78b23d07221eb138cfcbe3b81a46c46298f 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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;
     }
index fc1995fc5ba5f139d69d5c9eb465d78a0b2272dd..d093c09236bc56c677b61335efd118456b39fc4a 100644 (file)
@@ -1,3 +1,10 @@
+2003-02-22  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * msgfilter-1: Remove SKIP: messages, now emitted by the Makefile.
index 64f8ad46d458d7fa96b616ada91c8942ef82ffa5..0d76e1e35bac802ca68136c415195643b2a350cf 100644 (file)
@@ -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 (executable)
index 0000000..ef14e0e
--- /dev/null
@@ -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 <<EOF > 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