Problem/Motivation
In case of notifications remaining, revisedSentance text value on the itemsStatusChanged() differs by notification count.
The current implement use several Drupal.t() and if-else clause, finally concatenate these text but this section can write at once with Drupal.formatPlural().
Proposed resolution
Before:
revisedSentance = `${Drupal.t(
'You have ',
)}<span class="bg-white px-1 text-black fw-bold rounded-1 fst-italic">${
remainingCount
}</span>`;
if (remainingCount === 1) {
revisedSentance += Drupal.t(' unread notification');
} else {
revisedSentance += Drupal.t(' unread notifications');
}
After:
revisedSentance =
Drupal.formatPlural(
remainingCount,
'You have <span class="bg-white px-1 text-black fw-bold rounded-1 fst-italic">1</span> unread notification',
'You have <span class="bg-white px-1 text-black fw-bold rounded-1 fst-italic">@count</span> unread notifications',
);
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #6
tom kondaComment #7
tom kondaComment #8
bramdriesenI think this looks good. I just keep having "personal" issues with the span tag 😅 normally I try to keep HTML out of translatable strings. But I'm unsure how to solve it in this case.
Comment #9
tom kondaI checked existing CSS files on this module, there were no rules for the span element or it's class such as "bg-white", "px-1" and etc.
I don't know why the span tag was added on past commit, I think the span can be removed.
Comment #10
bramdriesenSounds like a solution! I also can't remember the number from looking different in the widget. Maybe it was done for easier theming. But then that should be done in the twig template I guess.
Comment #11
tom kondaI remove span tag and change issue title.
Please review.
Comment #13
bramdriesenThanks Tom!