Package translate :: Package filters :: Module autocorrect
[hide private]
[frames] | no frames]

Source Code for Module translate.filters.autocorrect

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  #  
 4  # Copyright 2005, 2006 Zuza Software Foundation 
 5  #  
 6  # This file is part of translate. 
 7  # 
 8  # translate is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  #  
13  # translate is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with translate; if not, write to the Free Software 
20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
21   
22  """a set of autocorrect functions that make resolving common problems more automatic...""" 
23   
24  from translate.filters import decoration 
25   
26 -def correct(msgid, msgstr):
27 """runs a set of easy automatic corrections""" 28 assert isinstance(msgid, unicode) 29 assert isinstance(msgstr, unicode) 30 if msgstr == "": 31 return msgstr 32 if "..." in msgid and u"…" in msgstr: 33 return msgstr.replace(u"…", "...") 34 if decoration.spacestart(msgid) != decoration.spacestart(msgstr) or decoration.spaceend(msgid) != decoration.spaceend(msgstr): 35 return decoration.spacestart(msgid) + msgstr.strip() + decoration.spaceend(msgid) 36 punctuation = (".", ":", ". ", ": ", "?") 37 puncendid = decoration.puncend(msgid, punctuation) 38 puncendstr = decoration.puncend(msgstr, punctuation) 39 if puncendid != puncendstr: 40 if not puncendstr: 41 return msgstr + puncendid 42 if msgid[:1].isalpha() and msgstr[:1].isalpha(): 43 if msgid[:1].isupper() and msgstr[:1].islower(): 44 return msgstr[:1].upper() + msgstr[1:] 45 elif msgid[:1].islower() and msgstr[:1].isupper(): 46 return msgstr[:1].lower() + msgstr[1:] 47 return None
48