pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\translation.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022"""Translation Test
0023
0024**What is checked**
0025This checks for controls which appear not to be translated.
0026
0027**How is it checked**
0028It compares the text of the localised and reference controls.
0029
0030If there are more than string in the control then each item is searched for in
0031the US list of titles (so checking is not order dependent).
0032The indices for the untranslated strings are returned in a comma separated
0033string.
0034Also the untranslated strings themselves are returned (all as one string).
0035These strings are not escaped and are delimited as
0036"string1","string2",..."stringN".
0037
0038**When is a bug reported**
0039
0040 If the text of the localised control is identical to the reference control
0041 (in case, spacing i.e. a binary compare) then it will be flagged as
0042 untranslated. Otherwise the control is treated as translated.
0043
0044Note: This is the method to return the least number of bugs. If there are
0045differences in any part of the string (e.g. a path or variable name) but the
0046rest of the string is untranslated then a bug will not be highlighted
0047
0048**Bug Extra Information**
0049The bug contains the following extra information
0050Name Description
0051Strings The list of the untranslated strings as explained above
0052StringIndices The list of indices (0 based) that are untranslated.
0053This will usually be 0 but if there are many strings in the control
0054untranslated it will report ALL the strings e.g. 0,2,5,19,23
0055
0056**Is Reference dialog needed**
0057The reference dialog is always necessary.
0058
0059**False positive bug reports**
0060False positive bugs will be reported in the following cases.
0061- The title of the control stays the same as the US because the
0062translation is the same as the English text(e.g. Name: in German)
0063- The title of the control is not displayed (and not translated).
0064This can sometimes happen if the programmer displays something else on the
0065control after the dialog is created.
0066
0067**Test Identifier**
0068The identifier for this test/bug is "Translation" """
0069
0070__revision__ = "$Revision: 221 $"
0071
0072testname = "Translation"
0073
0074import re
0075
0076
0077def TranslationTest(windows):
0078 "Returns just one bug for each control"
0079
0080 bugs = []
0081 for win in windows:
0082 if not win.ref:
0083 continue
0084
0085
0086 untranTitles, untranIndices = _GetUntranslations(win)
0087
0088 if untranTitles:
0089 indicesAsString = ",".join([unicode(idx) for idx in untranIndices])
0090
0091 bugs.append((
0092 [win,],
0093 {
0094 "StringIndices": indicesAsString,
0095 "Strings": ('"%s"' % '","'.join(untranTitles))
0096 },
0097 testname,
0098 0)
0099 )
0100
0101
0102 return bugs
0103
0104def _GetUntranslations(win):
0105 "Find the text items that are not translated"
0106
0107
0108 nonTransChars = re.compile(
0109 """(\&(?!\&)| # ampersand not followed by an ampersand
0110 \.\.\.$| # elipsis ...
0111 ^\s*| # leading whitespace
0112 \s*$| # trailing whitespace
0113 \s*:\s*$ # trailing colon (with/without whitespace)
0114 )* # repeated as often as necessary
0115 """, re.X)
0116
0117
0118
0119 cleanedLocTitles = []
0120 for title in win.Texts():
0121 cleanedLocTitles.append(nonTransChars.sub("", title))
0122
0123
0124 cleanedRefTitles = []
0125 for title in win.ref.Texts():
0126 cleanedRefTitles.append(nonTransChars.sub("", title))
0127
0128 untranslatedTitles = []
0129 untranslatedIndices = []
0130
0131
0132 for index, title in enumerate(cleanedLocTitles):
0133
0134
0135 if not title:
0136 continue
0137
0138
0139 if title in cleanedRefTitles:
0140
0141 untranslatedTitles.append(title)
0142 untranslatedIndices.append(index)
0143
0144
0145 return untranslatedTitles, untranslatedIndices
0146
0147
0148TranslationTest.TestsMenus = True