File: em_installtdeb

package info (click to toggle)
emdebian-tools 1.4.3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,112 kB
  • ctags: 274
  • sloc: perl: 6,297; xml: 4,828; sh: 1,902; php: 406; ansic: 189; makefile: 15
file content (764 lines) | stat: -rwxr-xr-x 24,619 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
#!/usr/bin/perl

=head1 NAME

em_installtdeb - generate Emdebian TDeb translation packages and source.

=cut

use strict;
use warnings;
use Cwd;
use Parse::DebControl;
use Debian::DpkgCross;
use Debian::Debhelper::Dh_Lib;
use File::Basename;
# avoid using Emdebian::Tools here.

=head1 SYNOPSIS

B<em_installtdeb>

B<em_installtdeb> S<I<-a|--arch ARCHITECTURE>>

B<em_installtdeb> [S<I<LANG_CODE>>]

B<em_installtdeb> [S<I<-a|--arch ARCHITECTURE>>] [S<I<--no-act>>]

B<em_installtdeb> [S<I<-a|--arch ARCHITECTURE>>] [S<I<--no-sign>>]

=cut

=head1 DESCRIPTION

em_installtdeb is a debhelper add-on created by Emdebian to create
translation packages (tdebs). em_installtdeb is intended to separate
out the individual translation files from the current Debian packages
into packages without any translation files and a series of tdeb
locale packages, one per translation.
Generated packages use the syntax:
$package-locale-$language_code_$version_$arch.deb

(Note that TDebs are architecture-dependent.)

Unlike other cross building related tools, em_installtdeb does B<NOT> read
your default dpkg-cross architecture. This is because it also needs to be
usable for native builds. When crossbuilding, ensure you explicitly set
the -a|--arch option. (emdebuild does this for you.)

Once a package uses em_installtdeb, translation files should be removed
from all packages in the normal build. em_installtdeb runs as a second
build (very small, very fast) that simply converts and packages the I<*.po>
files into tdebs. A tdeb source package is created (.dsc, .tar.gz and
.changes) alongside the existing build data. The source package is used
by translators to build updated or new tdeb packages. Tdeb .changes files
need to be uploaded only to secondary locale repositories instead of the
main Debian mirrors and these repositories can have much more relaxed
upload policies. Tdeb packages have no dependencies and no packages may
depend upon them.

em_installtdeb currently only supports gettext translation.

Certain language codes need to be modified to make acceptable components
of a debian package name. Underscores are converted to hyphens,
'@' is converted to '+' and all codes are made lowercase. These changes only
apply to the package name, the installation location is unchanged.

The locale package must use GETTEXT_PACKAGE for the eventual filename
of the binary translation file - although this may be the same as the
$dh{MAINPACKAGE}. GETTEXT_PACKAGE is determined by upstream, not Debian.
When building the whole package, the binary translation file may be in
debian/tmp/usr/share/locale/$lang/LC_MESSAGES but when in translator mode,
this location is not available. Instead retrieve GETTEXT_PACKAGE from
the POT filename, the Makefile GETTEXT_PACKAGE macro or if that is not set,
use the upstream source package name. This may need extending.

The "source" for translators therefore includes:

 debian/rules  /* dummy file */
 debian/control
 debian/changelog
 po*/$lang.po  /* if any */
 po*/$GETTEXT_PACKAGE.pot /* may be more than one */

Some packages use multiple po directories and em_installtdeb checks for
a POT file in all usable po directories, including them in the tdeb source
along with all po files: e.g.

 po/fr.po
 po-lib/fr.po
 po/application.pot
 po-lib/library.pot

When packaged, the tdeb built from this source would contain:

 ./usr/share/locale/fr/LC_MESSAGES/application.mo
 ./usr/share/locale/fr/LC_MESSAGES/library.mo

An equivalent tdeb for the 'de' locale would contain:

 ./usr/share/locale/de/LC_MESSAGES/application.mo
 ./usr/share/locale/de/LC_MESSAGES/library.mo

