3
"""This proggy parses given files for occurences of translatable strings
4
if some are found they are output in a xgettext style file"""
9
head = """# SOME DESCRIPTIVE TITLE.
10
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
11
# This file is distributed under the same license as the PACKAGE package.
12
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
16
"Project-Id-Version: PACKAGE VERSION\\n"
17
"Report-Msgid-Bugs-To: \\n"
18
"POT-Creation-Date: 2005-11-05 22:37+0100\\n"
19
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
20
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
21
"Language-Team: LANGUAGE <LL@li.org>\\n"
22
"MIME-Version: 1.0\\n"
23
"Content-Type: text/plain; charset=UTF-8\\n"
24
"Content-Transfer-Encoding: 8bit\\n"
29
def __init__( self, file, line ):
38
def is_multiline( str ):
39
l = firstl( str, '"\'');
42
r = firstr( str, '"\'')
46
def firstl( str, what ):
53
def firstr( str, what ):
55
index = str.rfind( c )
60
def append_string( known_strings, array, string ):
61
if known_strings.has_key( string.str ):
62
i = known_strings[string.str]
63
array[i].occurences += string.occurences
65
array.append( string )
66
known_strings[string.str] = len( array ) - 1
68
def parse_conf( files ):
69
translatable_strings = []
74
lines = open( file, 'r' ).readlines();
75
for i in range(0,len(lines)):
76
line = lines[i].rstrip('\n')
80
rindex = firstr(line, '"\'')
85
curstr.str += line[:rindex]
86
append_string( known_strings, translatable_strings, curstr )
90
index = line.find( "=_" )
92
curstr = trans_string()
93
curstr.occurences.append( occurences( file, linenr ))
94
restline = line[index+2:]
95
multiline = is_multiline( restline );
96
if multiline: # means exactly one "
97
index = firstl( restline, '"\'')
98
restline = restline[index+1:]
99
curstr.str += restline
102
# If there are ' or " its easy
103
l = firstl( restline, '"\'')
104
r = firstr( restline, '"\'')
105
if( l != -1 and r != -1 ):
106
restline = restline[l+1:]
107
r = firstr( restline, '"\'')
108
restline = restline[:r]
111
rindex = max( restline.rfind('#'), restline.rfind('//'))
113
restline = restline[:rindex]
115
restline = restline.strip()
116
curstr.str = restline
117
append_string( known_strings, translatable_strings, curstr )
119
translatable_strings.sort( lambda str1,str2: cmp(str1.str,str2.str) )
122
for i in translatable_strings:
123
for occ in i.occurences:
124
retval += "#: %s:%i\n" % ( occ.file, occ.line )
125
retval += 'msgid "%s"\n' % i.str
126
retval += 'msgstr ""\n\n'
130
#: ../src/ui/ui_fs_menus/fullscreen_menu_main.cc:41
131
#msgid "Single Player"
134
if __name__ == "__main__":
136
print "Usage %s <conf file> [ <conf file> ... ]" % sys.argv[0]
138
print parse_conf( sys.argv[1:] )