Added lots more modules from lintian. Maemian appears to work.
[maemian] / checks / po-debconf
1 # po-debconf -- lintian check script -*- perl -*-
2
3 # Copyright (C) 2002-2004 by Denis Barbier <barbier@linuxfr.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 package Maemian::po_debconf;
22 use strict;
23 use Tags;
24 use Util;
25
26 sub run {
27
28 my $pkg = shift;
29 my $type = shift;
30
31 my $full_translation = 0;
32
33 # First, check wether this package seems to use debconf but not po-debconf.
34 # Read the templates file and look at the template names it provides, since
35 # some shared templates aren't translated.
36 opendir(DEB, 'debfiles')
37         or fail("Can't open debfiles directory.");
38 my $has_template = my $has_depends = my $has_config = 0;
39 my @lang_templates;
40 for my $file (readdir(DEB)) {
41         next if -d "debfiles/$file";
42         if ($file =~ m/^(.+\.)?templates(\..+)?$/) {
43                 if ($file =~ m/templates\.\w\w(_\w\w)?$/) {
44                         push (@lang_templates, $file);
45                 } else {
46                         open(PO, '<', "debfiles/$file")
47                                 or fail("Can't open debfiles/$file file.");
48                         while (<PO>) {
49                                 tag "translated-default-field", "$file: $."
50                                         if (m/^_Default(Choice)?: [^\[]*$/);
51                                 if (/^Template: (\S+)/i) {
52                                         my $template = $1;
53                                         next if $template =~ m,^shared/packages-(wordlist|ispell)$,;
54                                         next if $template =~ m,/languages$,;
55                                         $has_template = 1;
56                                 }
57                         }
58                         close PO;
59                 }
60         }
61 }
62 closedir(DEB);
63
64 #TODO: check whether all templates are named in TEMPLATES.pot
65 if ( $has_template ) {
66     if ( ! -d "debfiles/po" ) {
67         tag "not-using-po-debconf", "";
68         return 0;
69     }
70 } else {
71     return 0;
72 }
73
74 # If we got here, we're using po-debconf, so there shouldn't be any stray
75 # language templates left over from debconf-mergetemplate.
76 for (@lang_templates) {
77     tag "stray-translated-debconf-templates", $_ unless /templates\.in$/;
78 }
79
80 # yada builds its template and po/POTFILES.in dynamically at build time, so
81 # excuse yada from some of these checks (including the out of date templates
82 # check).
83 my $missing_files = 0;
84 my $yada = 0;
85 if (open (RULES, '<', 'debfiles/rules')) {
86     local $_;
87     while (<RULES>) {
88         if (m%^\t\s*(?:perl debian/)?yada\s%) {
89             $yada = 1;
90             $missing_files = 1;
91         }
92     }
93 }
94
95 if (!$yada && -f "debfiles/po/POTFILES.in") {
96         open(POTFILES, '<', "debfiles/po/POTFILES.in")
97                 or fail("Can't open debfiles/po/POTFILES.in.");
98         while (<POTFILES>) {
99                 chomp;
100                 s/.*\]\s*//;
101                 #  Cannot check files which are not under debian/
102                 next if m,^\.\./, or $_ eq '';
103                 unless (-f "debfiles/$_") {
104                         tag "missing-file-from-potfiles-in", "$_";
105                         $missing_files = 1;
106                 } 
107         }
108         close(POTFILES);
109 } elsif (!$yada) {
110         tag "missing-potfiles-in", "";
111         $missing_files = 1;
112 }
113 if (! -f "debfiles/po/templates.pot") {
114         tag "missing-templates-pot", "";
115         $missing_files = 1;
116 }
117
118 if (-x "/usr/bin/msgcmp" && -x "/usr/share/intltool-debian/intltool-update" ) {
119         if ($missing_files == 0) {
120                 $ENV{"INTLTOOL_EXTRACT"} ||= "/usr/share/intltool-debian/intltool-extract";
121                 system_env("cd debfiles/po && /usr/share/intltool-debian/intltool-update --gettext-package=test --pot");
122                 system_env("/usr/bin/msgcmp --use-untranslated debfiles/po/test.pot debfiles/po/templates.pot >/dev/null 2>&1"
123                            . "&& /usr/bin/msgcmp --use-untranslated debfiles/po/templates.pot debfiles/po/test.pot >/dev/null 2>&1") == 0
124                         or tag "newer-debconf-templates";
125         }
126 } else {
127         fail("either msgcmp or intltool-update not found");
128 }
129
130 if (! -x "/usr/bin/msgfmt" ) {
131         fail("msgfmt not found");
132 }
133 opendir(DEBIAN, 'debfiles/po')
134         or fail("Can't open debfiles/po directory.");
135 while (defined(my $file=readdir(DEBIAN))) {
136         next unless $file =~ m/\.po$/;
137         tag "misnamed-po-file", "debian/po/$file"
138                 unless ($file =~ /^[a-z]{2,3}(_[A-Z]{2})?\.po$/);
139         local ($/) = "\n\n";
140         $_ = '';
141         open(PO, '<', "debfiles/po/$file")
142                 or fail("Can't open debfiles/po/$file file.");
143         while (<PO>) {
144                 last if m/^msgstr/m;
145         }
146         close(PO);
147         unless ($_) {
148                 tag "invalid-po-file", "debian/po/$file";
149                 next;
150         }
151         s/"\n"//g;
152         my $charset = '';
153         if (m/charset=(.*?)\\n/) {
154                 $charset = ($1 eq 'CHARSET' ? '' : $1);
155         }
156         tag "unknown-encoding-in-po-file", "debian/po/$file"
157                 unless length($charset);
158         system_env("msgfmt -o /dev/null debfiles/po/$file 2>/dev/null") == 0
159                 or tag "invalid-po-file", "debian/po/$file";
160
161         my $stats = `LANG=C msgfmt -o /dev/null --statistics debfiles/po/$file 2>&1`;
162         if (!$full_translation && $stats =~ m/^\w+ \w+ \w+\.$/) {
163                 $full_translation = 1;
164         }
165 }
166
167 tag "no-complete-debconf-translation", "" if !$full_translation;
168
169 }
170
171 1;
172
173 # Local Variables:
174 # indent-tabs-mode: t
175 # cperl-indent-level: 8
176 # End:
177 # vim: syntax=perl