Improve translations with pluralized string resources.

This commit is contained in:
Cody Henthorne
2024-04-30 16:04:14 -04:00
parent 8f3e62245f
commit 5d15eef61d
4 changed files with 36 additions and 15 deletions

View File

@@ -131,7 +131,7 @@ class PrivacySettingsFragment : DSLSettingsFragment(R.string.preferences__privac
clickPref(
title = DSLSettingsText.from(R.string.PrivacySettingsFragment__blocked),
summary = DSLSettingsText.from(getString(R.string.PrivacySettingsFragment__d_contacts, state.blockedCount)),
summary = DSLSettingsText.from(resources.getQuantityString(R.plurals.PrivacySettingsFragment__d_contacts, state.blockedCount, state.blockedCount)),
onClick = {
Navigation.findNavController(requireView())
.safeNavigate(R.id.action_privacySettingsFragment_to_blockedUsersActivity)

View File

@@ -11,6 +11,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
import org.thoughtcrime.securesms.R;
@@ -141,7 +142,7 @@ public class CallParticipantsListUpdatePopupWindow extends PopupWindow {
description = context.getString(getThreeMemberDescriptionResourceId(isAdded), getNextDisplayName(iterator), getNextDisplayName(iterator), getNextDisplayName(iterator));
break;
default:
description = context.getString(getManyMemberDescriptionResourceId(isAdded), getNextDisplayName(iterator), getNextDisplayName(iterator), recipients.size() - 2);
description = context.getResources().getQuantityString(getManyMemberDescriptionResourceId(isAdded), recipients.size() - 2, getNextDisplayName(iterator), getNextDisplayName(iterator), recipients.size() - 2);
}
descriptionTextView.setText(description);
@@ -181,11 +182,11 @@ public class CallParticipantsListUpdatePopupWindow extends PopupWindow {
}
}
private static @StringRes int getManyMemberDescriptionResourceId(boolean isAdded) {
private static @PluralsRes int getManyMemberDescriptionResourceId(boolean isAdded) {
if (isAdded) {
return R.string.CallParticipantsListUpdatePopupWindow__s_s_and_d_others_joined;
return R.plurals.CallParticipantsListUpdatePopupWindow__s_s_and_d_others_joined;
} else {
return R.string.CallParticipantsListUpdatePopupWindow__s_s_and_d_others_left;
return R.plurals.CallParticipantsListUpdatePopupWindow__s_s_and_d_others_left;
}
}
}

View File

@@ -38,7 +38,7 @@ public class ReviewCardDialogFragment extends FullScreenDialogFragment {
public static ReviewCardDialogFragment createForReviewRequest(@NonNull RecipientId recipientId) {
return create(R.string.ReviewCardDialogFragment__review_request,
R.string.ReviewCardDialogFragment__if_youre_not_sure,
R.plurals.ReviewCardDialogFragment__if_youre_not_sure,
R.string.ReviewCardDialogFragment__no_groups_in_common,
R.plurals.ReviewCardDialogFragment__d_groups_in_common,
recipientId,
@@ -47,7 +47,7 @@ public class ReviewCardDialogFragment extends FullScreenDialogFragment {
public static ReviewCardDialogFragment createForReviewMembers(@NonNull GroupId.V2 groupId) {
return create(R.string.ReviewCardDialogFragment__review_members,
R.string.ReviewCardDialogFragment__d_group_members_have_the_same_name,
R.plurals.ReviewCardDialogFragment__d_group_members_have_the_same_name,
R.string.ReviewCardDialogFragment__no_other_groups_in_common,
R.plurals.ReviewCardDialogFragment__d_other_groups_in_common,
null,
@@ -55,7 +55,7 @@ public class ReviewCardDialogFragment extends FullScreenDialogFragment {
}
private static ReviewCardDialogFragment create(@StringRes int titleResId,
@StringRes int descriptionResId,
@PluralsRes int descriptionResId,
@StringRes int noGroupsInCommonResId,
@PluralsRes int groupsInCommonResId,
@Nullable RecipientId recipientId,
@@ -92,7 +92,7 @@ public class ReviewCardDialogFragment extends FullScreenDialogFragment {
viewModel.getReviewCards().observe(getViewLifecycleOwner(), cards -> {
adapter.submitList(cards);
description.setText(getString(getDescriptionResId(), cards.size()));
description.setText(getResources().getQuantityString(getDescriptionResId(), cards.size(), cards.size()));
});
viewModel.getReviewEvents().observe(getViewLifecycleOwner(), this::onReviewEvent);
@@ -105,7 +105,7 @@ public class ReviewCardDialogFragment extends FullScreenDialogFragment {
viewModel = new ViewModelProvider(this, factory).get(ReviewCardViewModel.class);
}
private @StringRes int getDescriptionResId() {
private @PluralsRes int getDescriptionResId() {
return requireArguments().getInt(EXTRA_DESCRIPTION_RES_ID);
}