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 Lintian::po_debconf;
31 # First, check wether this package seems to use debconf but not po-debconf.
32 # Read the templates file and look at the template names it provides, since
33 # some shared templates aren't translated.
34 opendir(DEB, 'debfiles')
35 or fail("Can't open debfiles directory.");
36 my $has_template = my $has_depends = my $has_config = 0;
38 for my $file (readdir(DEB)) {
39 next if -d "debfiles/$file";
40 if ($file =~ m/^(.+\.)?templates(\..+)?$/) {
41 if ($file =~ m/templates\.\w\w(_\w\w)?$/) {
42 push (@lang_templates, $file);
44 open(PO, '<', "debfiles/$file")
45 or fail("Can't open debfiles/$file file.");
47 tag "translated-default-field", "$file: $."
48 if (m/^_Default(Choice)?: [^\[]*$/);
49 if (/^Template: (\S+)/i) {
51 next if $template =~ m,^shared/packages-(wordlist|ispell)$,;
52 next if $template =~ m,/languages$,;
62 #TODO: check whether all templates are named in TEMPLATES.pot
63 if ( $has_template ) {
64 if ( ! -d "debfiles/po" ) {
65 tag "not-using-po-debconf", "";
72 # If we got here, we're using po-debconf, so there shouldn't be any stray
73 # language templates left over from debconf-mergetemplate.
74 for (@lang_templates) {
75 tag "stray-translated-debconf-templates", $_ unless /templates\.in$/;
78 # yada builds its template and po/POTFILES.in dynamically at build time, so
79 # excuse yada from some of these checks (including the out of date templates
81 my $missing_files = 0;
83 if (open (RULES, '<', 'debfiles/rules')) {
86 if (m%^\t\s*(?:perl debian/)?yada\s%) {
93 if (!$yada && -f "debfiles/po/POTFILES.in") {
94 open(POTFILES, '<', "debfiles/po/POTFILES.in")
95 or fail("Can't open debfiles/po/POTFILES.in.");
99 # Cannot check files which are not under debian/
100 next if m,^\.\./, or $_ eq '';
101 unless (-f "debfiles/$_") {
102 tag "missing-file-from-potfiles-in", "$_";
108 tag "missing-potfiles-in", "";
111 if (! -f "debfiles/po/templates.pot") {
112 tag "missing-templates-pot", "";
116 if (-x "/usr/bin/msgcmp" && -x "/usr/share/intltool-debian/intltool-update" ) {
117 if ($missing_files == 0) {
118 $ENV{"INTLTOOL_EXTRACT"} ||= "/usr/share/intltool-debian/intltool-extract";
119 system_env("cd debfiles/po && /usr/share/intltool-debian/intltool-update --gettext-package=test --pot");
120 system_env("/usr/bin/msgcmp --use-untranslated debfiles/po/test.pot debfiles/po/templates.pot >/dev/null 2>&1"
121 . "&& /usr/bin/msgcmp --use-untranslated debfiles/po/templates.pot debfiles/po/test.pot >/dev/null 2>&1") == 0
122 or tag "newer-debconf-templates";
125 fail("either msgcmp or intltool-update not found");
128 if (! -x "/usr/bin/msgfmt" ) {
129 fail("msgfmt not found");
131 opendir(DEBIAN, 'debfiles/po')
132 or fail("Can't open debfiles/po directory.");
133 while (defined(my $file=readdir(DEBIAN))) {
134 next unless $file =~ m/\.po$/;
135 tag "misnamed-po-file", "debian/po/$file"
136 unless ($file =~ /^[a-z]{2,3}(_[A-Z]{2})?\.po$/);
139 open(PO, '<', "debfiles/po/$file")
140 or fail("Can't open debfiles/po/$file file.");
146 tag "invalid-po-file", "debian/po/$file";
151 if (m/charset=(.*?)\\n/) {
152 $charset = ($1 eq 'CHARSET' ? '' : $1);
154 tag "unknown-encoding-in-po-file", "debian/po/$file"
155 unless length($charset);
156 system_env("msgfmt -o /dev/null debfiles/po/$file 2>/dev/null") == 0
157 or tag "invalid-po-file", "debian/po/$file";
165 # indent-tabs-mode: t
166 # cperl-indent-level: 8