Skip to content

Commit

Permalink
v2019.09.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Plassiard committed Sep 17, 2019
1 parent 7608975 commit 424d139
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
addon/doc/*.css
addon/doc/en/
addon/doc/*/*.html
*_docHandler.py
*.html
*.ini
Expand Down
16 changes: 13 additions & 3 deletions 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.
Expand All @@ -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.
Expand Down
41 changes: 41 additions & 0 deletions 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)

43 changes: 25 additions & 18 deletions addon/globalPlugins/translate/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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")



Expand Down
2 changes: 1 addition & 1 deletion 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" : "2019.09.1",
"addon_version" : "2019.09.2",
# Author(s)
"addon_author" : u"Yannick PLASSIARD <podcastcecitek@gmail.com>",
# URL for the add-on documentation support
Expand Down
11 changes: 7 additions & 4 deletions sconstruct
Expand Up @@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Expand Down

0 comments on commit 424d139

Please sign in to comment.