#!/usr/bin/perl -w
        
#
#  The i18n Unicode Encoding Utility
#
#  Copyright (C) 2001 Free Software Foundation.
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this library; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  Authors:  Kenneth Christiansen <kenneth@gnu.org>
#

my $LANG = $ARGV[0];
my $VERBOSE="1";

if (! $LANG) { 
   print "You must specify the language\n"; 
}

open IN, "$LANG.po";

while (<IN>) {
    ## example: "Content-Type: text/plain; charset=ISO-8859-1\n"
    if (/Content-Type\:.*charset=(.*)\\n/) {
       	$encoding_code_orig = $1; 
	last;
    }
}

close IN;

print "Converting from $encoding_code_orig\n" if $VERBOSE;

my $extern_conv="iconv --from=$encoding_code_orig "
	       ."--to=UTF-8 $LANG.po > $LANG.po-1";

system($extern_conv);

my $source_orig;
{
    local (*IN);
    local $/; #slurp mode
    open (IN, "<$LANG.po-1") || die "can't open $LANG.po-1: $!";
    $source_orig = <IN>;
}

$source_orig =~ s/Content-Type\:(.*)$encoding_code_orig/Content-Type\:$1UTF-8/;

close IN;

open OUT, ">$LANG.po-1";
print OUT $source_orig;
close OUT;
