File: replacetrans.pl

package info (click to toggle)
josm 0.0.svn19369%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 243,336 kB
  • sloc: java: 490,598; xml: 201,669; perl: 10,314; jsp: 265; sh: 199; makefile: 120; javascript: 74; python: 60
file content (45 lines) | stat: -rwxr-xr-x 981 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl -w

use utf8;
use strict;
use open qw/:std :encoding(utf8)/;
use Encode;

# call with pairs of strings, first the wrong string, second the replacement
# strings must be escaped like in the po-file

my %rep;
while(@ARGV)
{
  my $from = Encode::decode("utf-8", shift @ARGV);
  my $to = Encode::decode("utf-8", shift @ARGV);
  $rep{$from} = $to;
  print "'$from' -> '$to'\n";
}

for my $po (reverse sort glob("po/*.po"))
{
  local $/;
  $/ = "\n\n";
  open my $in,'<:encoding(utf-8)',$po or die;
  my $outpo = $po;
  $outpo =~ s/.*\///;
  open my $out,'>',$outpo or die;
  my $changed = 0;

  for my $line (<$in>)
  {
    $line =~ s/"\n"//g;
    print $out $line if $line =~ /msgid ""\nmsgstr/;
    for my $f (keys %rep)
    {
      if($line =~ s/msgid "\Q$f\E"\nmsgstr/msgid "$rep{$f}"\nmsgstr/ && $line !~ /msgstr ""/ && $line !~ /msgstr "$f"/)
      {
        print $out $line;
        ++$changed;
      }
    }
  }
  close($out);
  unlink($outpo) if !$changed;
}