@@ -30,11 +30,11 @@ def read_po(fp):
30
30
rvalue += line
31
31
elif line .startswith ('msgid ' ):
32
32
st = 1
33
- key = unquote (line [5 :])
33
+ key = unquote (line [6 :])
34
34
rkey = line
35
35
elif line .startswith ('msgstr ' ):
36
36
st = 2
37
- value = unquote (line [6 :])
37
+ value = unquote (line [7 :])
38
38
rvalue = line
39
39
else :
40
40
raise RuntimeError
@@ -45,34 +45,29 @@ def read_po(fp):
45
45
def main ():
46
46
import sys
47
47
48
- # Read the current text catalog.
48
+ # Read the new text catalog template .
49
49
d = {}
50
- firstcomment = ''
51
- it = read_po (file (sys .argv [1 ]))
52
- try :
53
- (comment , key , value , rkey , rvalue ) = it .next ()
54
- d [key ] = rvalue
55
- firstcomment = comment # Preserve the first comment block
56
- except StopIteration :
57
- pass
58
- for (comment , key , value , rkey , rvalue ) in it :
59
- d [key ] = rvalue
50
+ for (comment , key , value , rkey , rvalue ) in read_po (sys .stdin ):
51
+ d [key ] = (comment , rkey , rvalue )
52
+
53
+ # Override existing entries with current text catalog.
54
+ for (comment , key , value , rkey , rvalue ) in read_po (file (sys .argv [1 ])):
55
+ if d .has_key (key ):
56
+ d [key ] = (comment , rkey , rvalue )
60
57
61
- # Read the new text catalog template and output.
62
- # The translated values come from the current text catalog read above.
63
58
out = file (sys .argv [1 ], 'w' )
64
- out .write (firstcomment )
65
- it = read_po (sys .stdin )
66
- try :
67
- (comment , key , value , rkey , rvalue ) = it .next ()
59
+ if d .has_key ('' ):
60
+ (comment , rkey , rvalue ) = d ['' ]
61
+ out .write (comment )
68
62
out .write (rkey )
69
- out .write (d .get (key , rvalue ))
70
- except StopIteration :
71
- pass
72
- for (comment , key , value , rkey , rvalue ) in it :
63
+ out .write (rvalue )
64
+ del d ['' ]
65
+
66
+ for key in sorted (d .keys ()):
67
+ (comment , rkey , rvalue ) = d [key ]
73
68
out .write (comment )
74
69
out .write (rkey )
75
- out .write (d . get ( key , rvalue ) )
70
+ out .write (rvalue )
76
71
77
72
if __name__ == '__main__' :
78
73
main ()
0 commit comments