Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / lang-javascript
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
8 cat <<\EOF > prog.js
9 const Format = imports.format;
10 const Gettext = imports.gettext;
11
12 String.prototype.format = Format.format;
13 const _ = Gettext.gettext;
14
15 Gettext.textdomain ("prog");
16 Gettext.bindtextdomain ("prog", ".");
17 print(_("'Your command, please?', asked the waiter."));
18 print(_("%s is replaced by %s.").format("FF", "EUR"));
19 EOF
20
21 : ${XGETTEXT=xgettext}
22 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.js || exit 1
23 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
24
25 cat <<EOF > prog.ok
26 msgid "'Your command, please?', asked the waiter."
27 msgstr ""
28
29 #, javascript-format
30 msgid "%s is replaced by %s."
31 msgstr ""
32 EOF
33
34 : ${DIFF=diff}
35 ${DIFF} prog.ok prog.pot || exit 1
36
37 cat <<\EOF > fr.po
38 msgid ""
39 msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
40
41 msgid "'Your command, please?', asked the waiter."
42 msgstr "«Votre commande, s'il vous plait», dit le garçon."
43
44 # Reverse the arguments.
45 #, javascript-format
46 msgid "%s is replaced by %s."
47 msgstr "%s remplace %s."
48 EOF
49
50 : ${MSGMERGE=msgmerge}
51 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
52 LC_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
57 test -d fr || mkdir fr
58 test -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
71 # Test which of the fr_FR locales are installed.
72 : ${LOCALE_FR=fr_FR}
73 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
74 if test $LOCALE_FR != none; then
75   LC_ALL=$LOCALE_FR ../testlocale
76   case $? in
77     0) ;;
78     77) LOCALE_FR=none;;
79     *) exit 1;;
80   esac
81 fi
82 if test $LOCALE_FR_UTF8 != none; then
83   LC_ALL=$LOCALE_FR_UTF8 ../testlocale
84   case $? in
85     0) ;;
86     77) LOCALE_FR_UTF8=none;;
87     *) exit 1;;
88   esac
89 fi
90 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
91   if test -f /usr/bin/localedef; then
92     echo "Skipping test: no french locale is installed"
93   else
94     echo "Skipping test: no french locale is supported"
95   fi
96   exit 77
97 fi
98
99 : ${DIFF=diff}
100 cat <<\EOF > prog.ok
101 «Votre commande, s'il vous plait», dit le garçon.
102 FF remplace EUR.
103 EOF
104 cat <<\EOF > prog.oku
105 «Votre commande, s'il vous plait», dit le garçon.
106 FF remplace EUR.
107 EOF
108
109 : ${LOCALE_FR=fr_FR}
110 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
111 if test $LOCALE_FR != none; then
112   prepare_locale_ fr $LOCALE_FR
113   LANGUAGE= LC_ALL=$LOCALE_FR gjs prog.js > prog.out || exit 1
114   ${DIFF} prog.ok prog.out || exit 1
115 fi
116 if test $LOCALE_FR_UTF8 != none; then
117   prepare_locale_ fr $LOCALE_FR_UTF8
118   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gjs prog.js > prog.out || exit 1
119   ${DIFF} -u prog.oku prog.out || exit 1
120 fi
121
122 exit 0