diff --git a/.gitignore b/.gitignore index 6d124be..d2452ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ addon/doc/*.css -addon/doc/en/ +addon/doc/*/*.html *_docHandler.py *.html *.ini diff --git a/README.md b/README.md index 024d4d2..16c2b72 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # nvda-translate Make NVDA translate any spoken text to the desired language. +## Download +- Stable release can be found [here](https://www.mtyp.fr/nvda/translate-2019.09.2.nvda-addon). + ## Installation This add-on installs like any other add-un: Press enter on the "translate-x.y.nvda-addon" file, and answer "Yes" to all asked questions. @@ -10,15 +13,22 @@ When installed, the add-on will detect the language your NVDA installation is se Then, to enable or disable the translation, press NVDA+Shift+Control+T. This gesture can be modified within NVDA Preferences menu -> Command Gestures dialog. +### Gestures +The following gestures are defined (and can be changed within the Gesture commands dialog): +- NVDA+Shift+Control+T: Activates / deactivates the translation. +- NVDA+Shift+F (twice quickly): Clears the cache for the current application. +- NVDA+Shipt+Control+F (twice quickly): Clear all caches for all translations for all applications. + +## About Cache +To increase performances (see below), each translated text is stored within a cache file. A cache file is created for each application the translation has been activated in, and is located in the "translation-cache" directory within your NVDA's user configuration directory. + ## How it works When active, the add-on will intercept any spoken text and connect to the Google Translate system to translate it to the desired language. This means that any text can be translated, from any app or game that uses NVDA to speak text, to websites. ## Privacy -Please, be aware that when the feature is active, any spoken text is sent to the Google Translate service. It means that any spoken information will be sent, whatever this could be (a simple sentence, file names within your Windows Explorer, mail content, contacts, phone numbers, or even credit card numbers). It is therefore important to activate this feature only when you're certain of which text your NVDA will speak. This module has been primarily developed to be used within games, so no privacy concerns are present. You're free to used it with whatever you want, but at your own risks. - -Final note: It is not planned to implement a filter function that would prevent the translation of sensitive information, as it is quite hard to guess what may be considered sensitive. It's therefore the responsibility of the user to deactivate the feature when using sensitive data; the add-on author(s) may not be responsible for translating any sensitive, private, or confidential data. +Please, be aware that when the feature is active, any spoken text is sent to the Google Translate service. It means that any spoken information will be sent, whatever this could be (a simple sentence, file names within your Windows Explorer, mail content, contacts, phone numbers, or even credit card numbers). It is therefore important to activate this feature only when you're certain of which text your NVDA will speak. This module has been primarily developped to be used within games, so no privacy concerns are present. You're free to use it with whatever you want, but at your own risks. ## About Performances You may notice that when the feature is active, there is a delay between each spoken text. This is due to the translate API: because the add-on do not use the non-free Google Translate API SDK, an HTTP connection is made each and every time a text has to be translated. Therefore, a 8mbps Internet connection is recommended for this feature to work correctly. diff --git a/addon/doc/en/readme.md b/addon/doc/en/readme.md new file mode 100644 index 0000000..16c2b72 --- /dev/null +++ b/addon/doc/en/readme.md @@ -0,0 +1,41 @@ +# nvda-translate +Make NVDA translate any spoken text to the desired language. +## Download +- Stable release can be found [here](https://www.mtyp.fr/nvda/translate-2019.09.2.nvda-addon). + +## Installation + +This add-on installs like any other add-un: Press enter on the "translate-x.y.nvda-addon" file, and answer "Yes" to all asked questions. + +## Usage +When installed, the add-on will detect the language your NVDA installation is set to, or will get the Windows active language as a fallback. This language will be used to translate any spoken text, when the feature is activated. +**Note:** It is currently not possible to set this manually within a Preferences dialog, this may however be implemented in a future release. + +Then, to enable or disable the translation, press NVDA+Shift+Control+T. This gesture can be modified within NVDA Preferences menu -> Command Gestures dialog. + +### Gestures +The following gestures are defined (and can be changed within the Gesture commands dialog): +- NVDA+Shift+Control+T: Activates / deactivates the translation. +- NVDA+Shift+F (twice quickly): Clears the cache for the current application. +- NVDA+Shipt+Control+F (twice quickly): Clear all caches for all translations for all applications. + +## About Cache +To increase performances (see below), each translated text is stored within a cache file. A cache file is created for each application the translation has been activated in, and is located in the "translation-cache" directory within your NVDA's user configuration directory. + +## How it works + +When active, the add-on will intercept any spoken text and connect to the Google Translate system to translate it to the desired language. This means that any text can be translated, from any app or game that uses NVDA to speak text, to websites. + +## Privacy + +Please, be aware that when the feature is active, any spoken text is sent to the Google Translate service. It means that any spoken information will be sent, whatever this could be (a simple sentence, file names within your Windows Explorer, mail content, contacts, phone numbers, or even credit card numbers). It is therefore important to activate this feature only when you're certain of which text your NVDA will speak. This module has been primarily developped to be used within games, so no privacy concerns are present. You're free to use it with whatever you want, but at your own risks. + +## About Performances +You may notice that when the feature is active, there is a delay between each spoken text. This is due to the translate API: because the add-on do not use the non-free Google Translate API SDK, an HTTP connection is made each and every time a text has to be translated. Therefore, a 8mbps Internet connection is recommended for this feature to work correctly. +Of course, the more bandwidth you have, the faster the translation will happen. + +## Contact and bug reports +- If you encounter any issue while using this add-on, please create a GitHub issue so that it will be easily trackable. +- Of course, Pull Requests are also welcomed if you want to extend the add-on or fix any issue. +- To contact me, you can use the address: [contact author](mailto:podcastcecitek@gmail.com) + diff --git a/addon/globalPlugins/translate/__init__.py b/addon/globalPlugins/translate/__init__.py index e068f10..711dd66 100644 --- a/addon/globalPlugins/translate/__init__.py +++ b/addon/globalPlugins/translate/__init__.py @@ -15,7 +15,7 @@ import os, sys, time, codecs, re import globalVars -import globalPluginHandler, logHandler +import globalPluginHandler, logHandler, scriptHandler import api, controlTypes import ui, wx, gui, core, config, speech import json @@ -339,15 +339,18 @@ def script_toggleTranslate(self, gesture): script_toggleTranslate.__doc__ = _("Enables translation to the desired language.") def script_flushAllCache(self, gesture): - if gui.messageBox(_("Are you sure you want to delete all cached translations?"), _("Delete all translations"), style=wx.YES | wx.NO | wx.CENTER, parent=gui.mainFrame) == wx.YES: - global _translationCache - _translationCache = {} - path = os.path.join(globalVars.appArgs.configPath, "translation-cache") - for entry in os.listdir(path): - try: - os.unlink(os.path.join(path, entry)) - except Exception as e: - logHandler.log.error("Failed to remove {entry}".format(entry=entry)) + if scriptHandler.getLastScriptRepeatCount() == 0: + ui.message(_("Press twice to delete all cached translations for all applications.")) + return + global _translationCache + _translationCache = {} + path = os.path.join(globalVars.appArgs.configPath, "translation-cache") + for entry in os.listdir(path): + try: + os.unlink(os.path.join(path, entry)) + except Exception as e: + logHandler.log.error("Failed to remove {entry}".format(entry=entry)) + ui.message(_("All translations have been deleted.")) script_flushAllCache.__doc__ = _("Remove all cached translations for all applications.") def script_flushCurrentAppCache(self, gesture): @@ -356,15 +359,19 @@ def script_flushCurrentAppCache(self, gesture): except: ui.message(_("No focused application")) return - if gui.messageBox(_("Are you sure you want to remove translations for {appName}".format(appName=appName)), _("Remove translations for {appName}".format(appName=appName)), style=wx.YES | wx.NO | wx.CENTER, parent=gui.mainFrame) == wx.YES: - global _translationCache + if scriptHandler.getLastScriptRepeatCount() == 0: + ui.message(_("Press twice to delete all translations for {app}".format(app=appName))) + return + + global _translationCache - _translationCache[appName] = {} - try: - os.unlink(os.path.join(globalVars.appArgs.configPath, "{app}.json".format(app=appName))) - except Exception as e: - logHandler.log.error("Failed to remove cache for {appName}: {e}".format(appName=appName, e=e)) - script_flushCurrentAppCache.__coc__ = _("Remove translation cache for the currently focused application") + _translationCache[appName] = {} + try: + os.unlink(os.path.join(globalVars.appArgs.configPath, "translation-cache", "{app}.json".format(app=appName))) + except Exception as e: + logHandler.log.error("Failed to remove cache for {appName}: {e}".format(appName=appName, e=e)) + ui.message(_("Transpation cache for {app} has been deleted.".format(app=appName))) + script_flushCurrentAppCache.__doc__ = _("Remove translation cache for the currently focused application") diff --git a/buildVars.py b/buildVars.py index bfa42fc..11c4c36 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" : "2019.09.1", + "addon_version" : "2019.09.2", # Author(s) "addon_author" : u"Yannick PLASSIARD ", # URL for the add-on documentation support diff --git a/sconstruct b/sconstruct index 6721c03..f126471 100644 --- a/sconstruct +++ b/sconstruct @@ -22,12 +22,15 @@ def md2html(source, dest): "\"]]": " #", } # python3 fixes - if sys.version_info.major == 3: - headerDic.iteritems = headerDic.items with codecs.open(source, "r", "utf-8") as f: mdText = f.read() - for k, v in headerDic.iteritems(): - mdText = mdText.replace(k, v, 1) + if sys.version_info.major == 2: + for k, v in headerDic.iteritems(): + mdText = mdText.replace(k, v, 1) + else: + for k, v in headerDic.items(): + mdText = mdText.replace(k, v, 1) + htmlText = markdown.markdown(mdText) with codecs.open(dest, "w", "utf-8") as f: f.write("\n" +