#!/usr/bin/perl -w

=head1 NAME

debconf-mergetemplate - merge together multiple debconf template files

=cut

use strict;
use Debconf::Template::Transient;

=head1 SYNOPSIS

 debconf-mergetemplate file [file ..]

=head1 DESCRIPTION

This program is useful if you have multiple debconf templates files which
you want to merge together into one big file. All the specified files will
be read in, merged, and output to standard output.

This can be especially useful if you are dealing with translated template
files. In this case, you might have your main template file, plus several
other files provided by the translators. These files will have translated
fields in them, and maybe the translators left in the english versions of
the fields they translated, for their reference. 

So, you want to merge together all the translated templates files
with your main templates file. Any fields that are unique to the translated
files need to be added in to the correct templates, but any fields they have
in common should be superceded by the fields in the main file (which might be
more up-to-date).

This program handles that case properly, just list each of the translated
templates files, and then your main templates file last.

=head1 SEE ALSO

L<debconf-getlang(1)>

=cut

# Ignore the users locale settings.
Debconf::Template::Transient->i18n(0);

my %templates;
foreach my $template (map { Debconf::Template::Transient->load($_) } @ARGV) {
	if (exists $templates{$template->template}) {
		$templates{$template->template}->merge($template);
	}
	else {
		$templates{$template->template}=$template;
	}
}

print Debconf::Template::Transient->stringify(values %templates);

=head1 AUTHOR

Joey Hess <joey@kitenet.net>

=cut
