diff --git a/README.md b/README.md index eafc00c..f8fe95c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/addon/doc/en/readme.md b/addon/doc/en/readme.md index 8ae17b1..f8fe95c 100644 --- a/addon/doc/en/readme.md +++ b/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 diff --git a/addon/globalPlugins/translate/__init__.py b/addon/globalPlugins/translate/__init__.py index dbf9eca..a9e7d6b 100644 --- a/addon/globalPlugins/translate/__init__.py +++ b/addon/globalPlugins/translate/__init__.py @@ -45,6 +45,8 @@ _gpObject = None _lastError = 0 _enableTranslation = False +_lastTranslatedText = None +_lastTranslatedTextTime = 0 def translate(text): @@ -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 @@ -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) @@ -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 @@ -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 # @@ -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.")) @@ -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", } diff --git a/buildVars.py b/buildVars.py index 81aaec5..9547389 100644 --- a/buildVars.py +++ b/buildVars.py @@ -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 ", # URL for the add-on documentation support @@ -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", }