File indexing completed on 2024-05-05 17:52:55
0001 # -*- coding: utf-8 -*- 0002 0003 """ 0004 @author: Javier Viñal <fjvinal@gmail.com> 0005 @license: GPLv3""" 0006 0007 import re 0008 0009 def setup_sieve (p): 0010 0011 p.set_desc("Replace normal space by non-breaking space where needed.") 0012 0013 0014 class Sieve (object): 0015 """Replace normal space by unbreakable space when needed""" 0016 0017 def __init__ (self, params): 0018 0019 self.nmatch = 0 0020 0021 self.percent=re.compile("( %)(?=$| |\.|,)") 0022 0023 def process (self, msg, cat): 0024 0025 oldcount=msg.modcount 0026 0027 for i in range(len(msg.msgstr)): 0028 msg.msgstr[i]=self.setUbsp(msg.msgstr[i]) 0029 0030 if oldcount<msg.modcount: 0031 self.nmatch+=1 0032 0033 def finalize (self): 0034 0035 if self.nmatch > 0: 0036 print("Total messages changed: %d" % (self.nmatch,)) 0037 0038 def setUbsp(self, text): 0039 """Set correctly unbreakable spaces""" 0040 text=text.replace(u"\xa0", u" ") 0041 text=text.replace(u" :", u"\xc2\xa0:") 0042 text=text.replace(u" :", u"\xa0:") 0043 text=text.replace(u" ;", u"\xa0;") 0044 text=text.replace(u" ?", u"\xa0?") 0045 text=text.replace(u" !", u"\xa0!") 0046 text=text.replace(u"« ", u"«\xa0") 0047 text=text.replace(u" »", u"\xa0»") 0048 text=text.replace(u" / ", u"\xa0/ ") 0049 text=self.percent.sub(u"\xa0%", text) 0050 0051 return text