1#! /bin/sh 2 3# Test of gettext facilities in the Perl language, 4# using printf format strings. 5# Assumes an fr_FR locale is installed. 6# Assumes the following packages are installed: perl. 7 8tmpfiles="" 9trap 'rm -fr $tmpfiles' 1 2 3 15 10 11tmpfiles="$tmpfiles program.pl" 12cat <<\EOF > program.pl 13use strict; 14 15use Locale::Messages qw (textdomain bindtextdomain gettext ngettext); 16textdomain "prog"; 17bindtextdomain "prog", "./"; 18my $n = 2; 19print gettext "'Your command, please?', asked the waiter."; 20print "\n"; 21printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n; 22print "\n"; 23printf gettext "%s is replaced by %s.", "FF", "EUR"; 24print "\n"; 25EOF 26 27tmpfiles="$tmpfiles prog.pot" 28: ${XGETTEXT=xgettext} 29${XGETTEXT} \ 30 -k__ --flag=__:1:pass-perl-format --flag=__:1:pass-perl-brace-format \ 31 -o prog.pot --omit-header --no-location program.pl 32 33tmpfiles="$tmpfiles prog.ok" 34cat <<EOF > prog.ok 35msgid "'Your command, please?', asked the waiter." 36msgstr "" 37 38#, perl-format 39msgid "a piece of cake" 40msgid_plural "%d pieces of cake" 41msgstr[0] "" 42msgstr[1] "" 43 44#, perl-format 45msgid "%s is replaced by %s." 46msgstr "" 47EOF 48 49: ${DIFF=diff} 50${DIFF} prog.ok prog.pot || exit 1 51 52tmpfiles="$tmpfiles fr.po" 53cat <<\EOF > fr.po 54msgid "" 55msgstr "" 56"Content-Type: text/plain; charset=ISO-8859-1\n" 57"Plural-Forms: nplurals=2; plural=(n > 1);\n" 58 59msgid "'Your command, please?', asked the waiter." 60msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 61 62# Les gateaux allemands sont les meilleurs du monde. 63#, perl-format 64msgid "a piece of cake" 65msgid_plural "%d pieces of cake" 66msgstr[0] "un morceau de gateau" 67msgstr[1] "%d morceaux de gateau" 68 69# Reverse the arguments. 70#, perl-format 71msgid "%s is replaced by %s." 72msgstr "%2$s remplace %1$s." 73EOF 74 75tmpfiles="$tmpfiles fr.po.new" 76: ${MSGMERGE=msgmerge} 77${MSGMERGE} -q -o fr.po.new fr.po prog.pot 78 79: ${DIFF=diff} 80${DIFF} fr.po fr.po.new || exit 1 81 82tmpfiles="$tmpfiles fr" 83test -d fr || mkdir fr 84test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 85 86: ${MSGFMT=msgfmt} 87${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 88 89tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 90: ${DIFF=diff} 91cat <<\EOF > prog.ok 92�Votre commande, s'il vous plait�, dit le gar�on. 932 morceaux de gateau 94EUR remplace FF. 95EOF 96cat <<\EOF > prog.oku 97«Votre commande, s'il vous plait», dit le garçon. 982 morceaux de gateau 99EUR remplace FF. 100EOF 101 102# Test for perl with Locale::Messages package. 103perl -e 'use Locale::Messages;' 2>/dev/null \ 104 || { echo "Skipping test: perl package Locale::Messages is not installed" 105 rm -fr $tmpfiles; exit 77 106 } 107 108: ${LOCALE_FR=fr_FR} 109: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 110if test $LOCALE_FR != none; then 111 LANGUAGE= LANG=$LOCALE_FR LC_MESSAGES= LC_CTYPE= LC_ALL= perl program.pl > prog.out || exit 1 112 ${DIFF} prog.ok prog.out || exit 1 113fi 114if test $LOCALE_FR_UTF8 != none; then 115 LANGUAGE= LANG=$LOCALE_FR_UTF8 LC_MESSAGES= LC_CTYPE= LC_ALL= perl program.pl > prog.out || exit 1 116 ${DIFF} prog.oku prog.out || exit 1 117fi 118if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 119 if test -f /usr/bin/localedef; then 120 echo "Skipping test: no french locale is installed" 121 else 122 echo "Skipping test: no french locale is supported" 123 fi 124 rm -fr $tmpfiles; exit 77 125fi 126 127rm -fr $tmpfiles 128 129exit 0 130