1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | # |
---|
4 | # The i18n Unicode Encoding Utility |
---|
5 | # |
---|
6 | # Copyright (C) 2001 Free Software Foundation. |
---|
7 | # |
---|
8 | # This library is free software; you can redistribute it and/or |
---|
9 | # modify it under the terms of the GNU General Public License as |
---|
10 | # published by the Free Software Foundation; either version 2 of the |
---|
11 | # License, or (at your option) any later version. |
---|
12 | # |
---|
13 | # This script is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | # General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU General Public License |
---|
19 | # along with this library; if not, write to the Free Software |
---|
20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | # |
---|
22 | # Authors: Kenneth Christiansen <kenneth@gnu.org> |
---|
23 | # |
---|
24 | |
---|
25 | my $LANG = $ARGV[0]; |
---|
26 | my $VERBOSE="1"; |
---|
27 | |
---|
28 | if (! $LANG) { |
---|
29 | print "You must specify the language\n"; |
---|
30 | } |
---|
31 | |
---|
32 | open IN, "$LANG.po"; |
---|
33 | |
---|
34 | while (<IN>) { |
---|
35 | ## example: "Content-Type: text/plain; charset=ISO-8859-1\n" |
---|
36 | if (/Content-Type\:.*charset=(.*)\\n/) { |
---|
37 | $encoding_code_orig = $1; |
---|
38 | last; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | close IN; |
---|
43 | |
---|
44 | print "Converting from $encoding_code_orig\n" if $VERBOSE; |
---|
45 | |
---|
46 | my $extern_conv="iconv --from=$encoding_code_orig " |
---|
47 | ."--to=UTF-8 $LANG.po > $LANG.po-1"; |
---|
48 | |
---|
49 | system($extern_conv); |
---|
50 | |
---|
51 | my $source_orig; |
---|
52 | { |
---|
53 | local (*IN); |
---|
54 | local $/; #slurp mode |
---|
55 | open (IN, "<$LANG.po-1") || die "can't open $LANG.po-1: $!"; |
---|
56 | $source_orig = <IN>; |
---|
57 | } |
---|
58 | |
---|
59 | $source_orig =~ s/Content-Type\:(.*)$encoding_code_orig/Content-Type\:$1UTF-8/; |
---|
60 | |
---|
61 | close IN; |
---|
62 | |
---|
63 | open OUT, ">$LANG.po-1"; |
---|
64 | print OUT $source_orig; |
---|
65 | close OUT; |
---|