1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """a set of autocorrect functions that make resolving common problems more automatic..."""
23
24 from translate.filters import decoration
25
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