Skip to content

Commit 1d3c0cc

Browse files
authored
Merge b20739a into d0614df
2 parents d0614df + b20739a commit 1d3c0cc

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

source/addonHandler/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff 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+
754758
def 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

user_docs/en/changes.t2t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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.
4444
Add-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 ===

0 commit comments

Comments
 (0)