source: git/lib/launchpad-merge-po @ 4bbe80d

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 4bbe80d was 4bbe80d, checked in by Olly Betts <olly@…>, 7 years ago

Merge #~ translations better

If the current translation has #~ and the launchpad one doesn't,
always prefix "#~ " on the launchpad one (before we only did if
that exactly matched the current one).

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4open O, '<', $ARGV[0] or die $!;
5if ($ARGV[1] eq '-') {
6    *N = *STDIN;
7} else {
8    open N, '<', $ARGV[1] or die $!;
9}
10
11my $fuzzy = 0;
12my $diff = 0;
13my ($o, $n);
14while (1) {
15    $o //= <O>;
16    $n //= <N>;
17    defined $o and $o =~ s/[ \t]+$//;
18    defined $n and $n =~ s/[ \t]+$//;
19    if (!defined $n) {
20        last unless defined $o;
21        print '-' if $diff;
22        print $o;
23        $o = undef;
24        next;
25    }
26    if (!defined $o) {
27        print '+' if $diff;
28        print $n;
29        $n = undef;
30        next;
31    }
32
33    if ($o eq "\n" || $n eq "\n") {
34        $fuzzy = 0;
35    }
36
37    if ($o eq $n) {
38        print ' ' if $diff;
39        print $n;
40        $n = $o = undef;
41        next;
42    }
43
44    if (substr($o, 0, 3) eq '#~ ' && substr($n, 0, 3) ne '#~ ') {
45        print ' ' if $diff;
46        print "#~ $n";
47        $n = $o = undef;
48        next;
49    }
50
51    if ($o =~ /^("PO(?:-Revision|T-Creation)-Date: \d+-\d+-\d+ \d+:\d+):\d\d (.*\n)$/ &&
52        $n eq "$1:00 $2") {
53        print ' ' if $diff;
54        print $o;
55        $n = $o = undef;
56        next;
57    }
58
59    if ($o =~ /^"PO-Revision-Date:/ && $n =~ /^"PO-Revision-Date:/) {
60        print ' ' if $diff;
61        print $o;
62        $n = $o = undef;
63        next;
64    }
65
66    if ($o eq "\n") {
67        print '+' if $diff;
68        print $n;
69        $n = undef;
70        next;
71    }
72
73    if ($n eq "\n") {
74        print '-$o' if $diff;
75        $o = undef;
76        next;
77    }
78
79    if ($o eq "#, fuzzy\n") {
80        print ' ' if $diff;
81        print $o;
82        $o = undef;
83        $fuzzy = 1;
84        next;
85    }
86
87    my $tmp = $o;
88    if ($tmp =~ s/, fuzzy// && $n eq $tmp) {
89        print ' ' if $diff;
90        print $o;
91        $n = $o = undef;
92        $fuzzy = 1;
93        next;
94    }
95
96    if ($fuzzy && $o =~ /^(?:#~ )?msgstr / && $n eq "msgstr \"\"\n") {
97        print ' ' if $diff;
98        print $o;
99        $n = $o = undef;
100        $fuzzy = 0;
101        next;
102    }
103
104    print "-$o" if $diff;
105    print '+' if $diff;
106    print $n;
107    $n = $o = undef;
108}
Note: See TracBrowser for help on using the repository browser.