Skip to content

Commit 43561bf

Browse files
committed
notif: Add i18n for conversation label on group DMs
This commit addresses the issue of handling plural and singular forms of the string when a group DM notification message is received. The previous implementation used a hard-coded string. Now it uses an internationalized string. Fixes: #573
1 parent 51c7b69 commit 43561bf

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

assets/l10n/app_en.arb

+8
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,13 @@
440440
"allMessagesPageTitle": "All messages",
441441
"@allMessagesPageTitle": {
442442
"description": "Title for the page of all messages"
443+
},
444+
"notifGroupDmConversationLabel": "{senderFullName} to you and {numOthers, plural, =1{1 other} other{{numOthers} others}}",
445+
"@notifGroupDmConversationLabel": {
446+
"description": "Label for a group DM conversation notification.",
447+
"placeholders": {
448+
"senderFullName": {"type": "String", "example": "Alice"},
449+
"numOthers": {"type": "int", "example": "4"}
450+
}
443451
}
444452
}

lib/notifications/display.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../api/notifications.dart';
1010
import '../host/android_notifications.dart';
1111
import '../log.dart';
1212
import '../model/binding.dart';
13+
import '../model/localizations.dart';
1314
import '../model/narrow.dart';
1415
import '../widgets/app.dart';
1516
import '../widgets/message_list.dart';
@@ -89,13 +90,15 @@ class NotificationDisplayManager {
8990

9091
static void _onMessageFcmMessage(MessageFcmMessage data, Map<String, dynamic> dataJson) {
9192
assert(debugLog('notif message content: ${data.content}'));
93+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
9294
final title = switch (data.recipient) {
9395
FcmMessageStreamRecipient(:var streamName?, :var topic) =>
9496
'$streamName > $topic',
9597
FcmMessageStreamRecipient(:var topic) =>
9698
'(unknown stream) > $topic', // TODO get stream name from data
9799
FcmMessageDmRecipient(:var allRecipientIds) when allRecipientIds.length > 2 =>
98-
'${data.senderFullName} to you and ${allRecipientIds.length - 2} others', // TODO(i18n), also plural; TODO use others' names, from data
100+
zulipLocalizations.notifGroupDmConversationLabel(
101+
data.senderFullName, allRecipientIds.length - 2), // TODO use others' names, from data
99102
FcmMessageDmRecipient() =>
100103
data.senderFullName,
101104
};

test/notifications/display_test.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,20 @@ void main() {
169169
expectedTagComponent: 'stream:${message.streamId}:${message.subject}');
170170
}));
171171

172-
test('group DM', () => awaitFakeAsync((async) async {
172+
test('group DM: 3 users', () => awaitFakeAsync((async) async {
173173
await init();
174174
final message = eg.dmMessage(from: eg.thirdUser, to: [eg.otherUser, eg.selfUser]);
175175
await checkNotifications(async, messageFcmMessage(message),
176-
expectedTitle: "${eg.thirdUser.fullName} to you and 1 others",
176+
expectedTitle: "${eg.thirdUser.fullName} to you and 1 other",
177+
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
178+
}));
179+
180+
test('group DM: more than 3 users', () => awaitFakeAsync((async) async {
181+
await init();
182+
final message = eg.dmMessage(from: eg.thirdUser,
183+
to: [eg.otherUser, eg.selfUser, eg.fourthUser]);
184+
await checkNotifications(async, messageFcmMessage(message),
185+
expectedTitle: "${eg.thirdUser.fullName} to you and 2 others",
177186
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
178187
}));
179188

0 commit comments

Comments
 (0)