Skip to content

Commit

Permalink
Untabified global plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick PLASSIARD committed Dec 10, 2018
1 parent 66818b2 commit 96b96c8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 84 deletions.
167 changes: 84 additions & 83 deletions addon/globalPlugins/translate/__init__.py
Expand Up @@ -49,9 +49,10 @@ def translate(text):
if translated is not None:
return translated
try:
translated = mtranslate.translate(text, _gpObject.language)
prepared = text.encode('utf8', ':/')
translated = mtranslate.translate(prepared, _gpObject.language)
except Exception as e:
logHandler.log.exception("Error translating text: %s" % e)
_translationCache[text] = text
return text
_translationCache[text] = translated
return translated
Expand Down Expand Up @@ -96,120 +97,120 @@ def getSpeechTextForProperties(reason=controlTypes.REASON_QUERY,**propertyValues
textList=[]
name=propertyValues.get('name')
if name:
textList.append(translate(name.replace("&", "")))
textList.append(translate(name.replace("&", "")))
if 'role' in propertyValues:
role=propertyValues['role']
speakRole=True
role=propertyValues['role']
speakRole=True
elif '_role' in propertyValues:
speakRole=False
role=propertyValues['_role']
speakRole=False
role=propertyValues['_role']
else:
speakRole=False
role=controlTypes.ROLE_UNKNOWN
speakRole=False
role=controlTypes.ROLE_UNKNOWN
value = propertyValues.get('value') if role not in controlTypes.silentValuesForRoles else None
cellCoordsText=propertyValues.get('cellCoordsText')
rowNumber=propertyValues.get('rowNumber')
columnNumber=propertyValues.get('columnNumber')
includeTableCellCoords=propertyValues.get('includeTableCellCoords',True)
if role==controlTypes.ROLE_CHARTELEMENT:
speakRole=False
roleText=propertyValues.get('roleText')
speakRole=False
roleText=propertyValues.get('roleText')
if speakRole and (roleText or reason not in (controlTypes.REASON_SAYALL,controlTypes.REASON_CARET,controlTypes.REASON_FOCUS) or not (name or value or cellCoordsText or rowNumber or columnNumber) or role not in controlTypes.silentRolesOnFocus) and (role!=controlTypes.ROLE_MATH or reason not in (controlTypes.REASON_CARET,controlTypes.REASON_SAYALL)):
textList.append(translate(roleText) if roleText else controlTypes.roleLabels[role])
textList.append(translate(roleText) if roleText else controlTypes.roleLabels[role])
if value:
textList.append(translate(value))
textList.append(translate(value))
states=propertyValues.get('states',set())
realStates=propertyValues.get('_states',states)
negativeStates=propertyValues.get('negativeStates',set())
if states or negativeStates:
textList.extend(controlTypes.processAndLabelStates(role, realStates, reason, states, negativeStates))
textList.extend(controlTypes.processAndLabelStates(role, realStates, reason, states, negativeStates))
if 'description' in propertyValues:
textList.append(translate(propertyValues['description']))
textList.append(translate(propertyValues['description']))
if 'keyboardShortcut' in propertyValues:
textList.append(propertyValues['keyboardShortcut'])
textList.append(propertyValues['keyboardShortcut'])
if includeTableCellCoords and cellCoordsText:
textList.append(translate(cellCoordsText))
textList.append(cellCoordsText)
if cellCoordsText or rowNumber or columnNumber:
tableID = propertyValues.get("_tableID")
# Always treat the table as different if there is no tableID.
sameTable = (tableID and tableID == oldTableID)
# Don't update the oldTableID if no tableID was given.
if tableID and not sameTable:
oldTableID = tableID
rowSpan = propertyValues.get("rowSpan")
columnSpan = propertyValues.get("columnSpan")
if rowNumber and (not sameTable or rowNumber != oldRowNumber or rowSpan != oldRowSpan):
rowHeaderText = propertyValues.get("rowHeaderText")
if rowHeaderText:
textList.append(translate(rowHeaderText))
if includeTableCellCoords and not cellCoordsText:
# Translators: Speaks current row number (example output: row 3).
textList.append(_("row %s")%rowNumber)
if rowSpan>1 and columnSpan<=1:
# Translators: Speaks the row span added to the current row number (example output: through 5).
textList.append(_("through %s")%(rowNumber+rowSpan-1))
oldRowNumber = rowNumber
oldRowSpan = rowSpan
if columnNumber and (not sameTable or columnNumber != oldColumnNumber or columnSpan != oldColumnSpan):
columnHeaderText = propertyValues.get("columnHeaderText")
if columnHeaderText:
textList.append(translate(columnHeaderText))
if includeTableCellCoords and not cellCoordsText:
# Translators: Speaks current column number (example output: column 3).
textList.append(_("column %s")%columnNumber)
if columnSpan>1 and rowSpan<=1:
# Translators: Speaks the column span added to the current column number (example output: through 5).
textList.append(_("through %s")%(columnNumber+columnSpan-1))
oldColumnNumber = columnNumber
oldColumnSpan = columnSpan
if includeTableCellCoords and not cellCoordsText and rowSpan>1 and columnSpan>1:
# Translators: Speaks the row and column span added to the current row and column numbers
# (example output: through row 5 column 3).
textList.append(_("through row {row} column {column}").format(
row=rowNumber+rowSpan-1,
column=columnNumber+columnSpan-1
))
tableID = propertyValues.get("_tableID")
# Always treat the table as different if there is no tableID.
sameTable = (tableID and tableID == oldTableID)
# Don't update the oldTableID if no tableID was given.
if tableID and not sameTable:
oldTableID = tableID
rowSpan = propertyValues.get("rowSpan")
columnSpan = propertyValues.get("columnSpan")
if rowNumber and (not sameTable or rowNumber != oldRowNumber or rowSpan != oldRowSpan):
rowHeaderText = propertyValues.get("rowHeaderText")
if rowHeaderText:
textList.append(translate(rowHeaderText))
if includeTableCellCoords and not cellCoordsText:
# Translators: Speaks current row number (example output: row 3).
textList.append(_("row %s")%rowNumber)
if rowSpan>1 and columnSpan<=1:
# Translators: Speaks the row span added to the current row number (example output: through 5).
textList.append(_("through %s")%(rowNumber+rowSpan-1))
oldRowNumber = rowNumber
oldRowSpan = rowSpan
if columnNumber and (not sameTable or columnNumber != oldColumnNumber or columnSpan != oldColumnSpan):
columnHeaderText = propertyValues.get("columnHeaderText")
if columnHeaderText:
textList.append(translate(columnHeaderText))
if includeTableCellCoords and not cellCoordsText:
# Translators: Speaks current column number (example output: column 3).
textList.append(_("column %s")%columnNumber)
if columnSpan>1 and rowSpan<=1:
# Translators: Speaks the column span added to the current column number (example output: through 5).
textList.append(_("through %s")%(columnNumber+columnSpan-1))
oldColumnNumber = columnNumber
oldColumnSpan = columnSpan
if includeTableCellCoords and not cellCoordsText and rowSpan>1 and columnSpan>1:
# Translators: Speaks the row and column span added to the current row and column numbers
# (example output: through row 5 column 3).
textList.append(_("through row {row} column {column}").format(
row=rowNumber+rowSpan-1,
column=columnNumber+columnSpan-1
))
rowCount=propertyValues.get('rowCount',0)
columnCount=propertyValues.get('columnCount',0)
if rowCount and columnCount:
# Translators: Speaks number of columns and rows in a table (example output: with 3 rows and 2 columns).
textList.append(_("with {rowCount} rows and {columnCount} columns").format(rowCount=rowCount,columnCount=columnCount))
# Translators: Speaks number of columns and rows in a table (example output: with 3 rows and 2 columns).
textList.append(_("with {rowCount} rows and {columnCount} columns").format(rowCount=rowCount,columnCount=columnCount))
elif columnCount and not rowCount:
# Translators: Speaks number of columns (example output: with 4 columns).
textList.append(_("with %s columns")%columnCount)
# Translators: Speaks number of columns (example output: with 4 columns).
textList.append(_("with %s columns")%columnCount)
elif rowCount and not columnCount:
# Translators: Speaks number of rows (example output: with 2 rows).
textList.append(_("with %s rows")%rowCount)
# Translators: Speaks number of rows (example output: with 2 rows).
textList.append(_("with %s rows")%rowCount)
if rowCount or columnCount:
# The caller is entering a table, so ensure that it is treated as a new table, even if the previous table was the same.
oldTableID = None
# The caller is entering a table, so ensure that it is treated as a new table, even if the previous table was the same.
oldTableID = None
ariaCurrent = propertyValues.get('current', False)
if ariaCurrent:
try:
textList.append(controlTypes.isCurrentLabels[ariaCurrent])
except KeyError:
log.debugWarning("Aria-current value not handled: %s"%ariaCurrent)
textList.append(controlTypes.isCurrentLabels[True])
try:
textList.append(controlTypes.isCurrentLabels[ariaCurrent])
except KeyError:
log.debugWarning("Aria-current value not handled: %s"%ariaCurrent)
textList.append(controlTypes.isCurrentLabels[True])
placeholder = propertyValues.get('placeholder', None)
if placeholder:
textList.append(placeholder)
textList.append(placeholder)
indexInGroup=propertyValues.get('positionInfo_indexInGroup',0)
similarItemsInGroup=propertyValues.get('positionInfo_similarItemsInGroup',0)
if 0<indexInGroup<=similarItemsInGroup:
# Translators: Spoken to indicate the position of an item in a group of items (such as a list).
# {number} is replaced with the number of the item in the group.
# {total} is replaced with the total number of items in the group.
textList.append(_("{number} of {total}").format(number=indexInGroup, total=similarItemsInGroup))
# Translators: Spoken to indicate the position of an item in a group of items (such as a list).
# {number} is replaced with the number of the item in the group.
# {total} is replaced with the total number of items in the group.
textList.append(_("{number} of {total}").format(number=indexInGroup, total=similarItemsInGroup))
if 'positionInfo_level' in propertyValues:
level=propertyValues.get('positionInfo_level',None)
role=propertyValues.get('role',None)
if level is not None:
if role in (controlTypes.ROLE_TREEVIEWITEM,controlTypes.ROLE_LISTITEM) and level!=oldTreeLevel:
textList.insert(0,_("level %s")%level)
oldTreeLevel=level
else:
# Translators: Speaks the item level in treeviews (example output: level 2).
textList.append(_('level %s')%propertyValues['positionInfo_level'])
level=propertyValues.get('positionInfo_level',None)
role=propertyValues.get('role',None)
if level is not None:
if role in (controlTypes.ROLE_TREEVIEWITEM,controlTypes.ROLE_LISTITEM) and level!=oldTreeLevel:
textList.insert(0,_("level %s")%level)
oldTreeLevel=level
else:
# Translators: Speaks the item level in treeviews (example output: level 2).
textList.append(_('level %s')%propertyValues['positionInfo_level'])
speech.oldTreeLevel = oldTreeLevel
speech.oldTableID = oldTableID
speech.oldRowNumber = oldRowNumber
Expand Down
2 changes: 1 addition & 1 deletion addon/globalPlugins/translate/mtranslate/core.py
Expand Up @@ -69,7 +69,7 @@ def translate(to_translate, to_language="auto", from_language="auto"):
"""
base_link = "http://translate.google.com/m?hl=%s&sl=%s&q=%s"
if (sys.version_info[0] < 3):
to_translate = urllib.quote_plus(to_translate.encode('utf8', ':/'))
to_translate = urllib.quote_plus(to_translate)
link = base_link % (to_language, from_language, to_translate)
request = urllib2.Request(link, headers=agent)
raw_data = urllib2.urlopen(request).read()
Expand Down

0 comments on commit 96b96c8

Please sign in to comment.