@@ -253,7 +253,7 @@ def check_whitespace_eol(self):
253253 break
254254 return errors
255255
256- def check_spelling (self , checkers ):
256+ def check_spelling (self , spelling , checkers ):
257257 """
258258 Check spelling.
259259 Return a list with errors detected.
@@ -264,7 +264,7 @@ def check_spelling(self, checkers):
264264 for mid , mstr in self .messages :
265265 if not mid or not mstr :
266266 continue
267- checkers [0 ].set_text (mstr )
267+ checkers [0 ].set_text (mstr if spelling == 'str' else mid )
268268 misspelled = []
269269 for err in checkers [0 ]:
270270 misspelled_word = True
@@ -275,8 +275,8 @@ def check_spelling(self, checkers):
275275 if misspelled_word :
276276 misspelled .append (err .word )
277277 for word in misspelled :
278- errors .append (PoReport (word , 'spelling' , self . filename ,
279- self .line , mid , mstr ))
278+ errors .append (PoReport (word , 'spelling-' + spelling ,
279+ self .filename , self . line , mid , mstr ))
280280 return errors
281281
282282
@@ -383,11 +383,11 @@ def __init__(self):
383383 'punct' : True ,
384384 'whitespace' : True ,
385385 'whitespace_eol' : True ,
386- 'spelling' : False ,
387386 'extract' : False ,
388387 }
389388
390389 # spelling options
390+ self .spelling = None
391391 self .dicts = None
392392 self .extra_checkers = []
393393 self .pwl = None
@@ -403,8 +403,9 @@ def set_check(self, check, state):
403403 if check in self .checks :
404404 self .checks [check ] = bool (state )
405405
406- def set_spelling_options (self , dicts , pwl ):
406+ def set_spelling_options (self , spelling , dicts , pwl ):
407407 """Set spelling options."""
408+ self .spelling = spelling
408409 self .dicts = dicts
409410 self .pwl = pwl
410411
@@ -429,17 +430,19 @@ def set_spelling_options(self, dicts, pwl):
429430 def _get_language_checker (self , po_file , reports ):
430431 """Get checker for PO file language."""
431432 checker = []
432- if self .checks [ ' spelling' ] :
433+ if self .spelling :
433434 if not ENCHANT_FOUND :
434435 raise ImportError ('Enchant module not found (please install '
435436 '"pyenchant")' )
437+ lang = po_file .props ['language' ] \
438+ if self .spelling == 'str' else 'en'
436439 try :
437- _dict = DictWithPWL (po_file . props [ 'language' ] , self .pwl )
440+ _dict = DictWithPWL (lang , self .pwl )
438441 checker .append (SpellChecker (_dict ))
439442 except DictNotFoundError :
440443 reports .append (PoReport (
441444 'enchant dictionary not found for language "{0}"'
442- '' .format (po_file . props [ 'language' ] ),
445+ '' .format (lang ),
443446 'dict' , po_file .filename ,
444447 po_file .props ['language_numline' ]))
445448 checker = []
@@ -479,9 +482,9 @@ def check_pofile(self, po_file):
479482 reports += msg .check_whitespace ()
480483 if self .checks ['whitespace_eol' ]:
481484 reports += msg .check_whitespace_eol ()
482- if self .checks [ ' spelling' ] :
485+ if self .spelling :
483486 reports += msg .check_spelling (
484- checker + self .extra_checkers )
487+ self . spelling , checker + self .extra_checkers )
485488
486489 return reports
487490
0 commit comments