addonHandler: install ngettext function when calling initTranslation#15661
Merged
Conversation
10e6b3e to
fd09e33
Compare
Contributor
|
Hi, I thought add-ons were covered under gettext.ngettext when folks worked on it in 2023.2. Thanks.
|
Contributor
Author
|
ngettext is not available in addons for now.
We faced a problem when implementing plural forms.
…On 10/21/23, Joseph Lee ***@***.***> wrote:
Hi, I thought add-ons were covered under gettext.ngettext when folks worked
on it in 2023.2. Thanks.
--
Reply to this email directly or view it on GitHub:
#15661 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
--
with best regards Beqa Gozalishvili
Tell: +995593454005
Email: ***@***.***
Web: https://gozaltech.org
Skype: beqabeqa473
Telegram: https://t.me/gozaltech
facebook: https://facebook.com/gozaltech
twitter: https://twitter.com/beqabeqa473
Instagram: https://instagram.com/beqa.gozalishvili
|
lukaszgo1
reviewed
Oct 22, 2023
Resolves problem of not working plurals in addons
fd09e33 to
b20739a
Compare
See test results for failed build of commit 1d3c0cc9e7 |
Contributor
Author
|
In that case i won't be able to store dictionary outside the function
and it is not so good.
…On 10/22/23, Łukasz Golonka ***@***.***> wrote:
@lukaszgo1 commented on this pull request.
> try:
callerFrame = inspect.currentframe().f_back
- callerFrame.f_globals['_'] = translations.gettext
- # Install pgettext and npgettext function.
- callerFrame.f_globals['pgettext'] = translations.pgettext
- callerFrame.f_globals['npgettext'] = translations.npgettext
+ module = inspect.getmodule(callerFrame)
+ [
I'd personally avoid the `getattr` call by storing the functions in the
dictionary, and use explicit names for consistency as follows:
```python
_TRANSLATION_FUNCTIONS = {translations.gettext: "_", translations.ngettext:
"ngettext", translations.pgettext: "pgettext", translations.npgettext:
"npgettext"}
```
--
Reply to this email directly or view it on GitHub:
#15661 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
--
with best regards Beqa Gozalishvili
Tell: +995593454005
Email: ***@***.***
Web: https://gozaltech.org
Skype: beqabeqa473
Telegram: https://t.me/gozaltech
facebook: https://facebook.com/gozaltech
twitter: https://twitter.com/beqabeqa473
Instagram: https://instagram.com/beqa.gozalishvili
|
Contributor
What exactly is not good about properly encapsulating the variable inside the only function which needs it? |
lukaszgo1
approved these changes
Oct 22, 2023
lukaszgo1
left a comment
Contributor
There was a problem hiding this comment.
LGTM, Thanks for your work on this @beqabeqa473 !
seanbudd
reviewed
Oct 22, 2023
Contributor
Author
|
it never worked before.
…On 10/23/23, Sean Budd ***@***.***> wrote:
@seanbudd commented on this pull request.
> @@ -43,6 +43,7 @@ Please refer to [the developer guide
> https://www.nvaccess.org/files/nvda/documen
- Note: this is an Add-on API compatibility breaking release.
Add-ons will need to be re-tested and have their manifest updated.
- Added extension point:
``treeInterceptorHandler.post_browseModeStateChange``. (#14969, @nvdaes)
+- It is now possible to use plural forms in addon's translations. (#15661,
@beqabeqa473)
If this currently works in 2023.2 and 2023.3, then fixing this is an
unreleased regression and doesn't need a change log entry
```suggestion
```
--
Reply to this email directly or view it on GitHub:
#15661 (review)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
--
with best regards Beqa Gozalishvili
Tell: +995593454005
Email: ***@***.***
Web: https://gozaltech.org
Skype: beqabeqa473
Telegram: https://t.me/gozaltech
facebook: https://facebook.com/gozaltech
twitter: https://twitter.com/beqabeqa473
Instagram: https://instagram.com/beqa.gozalishvili
|
seanbudd
approved these changes
Oct 23, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
None
Summary of the issue:
Currently, it is not possible to use gettext plural forms in addons.
Description of user facing changes
Nothing
Description of development approach
Refactored installing of translation functions.
Now they are defined in list just above initTranslation function, and set in the caller module itself instead of adding these functions in frame_globals.
Testing strategy:
Tested and confirmed, that plural forms are now working in addons.
Known issues with pull request:
None
Code Review Checklist: