55
66This program converts a textual Uniforum-style message catalog (.po file) into
77a binary GNU catalog (.mo file). This is essentially the same function as the
8- GNU msgfmt program, however, it is a simpler implementation. Currently it
9- does not handle plural forms but it does handle message contexts.
8+ GNU msgfmt program, however, it is a simpler implementation.
109
1110Usage: msgfmt.py [OPTIONS] filename.po
1211
2524 Display version information and exit.
2625"""
2726
28- import os
29- import sys
27+ import array
3028import ast
3129import getopt
30+ import os
3231import struct
33- import array
32+ import sys
3433from email .parser import HeaderParser
3534
3635__version__ = "1.2"
3736
37+
3838MESSAGES = {}
3939
4040
@@ -112,11 +112,12 @@ def make(filename, outfile):
112112 try :
113113 with open (infile , 'rb' ) as f :
114114 lines = f .readlines ()
115- except IOError as msg :
115+ except OSError as msg :
116116 print (msg , file = sys .stderr )
117117 sys .exit (1 )
118118
119119 section = msgctxt = None
120+ msgid = msgstr = b''
120121 fuzzy = 0
121122
122123 # Start off assuming Latin-1, so everything decodes without failure,
@@ -168,7 +169,7 @@ def make(filename, outfile):
168169 # This is a message with plural forms
169170 elif l .startswith ('msgid_plural' ):
170171 if section != ID :
171- print ('msgid_plural not preceded by msgid on %s:%d' % ( infile , lno ) ,
172+ print (f 'msgid_plural not preceded by msgid on { infile } : { lno } ' ,
172173 file = sys .stderr )
173174 sys .exit (1 )
174175 l = l [12 :]
@@ -179,15 +180,15 @@ def make(filename, outfile):
179180 section = STR
180181 if l .startswith ('msgstr[' ):
181182 if not is_plural :
182- print ('plural without msgid_plural on %s:%d' % ( infile , lno ) ,
183+ print (f 'plural without msgid_plural on { infile } : { lno } ' ,
183184 file = sys .stderr )
184185 sys .exit (1 )
185186 l = l .split (']' , 1 )[1 ]
186187 if msgstr :
187188 msgstr += b'\0 ' # Separator of the various plural forms
188189 else :
189190 if is_plural :
190- print ('indexed msgstr required for plural on %s:%d' % ( infile , lno ) ,
191+ print (f 'indexed msgstr required for plural on { infile } : { lno } ' ,
191192 file = sys .stderr )
192193 sys .exit (1 )
193194 l = l [6 :]
@@ -203,8 +204,7 @@ def make(filename, outfile):
203204 elif section == STR :
204205 msgstr += l .encode (encoding )
205206 else :
206- print ('Syntax error on %s:%d' % (infile , lno ), \
207- 'before:' , file = sys .stderr )
207+ print (f'Syntax error on { infile } :{ lno } before:' , file = sys .stderr )
208208 print (l , file = sys .stderr )
209209 sys .exit (1 )
210210 # Add last entry
@@ -217,7 +217,7 @@ def make(filename, outfile):
217217 try :
218218 with open (outfile ,"wb" ) as f :
219219 f .write (output )
220- except IOError as msg :
220+ except OSError as msg :
221221 print (msg , file = sys .stderr )
222222
223223
0 commit comments