This compares with the Debian "space-is-cheap" model of separating the
application.mo and library.mo files but combining all the translations in
one package, so that the equivalent Debian package would contain:

 ./usr/share/locale/cs/LC_MESSAGES/application.mo
 ./usr/share/locale/de/LC_MESSAGES/application.mo
 ./usr/share/locale/fr/LC_MESSAGES/application.mo
...
 ./usr/share/locale/sv/LC_MESSAGES/application.mo
 ./usr/share/locale/ro/LC_MESSAGES/application.mo
 ./usr/share/locale/vi/LC_MESSAGES/application.mo

(Repeated again for the other package.)

Many packages contain dozens of translations - some contain over 70 .mo
files and .mo files can vary between 2kb and 30kb each. Without tdebs,
all users get all 70 translations even if only one or two are used.
With tdebs, all users get both the library and the application translations
but only for the one or two locales supported by that installation. The extra
granularity achieved by splitting application.mo and library.mo into separate
packages for the same locale is not likely to be worth the workload. (In effect,
this means that packages with multiple translations are not actually
supported - at least not in the original manner.) It is possible that
developments like I<dpkg filtering> will be able to implement this final
level of division, where necessary.

em_installtdeb will try to generate the necessary POT file(s) and then create
a $package_$version_tdeb.tar.gz containing the source files.

Any package can have a source tdeb, as long as the POT file is either
packaged or can be built. The package does not have to have been translated
already.

For more detail on Tdebs, see:
L<http://www.emdebian.org/emdebian/langupdate.html>
L<http://wiki.debian.org/i18n/TranslationDebs>

Note that the Emdebian implementation of tdebs differs from the proposed tdebs for
Debian because Emdebian does not care about manpages in general, let alone
translated manpages. Once the 'nodocs' DEB_BUILD_OPTION is supported in debhelper,
this will not be an issue as the tdebs can be built for Emdebian without any
manpages. Other translated documentation would be omitted under 'nodocs' too.
Images containing translated text are relatively few.

To manage the increase in package numbers (average ten fold), the secondary
locale repository organises the tdeb packages by locale root, e.g. 'en_GB' is
beneath 'en' and 'sr@Latn' beneath 'sr'. Each locale root becomes a single
apt source in the locale repository to support fallback from a specific locale
to a the more general locale root. In this manner, each device only has to
cope with cache data for a fraction of the total number of tdeb packages
(roughly 1 part in 30).

A new C/C++ application then handles the installation and update of tdeb
packages according to the list of supported locales and the list of
installed packages. Data cached by I<langupdate> is temporary and is 
not intended to be stored between runs of I<langupdate>.

=cut

=head1 OPTIONS

The default action is to process all available po files.

This mode is used by package maintainers to generate tdeb source and
binaries at the end of the Debian build (with translation files
omitted). Note that this means a second .dsc, second .changes, a
second (much smaller) .tar.gz using the tdeb.tar.gz suffix and a separate
upload to the secondary locale repositories. I<emdebian-tools> will include
handlers for these operations and Debian can create similar wrappers as
needed.

=over 4

=item LANG_CODE

LANG_CODE can either be the name of the locale as specified in the PO
filename (fr, en_GB, sr@Ltn etc.) or the name of the locale as specified
in the eventual package name (fr, en-gb, sr+ltn etc.).

If a po file already exists for this locale, em_installtdeb processes
just that one translation and builds a single tdeb package.

If the po file does not exist, em_installtdeb exits with an error. (Copy
the POT file from the original source to create a new po file for the
new locale and edit it to include the new translation, then run
em_installtdeb again.)

LANG_CODE is intended as a 'translator mode' where individual tdeb packages
can be built by the translator and uploaded to a suitable repository.
em_installtdeb creates the tdeb source tarball, a usable .dsc file to
describe the tdeb source and a tdeb.changes file.

=item no-act

em_installtdeb will just print the control data that would be used for
the tdeb if the debhelper B<--no-act> option is used.

=item no-sign

em_installtdeb normally calls 'debsign' when the .changes is written. This
option suppresses this behaviour.

=back

=cut

=head1 Use in Debian

