1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test of gettext facilities in the JavaScript language. 5# Assumes an fr_FR locale is installed. 6# Assumes the following packages are installed: gjs. 7 8cat <<\EOF > prog.js 9const Format = imports.format; 10const Gettext = imports.gettext; 11 12String.prototype.format = Format.format; 13const _ = Gettext.gettext; 14 15Gettext.textdomain ("prog"); 16Gettext.bindtextdomain ("prog", "."); 17print(_("'Your command, please?', asked the waiter.")); 18print(_("%s is replaced by %s.").format("FF", "EUR")); 19EOF 20 21: ${XGETTEXT=xgettext} 22${XGETTEXT} -o prog.tmp --omit-header --no-location prog.js || Exit 1 23LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 24 25cat <<EOF > prog.ok 26msgid "'Your command, please?', asked the waiter." 27msgstr "" 28 29#, javascript-format 30msgid "%s is replaced by %s." 31msgstr "" 32EOF 33 34: ${DIFF=diff} 35${DIFF} prog.ok prog.pot || Exit 1 36 37cat <<\EOF > fr.po 38msgid "" 39msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" 40 41msgid "'Your command, please?', asked the waiter." 42msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 43 44# Reverse the arguments. 45#, javascript-format 46msgid "%s is replaced by %s." 47msgstr "%2$s remplace %1$s." 48EOF 49 50: ${MSGMERGE=msgmerge} 51${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 52LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 53 54: ${DIFF=diff} 55${DIFF} fr.po fr.po.new || Exit 1 56 57test -d fr || mkdir fr 58test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 59 60: ${MSGFMT=msgfmt} 61${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 62 63# Test for presence of gjs. 64(gjs -h) >/dev/null 2>/dev/null \ 65 || { echo "Skipping test: gjs not found"; Exit 77; } 66(gjs -c imports.gettext) >/dev/null 2>/dev/null \ 67 || { echo "Skipping test: gjs gettext module not found"; Exit 77; } 68(gjs -c imports.format) >/dev/null 2>/dev/null \ 69 || { echo "Skipping test: gjs format module not found"; Exit 77; } 70# Test for presence of gjs version 1.40 or newer. 71(gjs -c 'print(imports.format.vprintf("%3$s%2$s%1$s", ["x","y","z"]))') 2>/dev/null | grep zyx >/dev/null \ 72 || { echo "Skipping test: gjs version is older than 1.40"; Exit 77; } 73 74# Test which of the fr_FR locales are installed. 75: ${LOCALE_FR=fr_FR} 76: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 77if test $LOCALE_FR != none; then 78 LC_ALL=$LOCALE_FR ../testlocale 79 case $? in 80 0) ;; 81 77) LOCALE_FR=none;; 82 *) Exit 1;; 83 esac 84fi 85if test $LOCALE_FR_UTF8 != none; then 86 LC_ALL=$LOCALE_FR_UTF8 ../testlocale 87 case $? in 88 0) ;; 89 77) LOCALE_FR_UTF8=none;; 90 *) Exit 1;; 91 esac 92fi 93if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 94 if test -f /usr/bin/localedef; then 95 echo "Skipping test: no french locale is installed" 96 else 97 echo "Skipping test: no french locale is supported" 98 fi 99 Exit 77 100fi 101 102: ${DIFF=diff} 103cat <<\EOF > prog.ok 104�Votre commande, s'il vous plait�, dit le gar�on. 105EUR remplace FF. 106EOF 107cat <<\EOF > prog.oku 108«Votre commande, s'il vous plait», dit le garçon. 109EUR remplace FF. 110EOF 111 112: ${LOCALE_FR=fr_FR} 113: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 114if test $LOCALE_FR != none; then 115 prepare_locale_ fr $LOCALE_FR 116 LANGUAGE= LC_ALL=$LOCALE_FR gjs prog.js > prog.out || Exit 1 117 ${DIFF} prog.ok prog.out || Exit 1 118fi 119if test $LOCALE_FR_UTF8 != none; then 120 prepare_locale_ fr $LOCALE_FR_UTF8 121 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gjs prog.js > prog.out || Exit 1 122 ${DIFF} -u prog.oku prog.out || Exit 1 123fi 124 125Exit 0 126