On /poll page the number of votes are incorrect.
How to reproduce:
- Enable poll module for the first time
- Create a simple poll, 2 answers 0 starting vote counts (with uid 1)
- Vote for this poll (with uid 1)
- Add permission for anonymous users to see poll results
- Check the /poll page with uid 1. It will show 1 vote for the poll.
- Check the /poll page with anonymous. It will show 2 votes for the poll.
Core: Drupal 7.12
In the recent poll block it shows "1 vote", the correct number of votes!
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | Screenshot 2024-03-09 at 21.46.58.png | 30.18 KB | bramdriesen |
| #10 | fix_result_vote_translation.1502020-2.patch | 723 bytes | pbouchereau |
| #6 | fix_result_vote_translation.1502020.patch | 705 bytes | JensH |
Comments
Comment #0.0
edgarpe commentedAdded core version info.
Comment #1
amateescu commentedI cannot reproduce this in D7 latest -dev or D8. Are you sure these are only steps to reproduce the problem? Can you also try on a fresh Drupal install?
Comment #2
edgarpe commentedI'll try it with 7.x-dev or newer 7.14 and report what I found.
Comment #3
alexpottPoll is no longer part of core
Comment #4
adammaloneCan't reproduce this on a fresh 8.x install using instructions in #0
Feel free to open the issue again if it can be reproduced.
Comment #4.0
adammaloneAdded more info about the recent poll block.
Comment #5
JensH commentedThis is not the same problem as the one from OP, but I think there is an issue with the translation in the PollViewForm::showPollResults():
This will show "0% (1 vote)" for each answer on the result page of the poll when no user voted yet. It should be "0% (0 vote)", so the formatPlural() should depend on the votes.
Comment #6
JensH commentedPatch included
Comment #7
martijn de witChanging status because there is an actual patch now.
----
Using patch and fixes problem
Comment #8
berdir0 should use the plural version, what language are you using if you get that problem? maybe an issue with the plural formula? the current approach matches the documentation and while these do often not cover 0, that should work, I certainly can't reproduce this problem.
The dynamic string also means that detection of translatable strings doesn't work.
Comment #9
pbouchereau commentedThe problem comes from the fact that 0 isn't considered plural in all languages.
I think that the translation system handles that well, except when the count is hardcoded.
Is there a reason not to use the available placeholder for the singular form?
Wouldn't this work?
\Drupal::translation()->formatPlural($vote, '@count vote', '@count votes')Comment #10
pbouchereau commentedHere's a simpler patch that fixes the issue for me in French.
This one doesn't get in the way of translatable strings detection.
It's not related to the issue described here though, as pointed out in #5.
Should we open a new issue for this?
Comment #11
bramdriesenI tested this out but I think this is no longer an issue. Translations are properly being shown for me without the patch.
Feel free to re-open if I'm wrong.