#!/usr/bin/perl
# Script to print translators of a package with their languages.
# Checks up until the latest edit of NEWS, or the first commit,
# whichever comes first.
# By Thomas Thurman <thomas@thurman.org.uk>.
# Public domain.

use strict;
use warnings;

open LOG, "git log --pretty=format:%an --name-only|"
	or die "Can't open log: $!";

my %translators;
my $author;
while (<LOG>) {
	chomp;
	if (!$_) {
		$author = undef;
		next;
	}

	if ($author) {
		last if $_ eq 'NEWS';

		if (m!po/(.*?)\.po!) {
			$translators{$1} = {} unless defined $translators{$1};
			$translators{$1}->{$author} = 1;
		}
	} else {
		$author = $_;
	}
}
while (<LOG>) { }

close LOG or die "Can't close log: $!";

my $result = '';
for my $language (sort keys %translators) {
	$result .= '; ' if $result;
	$result .= join ', ', keys %{$translators{$language}};
	$result .= " ($language)";
}

my @result = split /\s+/, $result . '.';

my @lines = ('');
for (@result) {
	if (length($lines[-1])+length($_)+1 > 80) {
		push @lines, $_;
	} else {
		$lines[-1] .= ' ' unless $lines[-1] eq '' && length(@lines)==1;
		$lines[-1] .= $_;
	}
}
$result = join "\n", @lines;
print "$result\n";
