Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / xgettext-javascript-1
1 #!/bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test of JavaScript support.
5
6 cat <<\EOF > xg-js-1.js
7 var s1 = "Simple string, no gettext needed",
8     s2 = _("Extract this first string");
9 function foo(a) {
10     var s3 = "Prefix _(" + _("Extract this second string") + ") Postfix";
11 }
12 if (document.getElementsById("foo")[0].innerHTML == _("Extract this third string")) {
13     /* _("This is a comment and must not be extracted!") */
14 }
15 /* TRANSLATORS: This is a translator comment.  */
16 gettext('Extract this fourth string');
17 // TRANSLATORS: This is another translator comment.
18 gettext('Extract this fifth string');
19 EOF
20
21 : ${XGETTEXT=xgettext}
22 ${XGETTEXT} --add-comments=TRANSLATORS: --no-location -o xg-js-1.tmp xg-js-1.js 2>xg-js-1.err
23 test $? = 0 || { cat xg-js-1.err; exit 1; }
24 # Don't simplify this to "grep ... < xg-js-1.tmp", otherwise OpenBSD 4.0 grep
25 # only outputs "Binary file (standard input) matches".
26 cat xg-js-1.tmp | grep -v 'POT-Creation-Date' | LC_ALL=C tr -d '\r' > xg-js-1.pot
27
28 cat <<\EOF > xg-js-1.ok
29 # SOME DESCRIPTIVE TITLE.
30 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
31 # This file is distributed under the same license as the PACKAGE package.
32 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
33 #
34 #, fuzzy
35 msgid ""
36 msgstr ""
37 "Project-Id-Version: PACKAGE VERSION\n"
38 "Report-Msgid-Bugs-To: \n"
39 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
40 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
41 "Language-Team: LANGUAGE <LL@li.org>\n"
42 "Language: \n"
43 "MIME-Version: 1.0\n"
44 "Content-Type: text/plain; charset=CHARSET\n"
45 "Content-Transfer-Encoding: 8bit\n"
46
47 msgid "Extract this first string"
48 msgstr ""
49
50 msgid "Extract this second string"
51 msgstr ""
52
53 msgid "Extract this third string"
54 msgstr ""
55
56 #. TRANSLATORS: This is a translator comment.
57 msgid "Extract this fourth string"
58 msgstr ""
59
60 #. TRANSLATORS: This is another translator comment.
61 msgid "Extract this fifth string"
62 msgstr ""
63 EOF
64
65 : ${DIFF=diff}
66 ${DIFF} xg-js-1.ok xg-js-1.pot
67 result=$?
68
69 exit $result