File: po4a-new.py

package info (click to toggle)
debian-reference 2.76
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 27,868 kB
  • sloc: xml: 35,664; python: 3,871; makefile: 378; sh: 328; sed: 80
file content (51 lines) | stat: -rwxr-xr-x 1,206 bytes parent folder | download | duplicates (5)
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
46
47
48
49
50
51
#!/usr/bin/env python
# vim: set sts=4 expandtab:
"""
po4a-new

Copyright (C) 2009 Osamu Aoki, GPL

Design: fill old msgid with new one in po file

$ po4a-new <orig.po >this.po
$ wdiff -n1 orig.po this.po >new.po

Prerequisite: msgmerge --previous --no-wrap

"""

import sys, os, re

VERSION = '1.0.1'

msgold = ''
if __name__ == '__main__':

    for line in sys.stdin.readlines():
        # drop EOL = NL
        line=line[0:-1]
        if re.match("^[ \t]*$", line):
            # reformat as clean blank line
            print line
        elif re.match("^#. msgid ", line):
            msgold = re.sub(r"^#. msgid +\"(.*)\" *$",r'\1',line)
        elif re.match("^msgid ", line):
            msgnew = re.sub(r"^msgid +\"(.*)\" *$",r'\1',line)
            if msgold == '':
                print line
            else:
                print "#| msgid \"" + msgnew + "\""
                print line
            # reset
            msgold = ''
        elif re.match("^msgstr ", line):
            msgstr = re.sub(r"^msgstr +\"(.*)\" *$",r'\1',line)
            print line
        elif re.match("^#", line):
            # comment line
            print line
        else:
            print line
        #