From 62a1cf257eafb880af30eba6eb38665a3144ce14 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 16 May 2022 06:04:46 +0000 Subject: [PATCH] Improved poll texts for different conditions --- src/Model/Item.php | 19 +++++++++++++++++-- view/lang/C/messages.po | 27 +++++++++++++++++++++------ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 2435e15c2a..5b144fb73a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3196,13 +3196,28 @@ class Item $percent = $question['voters'] ? ($option['replies'] / $question['voters'] * 100) : 0; $options[$key]['percent'] = $percent; - $options[$key]['vote'] = DI::l10n()->t('%s (%d%s, %d votes)', $option['name'], round($percent, 1), '%', $option['replies']); + + if ($question['voters'] > 0) { + $options[$key]['vote'] = DI::l10n()->t('%s (%d%s, %d votes)', $option['name'], round($percent, 1), '%', $option['replies']); + } else { + $options[$key]['vote'] = DI::l10n()->t('%s (%d votes)', $option['name'], $option['replies']); + } + } + + if (!empty($question['voters']) && !empty($question['endtime'])) { + $summary = DI::l10n()->t('%d voters. Poll end: %s', $question['voters'], Temporal::getRelativeDate($question['endtime'])); + } elseif (!empty($question['voters'])) { + $summary = DI::l10n()->t('%d voters.', $question['voters']); + } elseif (!empty($question['endtime'])) { + $summary = DI::l10n()->t('Poll end: %s', Temporal::getRelativeDate($question['endtime'])); + } else { + $summary = ''; } $content .= Renderer::replaceMacros(Renderer::getMarkupTemplate('content/question.tpl'), [ '$question' => $question, '$options' => $options, - '$summary' => DI::l10n()->t('%d voters. Poll end: %s', $question['voters'], Temporal::getRelativeDate($question['endtime'])), + '$summary' => $summary, ]); } DI::profiler()->stopRecording(); diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 3d85ff31d7..263d07bd7b 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2022.05-rc\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-05-16 05:29+0000\n" +"POT-Creation-Date: 2022-05-16 06:01+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2534,8 +2534,8 @@ msgid "" "%2$s %3$s" msgstr "" -#: src/Content/Text/BBCode.php:1188 src/Model/Item.php:3243 -#: src/Model/Item.php:3249 src/Model/Item.php:3250 +#: src/Content/Text/BBCode.php:1188 src/Model/Item.php:3258 +#: src/Model/Item.php:3264 src/Model/Item.php:3265 msgid "Link to source" msgstr "" @@ -3738,17 +3738,32 @@ msgstr "" msgid "bytes" msgstr "" -#: src/Model/Item.php:3199 +#: src/Model/Item.php:3201 #, php-format msgid "%s (%d%s, %d votes)" msgstr "" -#: src/Model/Item.php:3205 +#: src/Model/Item.php:3203 +#, php-format +msgid "%s (%d votes)" +msgstr "" + +#: src/Model/Item.php:3208 #, php-format msgid "%d voters. Poll end: %s" msgstr "" -#: src/Model/Item.php:3231 src/Model/Item.php:3232 +#: src/Model/Item.php:3210 +#, php-format +msgid "%d voters." +msgstr "" + +#: src/Model/Item.php:3212 +#, php-format +msgid "Poll end: %s" +msgstr "" + +#: src/Model/Item.php:3246 src/Model/Item.php:3247 msgid "View on separate page" msgstr "" -- 2.39.5