#!/usr/bin/perl

# Little script to read the /usr/lib/menu/* files, and write a
# menu-messages.pot file for them. This file then should contain
# all possible translations, and can be used by translators.'
#
#
# Should be changed to
#  - accept the compat-2 mode
#  - extract /usr/lib/menu/* files from .deb files. Then I'll run it on master.

# Changes:
# - now checks also for longtitles (jfs, Fri Aug 31 02:39:09 CEST 2001)

open(POT, ">menu-messages.pot");

while (</usr/lib/menu/*>){
    my $file=$_;
    open(ME,$_);
    while(<ME>){
	my $line;
	$line=$_;
	chomp($line);
	while($line =~ /\\\s*$/){
	    $line =~ s/\\\s*$//;
	    $line .= <ME>;
	    chomp($line);
	}
	$line =~ s/^[^:]*://;
	$line =~ m/title\s*=\s*"(.*?[^\\])"/ ||
	    $line =~ m/title\s*=\s*([^\s]*)/;
	$title=$1;
	$longtitle=$1 if  $line =~ m/longtitle\s*=\s*"(.*?[^\\])"/;
	$line =~ m/section\s*=\s*"(.*?[^\\])"/ ||
	    $line =~ m/section\s*=\s*([^\s]*)/;
	$section=$1;
	#print "T=$title S=$section LL " . $line . "\n";
	$items{$title}=$file;
	$items{$longtitle}=$file if $longtitle;
	while( $section =~ s%/?([^/]+)/?%% ){
	    $items{$1}=$file;
	}
    }
    close(ME);
}


$date=`/bin/date +"%Y-%d-%m %H:%M+%Z"`;

print POT "# Collection of titles/sections of debian menu's.
# This file is automatically generated. Do not edit.
# It's generated from the /usr/lib/menu/* files.
#
#, fuzzy
msgid \"\"
msgstr \"\"
\"Project-Id-Version: MENU VERSION\\n\"
\"POT-Creation-Date: $date\\n\"
\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"
\"Last-Translator: FULL NAME <e-mail\@address>\\n\"
\"MIME-Version: 1.0\\n\"
\"Content-Type: text/plain; charset=CHARSET\\n\"
\"Content-Transfer-Encoding: ENCODING\\n\"

";

for my $s (sort keys %items){
    print POT "#: Found in " . $items{$s} . "\n";
    print POT "msgid \"" . $s . "\"\n";
    print POT "msgstr \"\"\n\n";
}












