Files
FreshRSS/app/views/javascript/nbUnreadsPerFeed.phtml
Frans de Jonge 612ac4f117 Notifications: pluralize the "new articles" count message (#8988)
* Generate new articles notification string in PHP

Closes #6470

Changes proposed in this pull request:

- Generate notifications string  in PHP
- Use plurals support

* New articles notification: switch to plural forms

* README status

* fix paramInt invocation

* i18n

* make fix-all

* Apply suggestion from @Frenzie

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
2026-07-06 11:16:29 +02:00

29 lines
943 B
PHTML

<?php
declare(strict_types=1);
/** @var FreshRSS_ViewJavascript $this */
$result = [
'feeds' => [],
'tags' => [],
];
$nbUnreadFeeds = 0;
foreach ($this->categories as $cat) {
foreach ($cat->feeds() as $feed) {
if ($feed->priority() > FreshRSS_Feed::PRIORITY_HIDDEN) {
$feedUnread = $feed->nbNotRead();
$result['feeds'][$feed->id()] = $feedUnread;
$nbUnreadFeeds += $feedUnread;
}
}
}
foreach ($this->tags as $tag) {
$result['tags'][$tag->id()] = $tag->nbUnread();
}
$nbUnreadBefore = max(0, Minz_Request::paramInt('previous_unread') ?: 0);
$nbNew = max(0, $nbUnreadFeeds - $nbUnreadBefore);
$result['notifBody'] = trim(
(Minz_Translate::plural('gen.js.feedback.body_new_articles', $nbNew) ?? _t('gen.js.feedback.body_new_articles', $nbNew)) . ' ' .
(Minz_Translate::plural('gen.js.feedback.body_unread_articles', $nbUnreadFeeds) ?? _t('gen.js.feedback.body_unread_articles', $nbUnreadFeeds))
);
echo json_encode($result);