Debian Codegraph @

i18n/replacetrans.pl

raw
1 #! /usr/bin/perl -w
2
3 use utf8;
4 use strict;
5 use open qw/:std :encoding(utf8)/;
6 use Encode;
7
8 # call with pairs of strings, first the wrong string, second the replacement
9 # strings must be escaped like in the po-file
10
11 my %rep;
12 while(@ARGV)
13 {
14 my $from = Encode::decode("utf-8", shift @ARGV);
15 my $to = Encode::decode("utf-8", shift @ARGV);
16 $rep{$from} = $to;
17 print "'$from' -> '$to'\n";
18 }
19
20 for my $po (reverse sort glob("po/*.po"))
21 {
22 local $/;
23 $/ = "\n\n";
24 open my $in,'<:encoding(utf-8)',$po or die;
25 my $outpo = $po;
26 $outpo =~ s/.*\///;
27 open my $out,'>',$outpo or die;
28 my $changed = 0;
29
30 for my $line (<$in>)
31 {
32 $line =~ s/"\n"//g;
33 print $out $line if $line =~ /msgid ""\nmsgstr/;
34 for my $f (keys %rep)
35 {
36 if($line =~ s/msgid "\Q$f\E"\nmsgstr/msgid "$rep{$f}"\nmsgstr/ && $line !~ /msgstr ""/ && $line !~ /msgstr "$f"/)
37 {
38 print $out $line;
39 ++$changed;
40 }
41 }
42 }
43 close($out);
44 unlink($outpo) if !$changed;
45 }