Note that the use of debian/xcontrol in the current script means
that XS-TDeb-Build-Directory and XS-TDeb-POT-Names will need to
be supported in debian/control before adoption by Debian.
At the same time, XC-Package-Type: tdeb needs support too.

=cut

=head1 Other translations

Packages may also contain translated manpages and translations for debconf
templates. These translations are not packaged or processed by em_installtdeb
because Emdebian does not need to handle such files and because each variant
will need customised handling (most of the debconf support is already
available). If Tdebs are to be supported in Debian, these issues will need
to be resolved such that Emdebian can continue to only package the
gettext program translations, omitting translated manpages and leaving
debconf translation support to existing tools.

=cut

use vars qw/@packages $mainpackage %control_lines $dummy_lines $lang $fullname
$section $priority %lang_equiv $file %lang_codes @new_locales $topdirprefix
$finprefix $finsuffix $single $gettext_package @podirs %gettextdirs $version
$sign @names $builddir $source $arch /;

$sign=0;
&read_config();
$arch = &get_architecture();
# Get the HOST arch as default. (Yes, this is deliberate.)
$arch = `dpkg-architecture -qDEB_HOST_ARCH`;
chomp($arch);

while( @ARGV ) {
	$_= shift( @ARGV );
	last if m/^--$/;
	if (!/^-/) {
		unshift(@ARGV,$_);
		last;
	}
	elsif (/^(--no-sign)$/) {
		$sign++;
	}
	elsif (/^(-a|--arch)$/) {
		$arch = shift(@ARGV);
	}
}

my $target_gnu_type = &check_arch($arch);
die ("Cannot determine the architecture to build.\n")
	if ((not defined $arch) or ($arch eq "") or (not defined $target_gnu_type));

=head1 Use of debhelper::init

The problem with init is that $dh{DOPACKAGES} works from debian/control
and the locale packages are not B<*in*> debian/control. So em_installtdeb
gets the "Source: " package name to use as the prefix for the locale package
names.

=cut

&init;
# the lang_code parameter is still in @ARGV after init.
die ("Only one lang code can be specified at a time in translator mode.\n")
	if (scalar @ARGV > 1);
$single = pop @ARGV if (@ARGV);

# need data from debian/control even if xcontrol does not exist.
my $parser = new Parse::DebControl;
my $options;
my $xcontrol = $parser->parse_file('./debian/control', $options);
# only read the source stanza
for my $stanza (@$xcontrol)
{
	$source = $stanza->{'Source'} if (defined $stanza->{'Source'})
}
$mainpackage = (not defined $single) ? $source : $single;
$mainpackage =~ s/-locale-*$//;

&parse_control;
exit 0;

sub dummy_control
{
	my $clog = `dpkg-parsechangelog`;
	my $r = $clog;
	$clog =~ /Version: (.*)\n/;
	$version = $1;
	$r =~ /Maintainer: (.*)\n/;
	my $maint = $1;
	# $mainpackage is the root for all locale packages.
	$mainpackage =~ s/-$//;
	$dummy_lines = "Source: $mainpackage\n";
	$dummy_lines .= "Priority: extra\n";
	$dummy_lines .= "Section: misc\n";
	# Only archive scripts need these - remove when possible.
	$dummy_lines .= "Maintainer: $maint\n";
	$dummy_lines .= "Standards-Version: ".&get_standards_version."\n";
}

sub print_control
{
	$lang = shift;
	$control_lines{$lang} = "";
	# $mainpackage is the root for all locale packages.
	$mainpackage =~ s/-$//;
	$fullname = $mainpackage . "-locale-" . $lang;
	my $newdeb = "Package: $fullname\n";
	$newdeb .= "Architecture: $arch\n";
	$newdeb .= "Priority: extra\n";
	$newdeb .= "Section: misc\n";
	$newdeb .= "Description: $lang translation for $mainpackage\n";
#	$newdeb .= "XC-Package-Type: tdeb\n";
	$newdeb .= "\n";
	$control_lines{$lang} .= $newdeb;
}

