From c5bcb396ff4669fe1fdb533a47f7bbe5a204d6df Mon Sep 17 00:00:00 2001 From: Safa AlFulaij Date: Tue, 23 Jan 2018 09:49:49 +0300 Subject: [PATCH] Fix some plural messages --- .../vector/activity/VectorRoomActivity.java | 10 +--- .../adapters/VectorRoomSummaryAdapter.java | 6 +- .../main/java/im/vector/util/EventGroup.java | 2 +- .../im/vector/util/NotificationUtils.java | 7 ++- .../main/java/im/vector/util/VectorUtils.java | 2 +- .../im/vector/view/ActiveWidgetsBanner.java | 2 +- vector/src/main/res/values/strings.xml | 55 +++++++++++++++---- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java index 9309e57e9f..98d5ef2639 100755 --- a/vector/src/main/java/im/vector/activity/VectorRoomActivity.java +++ b/vector/src/main/java/im/vector/activity/VectorRoomActivity.java @@ -2572,11 +2572,7 @@ public void onClick(View v) { iconId = R.drawable.newmessages; textColor = ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_fuchsia_color); - if (unreadCount == 1) { - text = new SpannableString(getResources().getString(R.string.room_new_message_notification)); - } else { - text = new SpannableString(getResources().getString(R.string.room_new_messages_notification, unreadCount)); - } + text = new SpannableString(getResources().getQuantityString(R.plurals.room_new_messages_notification, unreadCount, unreadCount)); } else { iconId = R.drawable.scrolldown; textColor = ThemeUtils.getColor(this, R.attr.room_notification_text_color); @@ -3008,9 +3004,9 @@ private void updateRoomHeaderMembersStatus() { if (joinedMembersCount == 1) { text = getResources().getString(R.string.room_title_one_member); } else if (null != sRoomPreviewData) { - text = getResources().getString(R.string.room_title_members, joinedMembersCount); + text = getResources().getQuantityString(R.plurals.room_title_members, joinedMembersCount, joinedMembersCount); } else { - text = getString(R.string.room_header_active_members, activeMembersCount, joinedMembersCount); + text = getQuantityString(R.plurals.room_header_active_members, joinedMembersCount, joinedMembersCount, activeMembersCount); } if (!TextUtils.isEmpty(text)) { diff --git a/vector/src/main/java/im/vector/adapters/VectorRoomSummaryAdapter.java b/vector/src/main/java/im/vector/adapters/VectorRoomSummaryAdapter.java index 47dedd2178..1113d84895 100644 --- a/vector/src/main/java/im/vector/adapters/VectorRoomSummaryAdapter.java +++ b/vector/src/main/java/im/vector/adapters/VectorRoomSummaryAdapter.java @@ -722,15 +722,13 @@ public View getChildView(int groupPosition, int childPosition, boolean isLastChi value = "> " + PublicRoomsManager.PUBLIC_ROOMS_LIMIT; } - roomMsgTxtView.setText(mContext.getResources().getString(R.string.directory_search_rooms_for, value, mSearchedPattern)); + roomMsgTxtView.setText(mContext.getResources().getQuantityString(R.plurals.directory_search_rooms_for, PublicRoomsManager.PUBLIC_ROOMS_LIMIT, value, mSearchedPattern)); } } else { if (null == mPublicRoomsCount) { roomMsgTxtView.setText(null); - } else if (mPublicRoomsCount > 1) { - roomMsgTxtView.setText(mContext.getResources().getString(R.string.directory_search_rooms, mPublicRoomsCount)); } else { - roomMsgTxtView.setText(mContext.getResources().getString(R.string.directory_search_room, mPublicRoomsCount)); + roomMsgTxtView.setText(mContext.getResources().getQuantityString(R.plurals.directory_search_rooms, mPublicRoomsCount, mPublicRoomsCount)); } } diff --git a/vector/src/main/java/im/vector/util/EventGroup.java b/vector/src/main/java/im/vector/util/EventGroup.java index f54d464bb3..cfb64bf776 100755 --- a/vector/src/main/java/im/vector/util/EventGroup.java +++ b/vector/src/main/java/im/vector/util/EventGroup.java @@ -279,6 +279,6 @@ public List getAvatarRows(int maxCount) { } public java.lang.String toString(Context context) { - return context.getString(R.string.membership_changes, mRowsMap.size()); + return context.getQuantityString(R.plurals.membership_changes, mRowsMap.size(), mRowsMap.size()); } } diff --git a/vector/src/main/java/im/vector/util/NotificationUtils.java b/vector/src/main/java/im/vector/util/NotificationUtils.java index 88c371bbfd..ac005e5ac6 100755 --- a/vector/src/main/java/im/vector/util/NotificationUtils.java +++ b/vector/src/main/java/im/vector/util/NotificationUtils.java @@ -466,7 +466,7 @@ private static void addTextStyleWithSeveralRooms(Context context, } } else { header = roomName + ": "; - text = context.getString(R.string.notification_unread_notified_messages, notifiedEvents.size()); + text = context.getQuantityString(R.plurals.notification_unread_notified_messages, notifiedEvents.size(), notifiedEvents.size()); } // ad the line if it makes sense @@ -490,7 +490,10 @@ private static void addTextStyleWithSeveralRooms(Context context, } inboxStyle.setBigContentTitle(context.getString(R.string.riot_app_name)); - inboxStyle.setSummaryText(context.getString(R.string.notification_unread_notified_messages_in_room, sum, roomsCount)); + + String unreadStringMessages = context.getQuantityString(R.plurals.notification_unread_notified_messages_in_room_msgs, sum, sum); + String unreadStringRooms = context.getQuantityString(R.plurals.notification_unread_notified_messages_in_room_rooms, roomsCount, roomsCount); + inboxStyle.setSummaryText(context.getString(R.string.notification_unread_notified_messages_in_room, unreadStringMessages, unreadStringRooms)); builder.setStyle(inboxStyle); TaskStackBuilder stackBuilderTap = TaskStackBuilder.create(context); diff --git a/vector/src/main/java/im/vector/util/VectorUtils.java b/vector/src/main/java/im/vector/util/VectorUtils.java index 634d60010a..e01dc4a1ae 100755 --- a/vector/src/main/java/im/vector/util/VectorUtils.java +++ b/vector/src/main/java/im/vector/util/VectorUtils.java @@ -272,7 +272,7 @@ public int compare(RoomMember m1, RoomMember m2) { displayName = context.getString(R.string.room_displayname_two_members, roomState.getMemberName(member1.getUserId()), roomState.getMemberName(member2.getUserId())); } else { RoomMember member = othersActiveMembers.get(0); - displayName = context.getString(R.string.room_displayname_more_than_two_members, roomState.getMemberName(member.getUserId()), othersActiveMembers.size() - 1); + displayName = context.getQuantityString(R.plurals.room_displayname_more_than_two_members, othersActiveMembers.size() - 1, othersActiveMembers.size() - 1, roomState.getMemberName(member.getUserId())); } return displayName; diff --git a/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java b/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java index ec61b4c8b8..2f2fece495 100755 --- a/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java +++ b/vector/src/main/java/im/vector/view/ActiveWidgetsBanner.java @@ -178,7 +178,7 @@ private void refresh() { firstWidget = mActiveWidgets.get(0); mWidgetTypeTextView.setText(firstWidget.getHumanName()); } else if (mActiveWidgets.size() > 1) { - mWidgetTypeTextView.setText(mContext.getString(R.string.active_widgets, mActiveWidgets.size())); + mWidgetTypeTextView.setText(mContext.getQuantityString(R.plurals.active_widgets, mActiveWidgets.size(), mActiveWidgets.size())); } if (null != mUpdateListener) { diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 0e37190cbf..c65b23ea75 100755 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -224,7 +224,10 @@ Read Receipts List - %d membership changes + + 1 membership change + %d membership changes + @@ -317,8 +320,14 @@ New Chat Add member - %1$d/%2$d active members - %1$d members + + %2$d/1 active members + %2$d/%d active members + + + 1 member + %d members + 1 member Warning! End-to-end encryption is in beta and may not be reliable.\n\nYou should not yet trust it to secure data.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nEncrypted messages will not be visible on clients that do not yet implement encryption. @@ -390,7 +399,10 @@ File not found You do not have permission to post to this room 1 new message - %1$d new messages + + 1 new message + %d new messages + Trust @@ -426,7 +438,10 @@ Invite from %s Room Invite %1$s and %2$s - %1$s and %2$d others + + %2$s and 1 other + %2$s and %d others + Empty room @@ -454,9 +469,15 @@ Browse directory %1$d room - %1$d rooms + + 1 room + %d rooms + %1$d room found for %2$s - %1$s rooms found for %2$s + + %1$s room found for %2$s + %1$s rooms found for %2$s + Searching directory.. @@ -752,8 +773,19 @@ All native %s rooms - %d unread notified messages - %1$d unread notified messages in %2$d rooms" + + 1 unread notified message + %d unread notified messages + + + 1 unread notified message + %d unread notified messages + + + 1 room + %d rooms + + %1$s in %2$s" Search for historical @@ -775,7 +807,10 @@ %1$s removed by %2$s Create conference calls with jitsi Are you sure you want to delete the widget? - %1$d active widgets + + 1 active widget + %d active widgets + // Widget Integration Manager You need to be able to invite users to do that.