1 # po-debconf -- lintian check script -*- perl -*-
3 # Copyright (C) 2002-2004 by Denis Barbier <barbier@linuxfr.org>
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.
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.
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,
21 package Maemian::po_debconf;
31 my $full_translation = 0;
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;
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);
46 open(PO, '<', "debfiles/$file")
47 or fail("Can't open debfiles/$file file.");
49 tag "translated-default-field", "$file: $."
50 if (m/^_Default(Choice)?: [^\[]*$/);
51 if (/^Template: (\S+)/i) {
53 next if $template =~ m,^shared/packages-(wordlist|ispell)$,;
54 next if $template =~ m,/languages$,;
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", "";
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$/;
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
83 my $missing_files = 0;
85 if (open (RULES, '<', 'debfiles/rules')) {
88 if (m%^\t\s*(?:perl debian/)?yada\s%) {
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.");
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", "$_";
110 tag "missing-potfiles-in", "";
113 if (! -f "debfiles/po/templates.pot") {
114 tag "missing-templates-pot", "";
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";
127 fail("either msgcmp or intltool-update not found");
130 if (! -x "/usr/bin/msgfmt" ) {
131 fail("msgfmt not found");
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$/);
141 open(PO, '<', "debfiles/po/$file")
142 or fail("Can't open debfiles/po/$file file.");
148 tag "invalid-po-file", "debian/po/$file";
153 if (m/charset=(.*?)\\n/) {
154 $charset = ($1 eq 'CHARSET' ? '' : $1);
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";
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;
167 tag "no-complete-debconf-translation", "" if !$full_translation;
174 # indent-tabs-mode: t
175 # cperl-indent-level: 8