sub get_gettext_names
{
	my $podir = shift;
	# this fails if the package uses a build-tree.
	if (-f "$podir/Makefile")
	{
		open (MK, "$podir/Makefile") or die ("Failed to read $podir/Makefile: $!\n");
		my @mkfile=<MK>;
		close MK;
		my @gp_ = grep /GETTEXT_PACKAGE*/, @mkfile;
		foreach my $gp (@gp_)
		{
			chomp($gp);
			$gp =~ s/ //g;
			if ($gp =~ /^GETTEXT_PACKAGE=(.*)$/)
			{
				return $1;
			}
		}
		@gp_ = grep /domainname*/i, @mkfile;
		foreach my $gp (@gp_)
		{
			chomp($gp);
			$gp =~ s/ //g;
			if ($gp =~ /^domainname=(.*)$/i)
			{
				return $1;
			}
		}
	}
	else
	{
		opendir (POT, "$podir") or die ("Cannot open $podir\n");
		my @potname=grep(/\.pot$/, readdir(POT));
		closedir (POT);
		if (@potname)
		{
			my $name = $potname[0];
			$name =~ s/(.*)\.pot$/$1/;
			return $name if (defined ($name));
		}
	}
	# if no po/Makefile exists, try the top_srcdir Makefile
	if (-f "Makefile")
	{
		open (MK, "Makefile") or die ("Failed to read Makefile: $!\n");
		my @mkfile=<MK>;
		close MK;
		my @gp_ = grep /GETTEXT_PACKAGE*/, @mkfile;
		foreach my $gp (@gp_)
		{
			chomp($gp);
			$gp =~ s/ //g;
			if ($gp =~ /^GETTEXT_PACKAGE=(.*)$/)
			{
				return $1;
			}
		}
	}
	# if all this fails, use debian/xcontrol instead.
	return $mainpackage;
}

