Skip to content

Commit

Permalink
Making the addon ready for NVDA 2021.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Plassiard committed Jun 9, 2021
1 parent 1de2383 commit fe7a560
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 121 deletions.
2 changes: 1 addition & 1 deletion addon/doc/en/readme.md
@@ -1,7 +1,7 @@
# nvda-translate
Make NVDA translate any spoken text to the desired language.
## Download
- Stable (NVDA 2019.3+): [translate-2021.01](http://www.mtyp.fr/nvda/translate/translate-2021.01.nvda-addon).
- Stable (NVDA 2019.3+): [translate-2021.06.1](http://www.mtyp.fr/nvda/translate/translate-2021.06.1.nvda-addon).

## Installation

Expand Down
50 changes: 23 additions & 27 deletions addon/globalPlugins/translate/__init__.py
Expand Up @@ -16,26 +16,22 @@
import os, sys, time, codecs, re
import globalVars
import globalPluginHandler, logHandler, scriptHandler
try:
import api, controlTypes
import ui, wx, gui
import core, config
import wx
import speech
from speech import *
import json
import queue
curDir = os.path.abspath(os.path.dirname(__file__))

sys.path.insert(0, curDir)
sys.path.insert(0, os.path.join(curDir, "html"))
import markupbase
import mtranslate
import updater
import addonHandler, languageHandler
except Exception as e:
logHandler.log.exception("Failed to initialize translate addon", e)
raise e
import api, controlTypes
import ui, wx, gui
import core, config
import wx
import speech
from speech import *
import json
import queue
curDir = os.path.abspath(os.path.dirname(__file__))
logHandler.log.info("Importing modules from %s" % curDir)
sys.path.insert(0, curDir)
sys.path.insert(0, os.path.join(curDir, "html"))
import markupbase
import mtranslate
import updater
import addonHandler, languageHandler

addonHandler.initTranslation()
#
Expand Down Expand Up @@ -88,7 +84,7 @@ def translate(text):
#

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

if _enableTranslation is False:
Expand All @@ -110,7 +106,7 @@ def speak(speechSequence: SpeechSequence,
#

def getPropertiesSpeech( # noqa: C901
reason = controlTypes.REASON_QUERY,
reason = controlTypes.OutputReason.QUERY,
**propertyValues
):
global oldTreeLevel, oldTableID, oldRowNumber, oldRowSpan, oldColumnNumber, oldColumnSpan
Expand Down Expand Up @@ -141,9 +137,9 @@ def getPropertiesSpeech( # noqa: C901
and (
roleText
or reason not in (
controlTypes.REASON_SAYALL,
controlTypes.REASON_CARET,
controlTypes.REASON_FOCUS
controlTypes.OutputReason.SAYALL,
controlTypes.OutputReason.CARET,
controlTypes.OutputReason.FOCUS
)
or not (
name
Expand All @@ -157,8 +153,8 @@ def getPropertiesSpeech( # noqa: C901
and (
role != controlTypes.ROLE_MATH
or reason not in (
controlTypes.REASON_CARET,
controlTypes.REASON_SAYALL
controlTypes.OutputReason.CARET,
controlTypes.OutputReason.SAYALL
)
)):
textList.append(translate(roleText) if roleText else controlTypes.roleLabels[role])
Expand Down
4 changes: 2 additions & 2 deletions addon/globalPlugins/translate/mtranslate/core.py
Expand Up @@ -33,7 +33,7 @@
import urllib
import HTMLParser
else:
import html.parser
import customhtml.parser
import urllib.request
import urllib.parse

Expand All @@ -53,7 +53,7 @@ def unescape(text):
if (sys.version_info[0] < 3):
parser = HTMLParser.HTMLParser()
else:
parser = html.parser.HTMLParser()
parser = customhtml.parser.HTMLParser()
return (parser.unescape(text))


Expand Down
75 changes: 50 additions & 25 deletions buildVars.py
@@ -1,50 +1,75 @@
# -*- coding: utf-8 -*-
# -*- coding: UTF-8 -*-

# Build customizations
# Change this file instead of sconstruct or manifest files, whenever possible.

# Full getext (please don't change)
_ = lambda x : x

# Since some strings in `addon_info` are translatable,
# we need to include them in the .po files.
# Gettext recognizes only strings given as parameters to the `_` function.
# To avoid initializing translations in this module we simply roll our own "fake" `_` function
# which returns whatever is given to it as an argument.
def _(arg):
return arg


# Add-on information variables
addon_info = {
# for previously unpublished addons, please follow the community guidelines at:
# https://bitbucket.org/nvdaaddonteam/todo/raw/master/guideLines.txt
# add-on Name, internal for nvda
"addon_name" : "translate",
# add-on Name/identifier, internal for NVDA
"addon_name": "translate",
# Add-on summary, usually the user visible name of the addon.
# Translators: Summary for this add-on to be shown on installation and add-on information.
"addon_summary" : _("Translate"),
# Translators: Summary for this add-on
# to be shown on installation and add-on information found in Add-ons Manager.
"addon_summary": _("Translate"),
# Add-on description
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
"addon_description" : _("""Uses the Google Translate API to translate each spoken text to the desired language, on the fly.
"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" : "2021.01.3",
"addon_version": "2021.06.1",
# Author(s)
"addon_author" : u"Yannick PLASSIARD <podcastcecitek@gmail.com>, Hxebolax",
"addon_author": u"Yannick PLASSIARD <podcastcecitek@gmail.com>, Hxebolax",
# URL for the add-on documentation support
"addon_url" : None,
"addon_url": None,
# Documentation file name
"addon_docFileName" : "readme.html",
# 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" : "2020.3",
# Add-on update channel (default is stable or None)
"addon_updateChannel" : "stable",
"addon_docFileName": "readme.html",
# Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional)
"addon_minimumNVDAVersion": "2021.1",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2021.1",
# Add-on update channel (default is None, denoting stable releases,
# and for development releases, use "dev".)
# Do not change unless you know what you are doing!
"addon_updateChannel": None,
}


import os.path

# Define the python files that are the sources of your add-on.
# You can use glob expressions here, they will be expanded.
pythonSources = ['addon/globalPlugins/translate/*.py', 'addon/globalPlugins/translate/*/*.py']
# You can either list every file (using ""/") as a path separator,
# or use glob expressions.
# For example to include all files with a ".py" extension from the "globalPlugins" dir of your add-on
# the list can be written as follows:
pythonSources = ["addon/globalPlugins/*.py",
"addon/globalPlugins/*/*.py",
"addon/globalPlugins/*/*/*.py"]
# For more information on SCons Glob expressions please take a look at:
# https://scons.org/doc/production/HTML/scons-user/apd.html


# Files that contain strings for translation. Usually your python sources
i18nSources = pythonSources + ["buildVars.py"]

# Files that will be ignored when building the nvda-addon file
# Paths are relative to the addon directory, not to the root directory of your addon sources.
excludedFiles = []

# Base language for the NVDA add-on
# If your add-on is written in a language other than english, modify this variable.
# For example, set baseLanguage to "es" if your add-on is primarily written in spanish.
baseLanguage = "en"

# Markdown extensions for add-on documentation
# Most add-ons do not require additional Markdown extensions.
# If you need to add support for markup such as tables, fill out the below list.
# Extensions string must be of the form "markdown.extensions.extensionName"
# e.g. "markdown.extensions.tables" to add tables.
markdownExtensions = []

0 comments on commit fe7a560

Please sign in to comment.