1#!/bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test Python support: --from-code option and encoding recognition.
5
6# Note: This test fails on Linux with musl libc versions that don't support
7# the EUC-JP encoding in 'iconv'.
8
9cat <<\EOF > xg-py-3a.py
10#!/usr/bin/env python
11# TRANSLATORS: Fran���ois Pinard is a hero.
12print gettext.gettext("���ܸ�");
13EOF
14
15cat <<\EOF > xg-py-3b.py
16#!/usr/bin/env python
17                       # Hey Emacs! -*- coding: euc-jp -*-
18# TRANSLATORS: Fran���ois Pinard is a hero.
19print gettext.gettext("���ܸ�");
20EOF
21
22cat <<\EOF > xg-py-3u.py
23#!/usr/bin/env python
24# TRANSLATORS: François Pinard is a hero.
25print gettext.gettext("日本語");
26EOF
27
28cat <<\EOF > xg-py-3.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
35msgid ""
36msgstr ""
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=UTF-8\n"
45"Content-Transfer-Encoding: 8bit\n"
46
47#. TRANSLATORS: François Pinard is a hero.
48msgid "日本語"
49msgstr ""
50EOF
51
52# Verify that if the source file has no magic coding comment, xgettext fails
53# if no --from-code option is given but succeeds if it is given.
54: ${XGETTEXT=xgettext}
55${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
56  -d xg-py-3a xg-py-3a.py > /dev/null 2>&1
57test $? = 1 || { Exit 1; }
58${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=euc-jp \
59  -o xg-py-3a.tmp xg-py-3a.py || Exit 1
60func_filter_POT_Creation_Date xg-py-3a.tmp xg-py-3a.pot
61
62: ${DIFF=diff}
63${DIFF} xg-py-3.ok xg-py-3a.pot || Exit 1
64
65# Verify that if the source file has a magic coding comment, xgettext succeeds.
66
67${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
68  -o xg-py-3b.tmp xg-py-3b.py || Exit 1
69func_filter_POT_Creation_Date xg-py-3b.tmp xg-py-3b.pot
70
71${DIFF} xg-py-3.ok xg-py-3b.pot || Exit 1
72
73# Verify that if the source file has no magic coding comment but is UTF-8
74# encoded, xgettext succeeds. (PEP 3120)
75
76${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
77  -o xg-py-3u.tmp xg-py-3u.py || Exit 1
78func_filter_POT_Creation_Date xg-py-3u.tmp xg-py-3u.pot
79
80${DIFF} xg-py-3.ok xg-py-3u.pot || Exit 1
81
82# Verify that if the source file has a magic coding comment and a --from-code
83# option is given, the magic coding comment takes precedence over it.
84
85${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=iso-8859-1 \
86  -o xg-py-3c.tmp xg-py-3b.py || Exit 1
87func_filter_POT_Creation_Date xg-py-3c.tmp xg-py-3c.pot
88
89${DIFF} xg-py-3.ok xg-py-3c.pot || Exit 1
90
91# Verify that backslashes in and second bytes with value 0x5C are correctly
92# distinguished in weird encodings like BIG5.
93
94cat <<\EOF > xg-py-3d.py
95#!/usr/bin/env python
96                       # Hey Emacs! -*- coding: big5 -*-
97print gettext.gettext(u"�\u0021");
98print gettext.gettext(u"�\\u0021");
99EOF
100
101${XGETTEXT} --add-comments=TRANSLATORS: \
102  -o xg-py-3d.tmp xg-py-3d.py || Exit 1
103func_filter_POT_Creation_Date xg-py-3d.tmp xg-py-3d.pot
104
105cat <<\EOF > xg-py-3d.ok
106# SOME DESCRIPTIVE TITLE.
107# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
108# This file is distributed under the same license as the PACKAGE package.
109# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
110#
111#, fuzzy
112msgid ""
113msgstr ""
114"Project-Id-Version: PACKAGE VERSION\n"
115"Report-Msgid-Bugs-To: \n"
116"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
117"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
118"Language-Team: LANGUAGE <LL@li.org>\n"
119"Language: \n"
120"MIME-Version: 1.0\n"
121"Content-Type: text/plain; charset=UTF-8\n"
122"Content-Transfer-Encoding: 8bit\n"
123
124#: xg-py-3d.py:3
125msgid "枯u0021"
126msgstr ""
127
128#: xg-py-3d.py:4
129msgid "枯!"
130msgstr ""
131EOF
132
133${DIFF} xg-py-3d.ok xg-py-3d.pot || Exit 1
134
135Exit 0
136