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