4040except ImportError :
4141 pass
4242
43-
44- def count_lines (string ):
45- """
46- Count the number of lines in a string or translation.
47- """
48- count = len (string .split ('\n ' ))
49- if count > 1 and string .endswith ('\n ' ):
50- count -= 1
51- return count
43+ from . utils import count_lines , replace_formatters
5244
5345
5446# pylint: disable=too-few-public-methods
@@ -119,7 +111,7 @@ class PoMessage(object):
119111 """
120112
121113 # pylint: disable=too-many-arguments
122- def __init__ (self , filename , line , msg , charset , fuzzy ):
114+ def __init__ (self , filename , line , msg , charset , fuzzy , fmt ):
123115 """Build a PO message."""
124116 self .filename = filename
125117 self .line = line
@@ -144,6 +136,7 @@ def __init__(self, filename, line, msg, charset, fuzzy):
144136 else :
145137 self .messages .append ((msg .get ('msgid' , '' ), msg .get ('msgstr' , '' )))
146138 self .fuzzy = fuzzy
139+ self .fmt = fmt
147140
148141 def check_lines (self ):
149142 """
@@ -271,7 +264,10 @@ def check_spelling(self, spelling, checkers):
271264 for mid , mstr in self .messages :
272265 if not mid or not mstr :
273266 continue
274- checkers [0 ].set_text (mstr if spelling == 'str' else mid )
267+ text = mstr if spelling == 'str' else mid
268+ if self .fmt :
269+ text = replace_formatters (text , ' ' , self .fmt )
270+ checkers [0 ].set_text (text )
275271 misspelled = []
276272 for err in checkers [0 ]:
277273 misspelled_word = True
@@ -302,7 +298,7 @@ def __init__(self, filename):
302298 }
303299 self .msgs = []
304300
305- def _add_message (self , numline_msgid , msgfuzzy , msg ):
301+ def _add_message (self , numline_msgid , fuzzy , fmt , msg ):
306302 """
307303 Add a message from PO file in list of messages.
308304 """
@@ -319,15 +315,16 @@ def _add_message(self, numline_msgid, msgfuzzy, msg):
319315 if match :
320316 self .props ['charset' ] = match .group (1 )
321317 self .msgs .append (PoMessage (self .filename , numline_msgid , msg ,
322- self .props ['charset' ], msgfuzzy ))
318+ self .props ['charset' ], fuzzy , fmt ))
323319
324320 def read (self ):
325321 """
326322 Read messages in PO file.
327323 """
328324 self .msgs = []
329- (numline , numline_msgid ) = (0 , 0 )
330- (fuzzy , msgfuzzy ) = (False , False )
325+ numline , numline_msgid = (0 , 0 )
326+ fuzzy , msgfuzzy = (False , False )
327+ fmt , msgfmt = (None , None )
331328 msg = {}
332329 msgcurrent = ''
333330 with open (self .filename , 'r' ) as po_file :
@@ -338,6 +335,9 @@ def read(self):
338335 continue
339336 if line .startswith ('#,' ):
340337 fuzzy = 'fuzzy' in line
338+ match = re .search (r'([a-z-]+)-format' , line , re .IGNORECASE )
339+ fmt = match .group (1 ) if match else None
340+ if line .startswith ('#' ):
341341 continue
342342 if line .startswith ('msg' ):
343343 match = re .match (
@@ -351,16 +351,20 @@ def read(self):
351351 if oldmsgcurrent .startswith ('msgstr' ):
352352 self ._add_message (numline_msgid ,
353353 msgfuzzy ,
354+ msgfmt ,
354355 msg )
355356 msgfuzzy = fuzzy
356357 fuzzy = False
358+ msgfmt = fmt
359+ fmt = None
357360 msg = {}
358361 numline_msgid = numline
359362 if msgcurrent and line .startswith ('"' ):
360363 msg [msgcurrent ] = msg .get (msgcurrent , '' ) + line [1 :- 1 ]
361364 if msgcurrent .startswith ('msgstr' ):
362365 self ._add_message (numline_msgid ,
363366 msgfuzzy ,
367+ msgfmt ,
364368 msg )
365369
366370 def compile (self ):
0 commit comments