Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

Add support for ngettext#97

Merged
seanbudd merged 3 commits into
nvaccess:masterfrom
CyrilleB79:supportNGettext
Jun 13, 2023
Merged

Add support for ngettext#97
seanbudd merged 3 commits into
nvaccess:masterfrom
CyrilleB79:supportNGettext

Conversation

@CyrilleB79

@CyrilleB79 CyrilleB79 commented May 10, 2023

Copy link
Copy Markdown
Contributor

Links to issues:

Preliminary to nvaccess/nvda#12445

Context

A first use of ngettext had been introduced in NVDA in nvaccess/nvda#11598 and nvaccess/nvda#12432.
However these changes were removed in nvaccess/nvda#12448.

Issue

As written by @michaelDCurran in nvaccess/nvda#12448:

However, it seems that our PO validation code in the translation system is not handling plural forms well, and is incorrectly classing translations as missing brace format variables, as it is incorrectly comparing the translation with the message before that one.
It then outputs the following error:
Message starting on line 7169
Original: "{startTime} to {endTime}"
Translated: "category {categories}"
Error: missing brace format interpolation, extra brace format interpolation
Expected: these brace format interpolations: {endTime}, {startTime}
Got: these brace format interpolations: {categories}

Changes in this PR

This PR adds the support of ngettext messages in the PO validation script.

Tests

Test 1

Run new scripts/poChecker.py on various files:

The files containing the plural string have been taken from SVN SRT repo when a first attempt to introduce ngettext in NVDA was made.

Test 2

Comparison of the output of the modified script with the output of the original one. The comparison has been made on the nvda.po files of all languages available in SVN repo screenreadertranslations (commit 74391) as well as with all the nvda.po files available in the last master version of NVDA's Git repo (commit 96764959510a19d390f4493b78510df3a353cd50).
The comparison has been made thanks to a test script made for this task.

Some diffs have been found in the order in which the placeholders are listed in the report, e.g.:

-Expected: these brace format interpolations: {hours:d}, {minutes:d}
+Expected: these brace format interpolations: {minutes:d}, {hours:d}

The placeholders are stored in a Python set in scripts/poChecker.py, thus their order is not significant. I do not know however why the order has changed from one version of scripts/poChecker.py to another.
Thus I have amended my test script to reorder alphabetically the placeholders in the output of scripts/poChecker.py so that we can ignore the order of placeholders on a same line.
After this reordering post-processing, there was no diff between the outputs of the old and the new version of the script.

For reference here is the (quick and dirty) test script that I have used (updated and re-tested on June 9 2023):
launch_poChecker.py.txt

@CyrilleB79 CyrilleB79 marked this pull request as ready for review May 11, 2023 13:06
@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@michaelDCurran and @seanbudd:
If possible for you, I would see the following planning regarding ngettext introduction in NVDA:

  • Before 2023.2 beta phase:
    • (You) Review and merge this PR
    • (I) Submit a PR against NVDA to introduce a limited subset of ngettext usage, e.g. 2 or 3 occurrences on strings frequently used
    • (You) Merge this last PR (limited usage of ngettext)
  • During 2023.2 beta phase:
    • Check with translators that there is no issue using the translation framework
  • In NVDA 2023.2beta2 or higher (2023.2 rc or stable)
    • Check with users that the translated strings of the test subset are reported as expected in all languages
  • During 2023.3 alpha phase:
    • (I) Submit another PR with the remaining strings requiring the use of ngettext.
      NVDA 2023.3 would thus be the first version with full usage of ngettext.

Note: I may also separate simple cases of ngettext usage and more complex ones (e.g. strings containing two numbers) as explained in nvaccess/nvda#12445.

@seanbudd seanbudd self-requested a review May 18, 2023 07:43
@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@seanbudd, @michaelDCurran:
Now that add-on store work has been merged and before beta phase, would you provide a feedback on this planning?
Thanks.

@michaelDCurran

michaelDCurran commented Jun 7, 2023 via email

Copy link
Copy Markdown
Member

@seanbudd

seanbudd commented Jun 8, 2023

Copy link
Copy Markdown
Member

The plan looks good to us, feel free to go ahead with it

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

Thanks @seanbudd. In this case, the first step is on your side: review and merge the current PR.

Comment thread scripts/poChecker.py Outdated
Comment thread scripts/poChecker.py
@CyrilleB79 CyrilleB79 requested a review from seanbudd June 9, 2023 09:09
Comment thread scripts/poChecker.py

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CyrilleB79 for the explanation

@seanbudd seanbudd merged commit 0c02684 into nvaccess:master Jun 13, 2023
seanbudd pushed a commit to nvaccess/nvda that referenced this pull request Jun 19, 2023
This PR is the first step to reintroduce the distinction of singulare/plural forms when formatting UI strings. The project is as follow:
1. This PR introduce three strings to be able to test the feature.
2. 2023.2 beta phase should be used to validate more widely the feature with translators
3. A second PR during 2023.3 dev cycle will implement the plural forms for all UI strings containing only one value to format them.
4. A third PR should implement more complex cases of string formatted by two or more values, e.g. such as "table with x rows and y columns".

This step-by-step approach should allow to lose less work in case an issue occurs and requires to revert changes.

### Link to issue number:
First step to implement #12445.
Restoring #11598, #12432 and #12435 that were reverted in #12448.
Unblocked by nvaccess/mrconfig#97.
### Summary of the issue:
Some UI messages or strings are reported with plural form, no matter the number passed as parameter to format them, e.g. NVDA reports "list with 1 items" with "s" even if there is only one item.

### Description of user facing changes
The following strings will be reported using singular or plural form depending on the number used to format them:
* "with %s items" (used to describe the number of items in a list on the web)
* ".1f lines" (used when reporting multiple line spacing formatting in MS Word)
* ""categories {categories}" used to report categories of appointments in MS Outlook

Translators will be able to translate singular or plural forms.

### Description of development approach
* First revert #12448 to restore the first attempt that was made to introduce `ngettext`.
* Develop a custom `npgettext` function the same way as `pgettext` was introduced in NVDA since `npgettext` is not available in Python 3.7; `pgettext` and `npgettext` are available natively in Python 3.8.
* `ngettext` and `npgettext` are made accessible without importing them; `pgettext` was already added previously in builtins.
* Implement the plural form for two strings that are more commonly used than Outlook appointments category reporting:
  * "with %s items", using `ngettext`
  * "%.1f lines", using `npgettext`
@CyrilleB79 CyrilleB79 deleted the supportNGettext branch June 23, 2023 14:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants