Skip to content

Plural forms support for translatable strings#15013

Merged
seanbudd merged 5 commits into
nvaccess:masterfrom
CyrilleB79:ngettext
Jun 19, 2023
Merged

Plural forms support for translatable strings#15013
seanbudd merged 5 commits into
nvaccess:masterfrom
CyrilleB79:ngettext

Conversation

@CyrilleB79

@CyrilleB79 CyrilleB79 commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

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 Remove one and only use of ngettext for now #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

Testing strategy:

I have tested the 3 modified strings in the situation where they are reported:

  • List of one or many items on the web
  • Report formatting in MS Word with line spacing set to "multiple" with value of 0.8 or 3
  • Outlook appointments with 1 or 2 assigned categories

Note: for MS Word, since reporting a line spacing of 1 line is not possible, I have tested in the console:

>>> npgettext("line spacing value", "with %s item", "with %s items", 1)

The checks were done for the following languages:

  • English: no translation
  • French: I have provided an updated .po with the 3 times 2 strings translated
  • Italian: no updated translation provided; used to check the fallback to English strings

Known issues with pull request:

Other strings with plural forms to be implemented in subsequent PRs.

Change log entries:

New features
Changes
Bug fixes
For Developers
TBD

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • Security precautions taken.

Cc @LeonarddeR (author of 11598)
Cc @zstanecic (translator of various Slavic languages) Slavic languages are known to have complex forms of plural

… to be getting confused by it, and this was not the first and only issue. (nvaccess#12448)"

This reverts commit 76fc1f7.
@AppVeyorBot

Copy link
Copy Markdown
  • FAIL: Translation comments check. Translation comments missing or unexpectedly included. See build log for more information.
  • PASS: Unit tests.
  • PASS: Lint check.
  • FAIL: System tests (tags: installer NVDA). See test results for more information.
  • Build (for testing PR): https://ci.appveyor.com/api/buildjobs/8hgen7el8ui557io/artifacts/output/nvda_snapshot_pr15013-28434,5bbca249.exe
  • CI timing (mins):
    INIT 0.0,
    INSTALL_START 0.9,
    INSTALL_END 0.9,
    BUILD_START 0.0,
    BUILD_END 26.2,
    TESTSETUP_START 0.0,
    TESTSETUP_END 0.4,
    TEST_START 0.0,
    TEST_END 19.3,
    FINISH_END 0.1

See test results for failed build of commit 5bbca24981

@CyrilleB79 CyrilleB79 marked this pull request as ready for review June 15, 2023 20:47
@CyrilleB79 CyrilleB79 requested a review from a team as a code owner June 15, 2023 20:47
@CyrilleB79 CyrilleB79 requested a review from seanbudd June 15, 2023 20:47
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 3a954f26ef

Comment thread source/NVDAObjects/window/winword.py Outdated
Comment thread source/languageHandler.py Outdated
Comment thread source/languageHandler.py Outdated
Comment thread source/languageHandler.py Outdated
@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@seanbudd thanks for the review. I have addressed your comments in a73163e.

@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 - any suggestions on a change log entry?

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

I was unsure about the change log.

I have no idea of something significant to put in all the end-user related sections; maybe rather when we convert all other strings of NVDA's codebase later.

Maybe in changes for dev:
Translatable strings can now be defined with a singular and a plural form; for now only few strings are tested in NVDA's code base. (#12445)

But do not close #12445 since it is not complete.

[Not: should I use "code base" or "codebase"]

Is it OK for you?

@seanbudd

seanbudd commented Jun 19, 2023

Copy link
Copy Markdown
Member

Thanks @CyrilleB79 - makes sense. I'm going to drop the information about the strings as that may change by release time.

Translatable strings can now be defined with a singular and a plural form using ngettext and npgettext. (#12445)

@seanbudd seanbudd merged commit 4002395 into nvaccess:master Jun 19, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone Jun 19, 2023
@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@seanbudd, according to the step-by-step approach written the initial description, it is not expected to have many more strings until the release: 2023.2 should be used to test the first few strings and 2023.3 to convert the rest of NVDA's codebase.

Anyway, it does not matter: the change log item that you have merged is less precise but remain correct in any case.

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@seanbudd, also, if possible, it would be nice to have soon a merge from master to beta (e.g. before Friday) so that we can test these strings early with translators. Thanks!

@seanbudd

Copy link
Copy Markdown
Member

@CyrilleB79 - done

seanbudd pushed a commit to nvaccess/mrconfig that referenced this pull request Jun 27, 2023
…NVDA/#15013) (#106)

Issue
Today, the first version of NVDA including nvaccess/nvda#15013 has been merged to SVN. The translatable strings using ngettext appear in the nvda.po as expected. But the strings using npgettext ("%.1f lignes") don't.

Cause
In PR nvaccess/nvda#15013, the command to build the .pot file has been updated to be able to recognize npgettext as a function operating on translatable strings.
However, the nvda2svn script in the current repository does not use the .pot generated by NVDA's sconstruct; xgettext is called directly in the current repository instead. Thus the command in the nvda2svn script should match the one in NVDA's sconstruct. The change in NVDA's repository had not been duplicated here.

Solution
Update xgettext's parameters as per what was done in NVDA's repo to be able to detect ngettext as a function operating on translatable strings.

Testing
I have no way to test before merging this PR.

@seanbudd, could you test manually this branch on NVAccess server the result of nvda2svn script or merge this PR and trigger nvda2svn?

The string "%.1f lignes" should appear in the .pot file with a "msgid_plural" field.
Also the strings "category {categories}" and "with %s item" should still have the msgid_plural field (as today)
@CyrilleB79 CyrilleB79 deleted the ngettext branch June 27, 2023 07:49
seanbudd pushed a commit that referenced this pull request Dec 8, 2023
Closes #12445
Follow-up of #15013.

Summary of the issue:
When possible NVDA needs to distinguish between singular and plural in UI messages. The impact may be more significant in languages such as Slavic ones, where there are more than one plural form.

Description of user facing changes
In NVDA UI messages, i.e. in GUI or when NVDA speaks or brailles messages, messages will use singular/plural form as needed.

Description of development approach
Look for all strings containing "%" or "{" in the .pot and check if a plural form is needed. And replace _ / pgettext by ngettext / npgettext where needed.
Some expression containing a number have been pluralized even if they do not differ between singular and plural form in English due to the difference being visible in translations due to a different grammar. E.g.: "{numFingers} finger {action}" in English to be translated to "{action} {numFingers} doigt" (singular) vs "{action} {numFingers} doigts" (plural) in French.
table-rowcount and table-columncount control fields of the virtual buffer's text info have had to be converted to integer (previously strings), so that computation can be done.
No change log needed except for the code's API breaking change.
Testing strategy:
Manual smoke test on a subset of strings.
Feedback from translators during translation period and communication with the translators mailing list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants