From: Bruno Haible Date: Tue, 20 Mar 2001 15:07:03 +0000 (+0000) Subject: Add another plural test. X-Git-Tag: v0.10.36~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a06bf5eb986d0272d7b64d236fd345fcd3edb6c;p=thirdparty%2Fgettext.git Add another plural test. --- diff --git a/tests/ChangeLog b/tests/ChangeLog index aff893450..9ccbb72f7 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,13 @@ +2001-03-18 Bruno Haible + + * tstngettext.c: New file. + * plural-2: New file. + * Makefile.am (TESTS): Add plural-2. + (TESTS_ENVIRONMENT): Define NGETTEXT environment variable. + (EXTRA_PROGRAMS): Add tstngettext. + (tstngettext_SOURCES, tstngettext_LDADD): New variables. + * xg-test1.ok.po: Regenerated. + 2001-03-11 Bruno Haible * plural-1-prg.c: Force inclusion of libgnuintl.h. On Solaris, diff --git a/tests/Makefile.am b/tests/Makefile.am index d402cc000..b6c6e6cef 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,7 +22,7 @@ AUTOMAKE_OPTIONS = 1.2 gnits TESTS = gettext-1 gettext-2 msgcmp-1 msgcmp-2 msgfmt-1 msgfmt-2 msgfmt-3 \ msgfmt-4 msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 \ msgunfmt-1 xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 \ - xgettext-6 xgettext-7 xgettext-8 xgettext-9 plural-1 + xgettext-6 xgettext-7 xgettext-8 xgettext-9 plural-1 plural-2 EXTRA_DIST = $(TESTS) test.mo xg-test1.ok.po @@ -30,6 +30,7 @@ XGETTEXT = ../src/xgettext TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=.:../src:$$PATH \ GETTEXT=tstgettext \ + NGETTEXT=tstngettext \ XGETTEXT=`echo xgettext|sed '$(transform)'` \ MSGFMT=`echo msgfmt|sed '$(transform)'` \ MSGCMP=`echo msgcmp|sed '$(transform)'` \ @@ -49,9 +50,11 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ LDADD = $(LDADD_@USE_INCLUDED_LIBINTL@) LDADD_yes = ../intl/libintl.la LDADD_no = ../intl/libgnuintl.la @INTLLIBS@ -EXTRA_PROGRAMS = tstgettext cake +EXTRA_PROGRAMS = tstgettext tstngettext cake tstgettext_SOURCES = tstgettext.c setlocale.c tstgettext_LDADD = ../lib/libnlsut.a $(LDADD) +tstngettext_SOURCES = tstngettext.c setlocale.c +tstngettext_LDADD = ../lib/libnlsut.a $(LDADD) cake_SOURCES = plural-1-prg.c setlocale.c all-local: $(EXTRA_PROGRAMS) CLEANFILES = $(EXTRA_PROGRAMS) diff --git a/tests/plural-2 b/tests/plural-2 new file mode 100755 index 000000000..5a293533c --- /dev/null +++ b/tests/plural-2 @@ -0,0 +1,65 @@ +#! /bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles ll ll.po dataout" +: ${MSGFMT=msgfmt} +test -d ll || mkdir ll +test -d ll/LC_MESSAGES || mkdir ll/LC_MESSAGES + +cat <1 +00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 +gd +n==1 ? 0 : n==2 ? 1 : 2 +20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 +ru +n==1 ? 0 : n%10>=2 && n%10<=4 ? 1 : 2 +20111222222211122222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222 +pl +n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2 +20111222222222222222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222222222222222111222222211122222221112222222111222222211122222221112222222111222222211122222 +sl +n==1 ? 0 : n%10==2 ? 1 : n%10==3 || n%10==4 ? 2 : 3 +30122333333312233333331223333333122333333312233333331223333333122333333312233333331223333333122333333312233333331223333333122333333312233333331223333333122333333312233333331223333333122333333312233333 +EOF +while read lang; do + read formula + read dataok + (echo "msgid \"\"" + echo "msgstr \"\"" + echo "\"MIME-Version: 1.0\\n\"" + echo "\"Content-Type: text/plain; charset=ASCII\\n\"" + echo "\"Content-Transfer-Encoding: 8-bit\\n\"" + echo "\"Plural-Forms: nplurals=10; plural=${formula};\\n\"" + echo + echo "msgid \"X\"" + echo "msgid_plural \"Y\"" + for i in 0 1 2 3 4 5 6 7 8 9 ; do + echo "msgstr[${i}] \"${i}\"" + done) > ll.po + ${MSGFMT} -o ll/LC_MESSAGES/plural.mo ll.po || exit 1 + (for i in '' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do + LANGUAGE= LC_ALL=ll TEXTDOMAIN=plural TEXTDOMAINDIR=. \ + $NGETTEXT X Y ${i}0 ${i}1 ${i}2 ${i}3 ${i}4 ${i}5 ${i}6 ${i}7 ${i}8 ${i}9 + done) > dataout + test "$dataok" = `cat dataout` || { + echo "Formula evaluation error for language $lang" 1>&2 + echo "plural=${formula}" 1>&2 + echo "Expected: $dataok" 1>&2 + echo "Got: "`cat dataout` 1>&2 + exit 1 + } +done + +rm -fr $tmpfiles + +exit 0 diff --git a/tests/tstngettext.c b/tests/tstngettext.c new file mode 100644 index 000000000..a47e09c97 --- /dev/null +++ b/tests/tstngettext.c @@ -0,0 +1,208 @@ +/* ngettext - retrieve plural form strings from message catalog and print them. + Copyright (C) 1995-1997, 2000, 2001 Free Software Foundation, Inc. + + 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. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include + +#include "error.h" +#include "system.h" + +#define HAVE_SETLOCALE 1 +/* Make sure we use the included libintl, not the system's one. */ +#define textdomain textdomain__ +#define bindtextdomain bindtextdomain__ +#define gettext gettext__ +#define dngettext dngettext__ +#undef _LIBINTL_H +#include "libgnuintl.h" + +#define _(str) gettext (str) + +/* Name the program is called with. */ +char *program_name; + +/* Long options. */ +static const struct option long_options[] = +{ + { "domain", required_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +/* Prototypes for local functions. */ +static void usage PARAMS ((int __status)) +#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) + __attribute__ ((noreturn)) +#endif +; + +int +main (argc, argv) + int argc; + char *argv[]; +{ + int optchar; + const char *msgid; + const char *msgid_plural; + const char *count; + unsigned long n; + + /* Default values for command line options. */ + int do_help = 0; + int do_version = 0; + const char *domain = getenv ("TEXTDOMAIN"); + const char *domaindir = getenv ("TEXTDOMAINDIR"); + + /* Set program name for message texts. */ + program_name = argv[0]; + +#ifdef HAVE_SETLOCALE + /* Set locale via LC_ALL. */ + setlocale (LC_ALL, ""); +#endif + + /* Set the text message domain. */ + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + /* Parse command line options. */ + while ((optchar = getopt_long (argc, argv, "+d:hV", long_options, NULL)) + != EOF) + switch (optchar) + { + case '\0': /* Long option. */ + break; + case 'd': + domain = optarg; + break; + case 'h': + do_help = 1; + break; + case 'V': + do_version = 1; + break; + default: + usage (EXIT_FAILURE); + } + + /* Version information is requested. */ + if (do_version) + { + printf ("%s (GNU %s) %s\n", basename (program_name), PACKAGE, VERSION); + /* xgettext: no-wrap */ + printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ +"), + "1995-1997, 2000, 2001"); + printf (_("Written by %s.\n"), "Ulrich Drepper"); + exit (EXIT_SUCCESS); + } + + /* Help is requested. */ + if (do_help) + usage (EXIT_SUCCESS); + + /* More optional command line options. */ + if (argc - optind <= 2) + error (EXIT_FAILURE, 0, _("missing arguments")); + + /* Now the mandatory command line options. */ + msgid = argv[optind++]; + msgid_plural = argv[optind++]; + + /* If no domain name is given we print the original string. + We mark this assigning NULL to domain. */ + if (domain == NULL || domain[0] == '\0') + domain = NULL; + else + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* To speed up the plural-2 test, we accept more than one COUNT in one + call. */ + while (optind < argc) + { + count = argv[optind++]; + + { + char *endp; + unsigned long tmp_val; + + errno = 0; + tmp_val = strtoul (count, &endp, 10); + if (errno == 0 && count[0] != '\0' && endp[0] == '\0') + n = tmp_val; + else + /* When COUNT is not valid, use plural. */ + n = 99; + } + + /* If no domain name is given we don't translate, and we use English + plural form handling. */ + if (domain == NULL) + fputs (n == 1 ? msgid : msgid_plural, stdout); + else + /* Write out the result. */ + fputs (dngettext (domain, msgid, msgid_plural, n), stdout); + } + + exit (EXIT_SUCCESS); +} + + +/* Display usage information and exit. */ +static void +usage (status) + int status; +{ + if (status != EXIT_SUCCESS) + fprintf (stderr, _("Try `%s --help' for more information.\n"), + program_name); + else + { + /* xgettext: no-wrap */ + printf (_("\ +Usage: %s [OPTION] MSGID MSGID-PLURAL COUNT...\n\ + -d, --domain=TEXTDOMAIN retrieve translated message from TEXTDOMAIN\n\ + -h, --help display this help and exit\n\ + -V, --version display version information and exit\n\ + MSGID MSGID-PLURAL translate MSGID (singular) / MSGID-PLURAL (plural)\n\ + COUNT choose singular/plural form based on this value\n"), + program_name); + /* xgettext: no-wrap */ + printf (_("\ +\n\ +If the TEXTDOMAIN parameter is not given, the domain is determined from the\n\ +environment variable TEXTDOMAIN. If the message catalog is not found in the\n\ +regular directory, another location can be specified with the environment\n\ +variable TEXTDOMAINDIR.\n\ +Standard search directory: %s\n"), LOCALEDIR); + fputs (_("Report bugs to .\n"), stdout); + } + + exit (status); +}