File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -751,17 +751,23 @@ def getCodeAddon(obj=None, frameDist=1):
751751 # Not found!
752752 raise AddonError ("Code does not belong to an addon" )
753753
754+
755+ _TRANSLATION_FUNCTIONS = ["_" , "ngettext" , "pgettext" , "npgettext" ]
756+
757+
754758def initTranslation ():
755759 addon = getCodeAddon (frameDist = 2 )
756760 translations = addon .getTranslationsInstance ()
757761 # Point _ to the translation object in the globals namespace of the caller frame
758- # FIXME: should we retrieve the caller module object explicitly?
759762 try :
760763 callerFrame = inspect .currentframe ().f_back
761- callerFrame .f_globals ['_' ] = translations .gettext
762- # Install pgettext and npgettext function.
763- callerFrame .f_globals ['pgettext' ] = translations .pgettext
764- callerFrame .f_globals ['npgettext' ] = translations .npgettext
764+ module = inspect .getmodule (callerFrame )
765+ [
766+ setattr (
767+ module , func , getattr (translations , "gettext" if func == "_" else func )
768+ )
769+ for func in _TRANSLATION_FUNCTIONS
770+ ]
765771 finally :
766772 del callerFrame # Avoid reference problems with frames (per python docs)
767773
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ Please refer to [the developer guide https://www.nvaccess.org/files/nvda/documen
4343- Note: this is an Add-on API compatibility breaking release.
4444Add-ons will need to be re-tested and have their manifest updated.
4545- Added extension point: ``treeInterceptorHandler.post_browseModeStateChange``. (#14969, @nvdaes)
46+ - It is now possible to use plural forms in addon's translations. (#15661, @beqabeqa473)
4647-
4748
4849=== API Breaking Changes ===
You can’t perform that action at this time.
0 commit comments