diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 49e27d108..23dd6b2c7 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -426,12 +426,24 @@ public final class Localization { return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue(); } + /** + * A wrapper around {@code context.getResources().getQuantityString()} with some safeguard. + * + * @param context the Android context + * @param pluralId the ID of the plural resource + * @param zeroCaseStringId the resource ID of the string to use in case {@code count=0}, + * or 0 if the plural resource should be used in the zero case too + * @param count the number that should be used to pick the correct plural form + * @param formattedCount the formatting parameter to substitute inside the plural resource, + * ideally just {@code count} converted to string + * @return the formatted string with the correct pluralization + */ private static String getQuantity(@NonNull final Context context, @PluralsRes final int pluralId, @StringRes final int zeroCaseStringId, final long count, final String formattedCount) { - if (count == 0) { + if (count == 0 && zeroCaseStringId != 0) { return context.getString(zeroCaseStringId); }