diff --git a/source/addonHandler/__init__.py b/source/addonHandler/__init__.py index bf9bd6d4421..5f505c01a81 100644 --- a/source/addonHandler/__init__.py +++ b/source/addonHandler/__init__.py @@ -1,9 +1,9 @@ # -*- coding: UTF-8 -*- -#addonHandler.py -#A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2012-2019 Rui Batista, NV Access Limited, Noelia Ruiz Martínez, Joseph Lee, Babbage B.V., Arnold Loubriat -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. +# A part of NonVisual Desktop Access (NVDA) +# Copyright (C) 2012-2021 NV Access Limited, Rui Batista, Noelia Ruiz Martínez, +# Joseph Lee, Babbage B.V., Arnold Loubriat +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. import sys import os.path @@ -539,8 +539,8 @@ def initTranslation(): try: callerFrame = inspect.currentframe().f_back callerFrame.f_globals['_'] = translations.gettext - # Install our pgettext function. - callerFrame.f_globals['pgettext'] = languageHandler.makePgettext(translations) + # Install pgettext function. + callerFrame.f_globals['pgettext'] = translations.pgettext finally: del callerFrame # Avoid reference problems with frames (per python docs) diff --git a/source/languageHandler.py b/source/languageHandler.py index 7699701ec0e..b134ea0373f 100644 --- a/source/languageHandler.py +++ b/source/languageHandler.py @@ -1,14 +1,12 @@ -#languageHandler.py -#A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2007-2018 NV access Limited, Joseph Lee -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. +# A part of NonVisual Desktop Access (NVDA) +# Copyright (C) 2007-2021 NV Access Limited, Joseph Lee +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. """Language and localization support. This module assists in NVDA going global through language services such as converting Windows locale ID's to friendly names and presenting available languages. """ -import builtins import os import sys import ctypes @@ -123,27 +121,6 @@ def getAvailableLanguages(presentational=False): ) return langs -def makePgettext(translations): - """Obtaina pgettext function for use with a gettext translations instance. - pgettext is used to support message contexts, - but Python's gettext module doesn't support this, - so NVDA must provide its own implementation. - """ - if isinstance(translations, gettext.GNUTranslations): - def pgettext(context, message): - try: - # Look up the message with its context. - return translations._catalog[u"%s\x04%s" % (context, message)] - except KeyError: - return message - elif isinstance(translations, gettext.NullTranslations): - # A language with out a translation catalog, such as English. - def pgettext(context, message): - return message - else: - raise ValueError("%s is Not a GNUTranslations or NullTranslations object"%translations) - return pgettext - def getWindowsLanguage(): """ Fetches the locale name of the user's configured language in Windows. @@ -198,10 +175,8 @@ def setLanguage(lang): except IOError: trans=gettext.translation("nvda",fallback=True) curLang="en" - trans.install() - # Install our pgettext function. - import builtins - builtins.pgettext = makePgettext(trans) + # #9207: Python 3.8 adds gettext.pgettext, so add it to the built-in namespace. + trans.install(names=["pgettext"]) def getLanguage(): return curLang