Skip to content

Commit

Permalink
Fixes a clipboard copy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Plassiard committed Apr 30, 2020
1 parent eae129b commit 195eb2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@
Make NVDA translate any spoken text to the desired language.
## Download
- Stable: [translate-2019.09.3](http://www.mtyp.fr/nvda/translate-2019.09.3.nvda-addon).
- Stable (NVDA 2019.3+): [translate-2020.01](http://www.mtyp.fr/nvda/translate-2020.01.nvda-addon).
- Stable (NVDA 2019.3+): [translate-2020.01](http://www.mtyp.fr/nvda/translate-2020.05.nvda-addon).

## Installation

Expand Down
3 changes: 2 additions & 1 deletion addon/doc/en/readme.md
@@ -1,7 +1,8 @@
# nvda-translate
Make NVDA translate any spoken text to the desired language.
## Download
- Stable: [translate-2019.09.3](https://www.mtyp.fr/nvda/translate-2019.09.3.nvda-addon).
- Stable: [translate-2019.09.3](http://www.mtyp.fr/nvda/translate-2019.09.3.nvda-addon).
- Stable (NVDA 2019.3+): [translate-2020.01](http://www.mtyp.fr/nvda/translate-2020.05.nvda-addon).

## Installation

Expand Down
21 changes: 18 additions & 3 deletions addon/globalPlugins/translate/__init__.py
Expand Up @@ -45,6 +45,8 @@
_gpObject = None
_lastError = 0
_enableTranslation = False
_lastTranslatedText = None
_lastTranslatedTextTime = 0


def translate(text):
Expand Down Expand Up @@ -73,8 +75,7 @@ def translate(text):
_translationCache[appName][text] = text
return text
if translated is None or len(translated) == 0:
translated = text

translated = text
_translationCache[appName][text] = translated
return translated

Expand All @@ -85,7 +86,7 @@ def translate(text):

def speak(speechSequence: SpeechSequence,
priority: Optional[Spri] = None):
global _enableTranslation
global _enableTranslation, _lastTranslatedText

if _enableTranslation is False:
return _nvdaSpeak(speechSequence=speechSequence, priority=priority)
Expand All @@ -97,6 +98,7 @@ def speak(speechSequence: SpeechSequence,
else:
newSpeechSequence.append(val)
_nvdaSpeak(speechSequence=newSpeechSequence, priority=priority)
_lastTranslatedText = " ".join(x if isinstance(x, str) else "" for x in newSpeechSequence)

#
## This is overloaded as well because the generated text may contain already translated text by
Expand Down Expand Up @@ -278,6 +280,8 @@ def getPropertiesSpeech( # noqa: C901
else:
textList.append(levelTranslation)
types.logBadSequenceTypes(textList)
global _lastTranslatedText
_lastTranslatedText = " ".join(e for e in textList)
return textList

#
Expand Down Expand Up @@ -383,6 +387,16 @@ def script_toggleTranslate(self, gesture):

script_toggleTranslate.__doc__ = _("Enables translation to the desired language.")

def script_copyLastTranslation(self, gesture):
global _lastTranslatedText

if _lastTranslatedText is not None and len(_lastTranslatedText) > 0:
api.copyToClip(_lastTranslatedText)
ui.message(_("translation {text} ¨copied to clipboard".format(text=_lastTranslatedText)))
else:
ui.message(_("No translation to copy"))
script_copyLastTranslation.__doc__ = _("Copy the latest translated text to the clipboard.")

def script_flushAllCache(self, gesture):
if scriptHandler.getLastScriptRepeatCount() == 0:
ui.message(_("Press twice to delete all cached translations for all applications."))
Expand Down Expand Up @@ -434,6 +448,7 @@ def script_flushCurrentAppCache(self, gesture):

__gestures = {
"kb:nvda+shift+control+t": "toggleTranslate",
"kb:nvda+shift+c": "copyLastTranslation",
"kb:nvda+shift+control+f": "flushAllCache",
"kb:nvda+shift+f": "flushCurrentAppCache",
}
6 changes: 3 additions & 3 deletions buildVars.py
Expand Up @@ -20,7 +20,7 @@
"addon_description" : _("""Uses the Google Translate API to translate each spoken text to the desired language, on the fly.
This add-on requires an internet connection."""),
# version
"addon_version" : "2020.01",
"addon_version" : "2020.05",
# Author(s)
"addon_author" : u"Yannick PLASSIARD <podcastcecitek@gmail.com>",
# URL for the add-on documentation support
Expand All @@ -30,9 +30,9 @@
# Minimum NVDA version supported (e.g. "2018.3")
"addon_minimumNVDAVersion" : "2019.3",
# Last NVDA version supported/tested (e.g. "2018.4", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion" : "2019.3",
"addon_lastTestedNVDAVersion" : "2020.1",
# Add-on update channel (default is stable or None)
"addon_updateChannel" : "dev",
"addon_updateChannel" : "stable",
}


Expand Down

0 comments on commit 195eb2f

Please sign in to comment.