sub check_debian
{
	my $pkg;
	# check this is a debian working directory
	until (-f "debian/changelog")
	{
		chdir ".." or die "Cannot change directory ../ $!";
		if (cwd() eq '/')
		{
			die "Cannot find debian/changelog anywhere!\nAre you in the source code tree?\n";
		}
	}
	# try to assume that po/ exists
	@podirs= `find . -name 'po*' -a -type d`;
	my @templist = ();
	foreach my $podir (@podirs)
	{
		chomp($podir);
		next unless $podir =~ /\/po[-]?.*/;
		next unless (-d $podir);
		# ignore debconf translations, for now.
		next if ($podir =~ m#^\./debian/po#);
		# ignore manpage translations - wrap in nodocs support.
		next if ($podir =~ m#manpage#);
		push @templist, $podir;
	}
	@podirs = @templist;
	unlink "debian/files";
	# if custom support requested, avoid tampering with POT files.
	return if (@names);
	foreach my $podir (@podirs)
	{
		my @potfiles= `find $podir -maxdepth 1 -name '*po' -type f`;
		next unless @potfiles;
		$gettext_package = &get_gettext_names($podir);
		# one package per po directory
		$gettextdirs{$gettext_package} = $podir;
		if (scalar @potfiles == 0)
		{
			# if no POT file exists, try to make it.
			# the Makefile in the $podir always uses GETTEXT_PACKAGE
			# for *this* POT file even if the top_srcdir Makefile
			# uses more than one GETTEXT variable.
			system ("make -C $podir $gettext_package.pot") if (-f "$podir/Makefile");
		}
		die "Cannot find POT file in $podir!\n"
			if (not defined $gettext_package);
	}
}

sub parse_xcontrol
{
	my $xcontrol;
	return $xcontrol if (! -f "debian/xcontrol");
	my $parser = new Parse::DebControl;
	my $options;
	$xcontrol = $parser->parse_file('./debian/xcontrol', $options);
	return $xcontrol;
}

sub find_messages
{
	my $code;
	my $v = "";
	# skip our own packages
	return if ($_[0] =~ /\Q-locale-\E/);
	# gettext dirs *should* be the same as podirs but not all
	# packages play by those rules.
	foreach my $podir (@podirs)
	{
		chomp ($podir);
		next unless $podir =~ /\/po[-]?.*/;
		next unless (-d $podir);
		my @pofiles=`find $podir -name '*po' -a -type f`;
		next unless @pofiles;
		foreach my $pofile (@pofiles)
		{
			chomp($pofile);
			my $c = basename ($pofile);
			$pofile = $c;
			$pofile =~ /^(.*)\.po$/;
			my $a = $code = $1;
			next unless (defined ($code));
			$code =~ s/[_]/-/;
			$code =~ s/[@]/+/;
			$code = lc ($code);
			$code =~ s/\/.*//;
			$a =~ s/\/.*//;
			# if a package has more than one translation, only set one lang_code
			$lang_codes{$code} = 1;
			$lang_equiv{$code} = $a;
		}
	}
}

sub parse_control
{
	my @package_list = ();
	# remove any trailing hyphen.
	$mainpackage =~ s/-$//;
	my $pkg;
	@names=();
	my $xcontrol = &parse_xcontrol;
	# only interested in top stanza (Source: )
	my $stanza = $$xcontrol[0];
	if (defined $stanza->{'XS-TDeb-Build-Directory'} or
		defined $stanza->{'XS-TDeb-POT-Names'})
	{
		$builddir = $stanza->{'XS-TDeb-Build-Directory'};
		my @tmp = split(',', $stanza->{'XS-TDeb-POT-Names'});
		foreach my $n (@tmp)
		{
			$n =~ s/^\s+//;
			push @names, $n;
		}
	}
	# check if a changelog exists
	&check_debian;
	&find_messages($mainpackage);
	# check to prevent duplication
	my @sorted = sort (keys %lang_codes);
	# nothing to do if @sorted is empty
	return unless (@sorted);
	&dummy_control;
	open (DEB, ">debian/dummy-control") or
		die ("Cannot open debian/dummy-control: $!\n");
	print DEB $dummy_lines;
	close DEB;
	if (defined $single)
	{
		my $code;
		my $tmppkg = $single;
		my $tmppo = $lang_equiv{$single};
		if (not defined ($tmppo))
		{
			# convert $single if in po form rather than dpkg form
			$code = $single;
			$code =~ s/[_]/-/;
			$code =~ s/[@]/+/;
			$code = lc ($code);
			$code =~ s/\/.*//;
			$tmppkg = $code;
			$tmppo = $lang_equiv{$code};
		}
		if (not defined ($tmppo))
		{
			my @pots = `find . -name '*.pot'`;
			foreach my $pot (@pots)
			{
				chomp ($pot);
				my $d = dirname($pot);
				print "Please create: '$d/$single.po' using: $pot\n";
			}
			die ("No '$single' translation found.\n");
		}
		$single = $tmppkg;
		$fullname = $mainpackage . "-locale-" . $single;
		&print_control($single);
		&install_files($single);
		&generate_source;
		unlink ("debian/dummy-control");
		return;
	}
	foreach $lang (@sorted)
	{
		$fullname = $mainpackage . "-locale-" . $lang;
		&print_control($lang);
		&install_files($lang);
	}
	# bug - refactor generate_source to not need these.
	$single = $lang = $mainpackage;
	&generate_source;
	unlink ("debian/dummy-control");
}

sub install_files
{
	my $lang=shift;
	$topdirprefix="debian/${mainpackage}-locale-";
	$finprefix="/usr/share/locale/";
	$finsuffix="/LC_MESSAGES";
	my $tmppkg = $lang;
	my $tmppo = $lang_equiv{$lang};
	my @cmds=();
	push @cmds, "install -d ${topdirprefix}$tmppkg/DEBIAN";
	push @cmds, "install -d ${topdirprefix}${tmppkg}${finprefix}${tmppo}${finsuffix}";
	# need to handle $dh{NO_ACT}
	if (defined $dh{NO_ACT})
	{
		print $dummy_lines;
		print "\n";
		print $control_lines{$tmppkg};
	}
	else
	{
		foreach my $cmd (@cmds)
		{
			system ($cmd);
		}
		@cmds=();
		open (DEB, ">${topdirprefix}$tmppkg/DEBIAN/control") or
			die ("Cannot open ${topdirprefix}$tmppkg/DEBIAN/control: $!\n");
		print DEB $dummy_lines;
		print DEB "\n";
		print DEB $control_lines{$tmppkg};
		close DEB;
		open (DEB, ">>debian/dummy-control") or
			die ("Cannot open debian/dummy-control: $!\n");
		print DEB "\n";
		print DEB $control_lines{$tmppkg};
		close DEB;
	}
	foreach my $gpkg (keys %gettextdirs)
	{
		my $pdir = $gettextdirs{$gpkg};
		next unless $pdir =~ /\/po[-]?.*/;
		next unless (-d $pdir);
		next unless (-f "$pdir/$tmppo.po");
		my $endian = &get_endianness;
		my $cross = "--endianness $endian" if (defined $endian);
		push @cmds, "msgfmt $cross -o $pdir/$tmppo.gmo $pdir/$tmppo.po" if (! -f "$pdir/$tmppo.gmo");
		push @cmds, "install -m 0644 $pdir/$tmppo.gmo ${topdirprefix}${tmppkg}${finprefix}${tmppo}".
			"${finsuffix}/${gpkg}.mo";
	}
	# some packages, like apt, use specialised handling which is
	# supported using fields in debian/xcontrol.
	if ((defined (@names)) and (defined ($builddir)))
	{
		foreach my $d (@names)
		{
			next unless (-d "$builddir/$d/");
			my @custom_po = `find $builddir/$d/ -name $tmppo\.mo -type f`;
			foreach my $custom (@custom_po)
			{
				chomp ($custom);
				push @cmds, "install -m 0644 $custom ${topdirprefix}${tmppkg}${finprefix}${tmppo}".
					"${finsuffix}/$d.mo";
			}
		}
	}
	push @cmds, "DEB_HOST_ARCH=$arch dpkg-gencontrol ".
		"-p${mainpackage}-locale-$tmppkg ".
		"-P${topdirprefix}${tmppkg} -cdebian/dummy-control";
	push @cmds, "dpkg --build ${topdirprefix}${tmppkg} .. ";
	# add clean up commands.
	push @cmds, "rm -rf debian/${mainpackage}-locale*";
	push @cmds, "rm -f po*/*.gmo";
	# need to handle $dh{NO_ACT}
	if (defined $dh{NO_ACT})
	{
		print join ("\n", @cmds);
		print "\n";
	}
	else
	{
		# do the real work here.
		foreach my $cmd (@cmds)
		{
			doit ("$cmd");
		}
	}
}

sub get_standards_version
{
	return "3.7.3";
}

=head1 Translator mode

This is a special mode, not usually something that debhelper would do. In
translator mode, I<debian/rules> is not used. em_installtdeb does everything
needed to configure, build, install and package the requested tdeb and the
appropriate tdeb source package using a temporary directory to ensure that
the correct control and changelog data is available.

There are a few issues with this method - the build needs a debian/changelog
but also needs to create the translation as a native package (to prevent the
need for an empty .diff.gz) even if the upstream package is non-native. The
current solution is to create a new version (with tdeb appended) to create
a clean changelog entry that does not try to re-close bugs from the original
upload and then use that version to force dpkg-source to treat the tdeb
source as a native package. This may need changing in future but such
changes are likely to need support in dpkg. This method, whilst not ideal,
does work with the existing support. Using a modified version also ensures
that the generated files do not interfere with other builds in the same
location. Although not used, an empty I<debian/rules> file is added.

if DEBSIGN_KEYID is defined, em_installtdeb tries to use debsign to sign
the .tdeb.changes and .dsc files. This could be made optional if it is
later decided that translation uploads will need full changelog entries to
close bugs in the Debian BTS. Part of the appeal of tdebs is that i18n bugs
would not normally need to be filed in the BTS.

=cut

sub generate_source
{
	# strip the epoch
	my $epoch_ver = $version;
	$version =~ s/^[0-9]://;
	my $srcversion = $version;
	$srcversion =~ s/\-[em0-9]*$//;
	my $tdebdir = `mktemp -d -t tdeb-${single}.XXXXXXXXXX`;
	chomp($tdebdir);
	my $pkg = "../${mainpackage}-locale-*_${version}_$arch.deb";
	system ("mkdir -p $tdebdir/${mainpackage}-${srcversion}/debian/");
	# copy debian/files into place.
	system ("cp debian/files $tdebdir/${mainpackage}-${srcversion}/debian/") if (-f "debian/files");
	system ("cp debian/dummy-control $tdebdir/${mainpackage}-${srcversion}/debian/control");
	system ("cp debian/changelog $tdebdir/${mainpackage}-${srcversion}/debian/");
	my $loc = cwd();
	# Add a new version to the upstream changelog to mask Closes: etc that
	# are not relevant to the translator upload.
	chdir ("$tdebdir/${mainpackage}-${srcversion}");
	my $msg = "-v${epoch_ver}tdeb TDeb translation for $lang";
	my $changes = "-sa";
	if ($version =~ /tdeb$/)
	{
		$msg = "-a TDeb update for $lang";
		$changes = "-b";
	}
	system ("dch -p $msg");
	# add a dummy rules file to keep dpkg-source -x happy.
	open (RULES, ">debian/rules");
	print RULES "#!/usr/bin/make -f\n\n";
	close (RULES);
	chmod (0755, "debian/rules");
	# add a fallback dummy Makefile to retrieve the GETTEXT_PACKAGE macro
	open (MK, ">Makefile");
	print MK "GETTEXT_PACKAGE = $gettext_package";
	close MK;
	chdir ($loc);
	foreach my $pd (@podirs)
	{
		next unless $pd =~ /\/po[-]?.*/;
		next unless (-d $pd);
		next unless `find $pd -maxdepth 1 -name '*po' -type f`;
		my $final = $pd;
		$final =~ s/.*\///;
		system ("mkdir -p $tdebdir/${mainpackage}-${srcversion}/$final");
		system ("cp $pd/*.po $tdebdir/${mainpackage}-${srcversion}/$final/");
		next unless `find $pd -maxdepth 1 -name '*pot' -type f`;
		system ("cp $pd/*.pot $tdebdir/${mainpackage}-${srcversion}/$final/");
	}
	my @extrapot = `find . -name *.pot`;
	system ("mkdir $tdebdir/${mainpackage}-${srcversion}/po")
		if ((@extrapot) and (! -d "$tdebdir/${mainpackage}-${srcversion}/po"));
	foreach my $ex (@extrapot)
	{
		chomp ($ex);
		system ("cp $ex $tdebdir/${mainpackage}-${srcversion}/po/");
	}
	# create the tdeb source .tar.gz
	system ("cp $pkg $tdebdir");
	chdir ("$tdebdir/");
	system ("tar -czf ${mainpackage}_${version}tdeb.tar.gz ./${mainpackage}-${srcversion}/");
	# create the .dsc without trashing the working directory and force native.
	system ("dpkg-source -b ${mainpackage}-${srcversion}/ ");
	# create the .changes
	chdir ("$tdebdir/${mainpackage}-${srcversion}");
	system ("dpkg-genchanges $changes | tee ../${mainpackage}_${version}tdeb_$arch.changes");
	chdir ("$loc");
	system ("cp $tdebdir/*.dsc ../");
	system ("cp $tdebdir/*.tar.gz ../");
	system ("cp $tdebdir/*.changes ../");
	chdir ("${mainpackage}-${srcversion}");
	system ("rm -rf $tdebdir");
	print "Changes file: ../${mainpackage}_${version}tdeb_$arch.changes\n";
	# check for DEBSIGN_KEYID before trying debsign
	if ((defined $ENV{DEBSIGN_KEYID}) and ($sign == 0)) {
		system ("debsign ../${mainpackage}_${version}tdeb.changes");
	}
	unlink ("debian/files");
}