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