OSDN Git Service

import jp-0.9.3
[handbrake-jp/handbrake-jp.git] / macosx / LocalizationTools / MakeTraslateTable.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 
3 # MakeTranslateTable.py
4 #
5 #
6
7 import os, sys, re, codecs
8
9 #fo_in = codecs.lookup("utf_16")[-1](sys.stdin)
10 fo_in = sys.stdin
11 string_table = []
12
13 re_comment = re.compile( r"^/\* (.*) \*/" )
14 re_string = re.compile( r"\"(.*)([^\\])\" = \"(.*)([^\\])\";" )
15 re_blank = re.compile( r"^\s*$" )
16
17 comment = ""
18 key = ""
19 value = ""
20
21 for line in fo_in:
22     line = line.rstrip()
23
24     if re_blank.search( line ):
25       if (comment) and (key):
26 #          print "/* %s */" % (comment)
27 #          print "\"%s\" = \"%s\";\n" % (key, value)
28           if comment == "No comment provided by engineer.":
29               comment = ""
30           if key != value:
31               print "%s\t%s\t%s" % (key, value, comment)
32           comment = ""
33           key = ""
34           value = ""
35       elif (comment):
36 #          print "/* %s */" % (comment)
37           comment = ""
38       continue
39
40     elif re_comment.search( line ):
41         comment = re_comment.search( line ).group(1)
42
43     elif re_string.search( line ):
44         mt = re_string.search( line )
45         key = mt.group(1) + mt.group(2)
46         value = mt.group(3) + mt.group(4)
47
48 #    print line
49 #    print ">", comment, key, value