Skip to content

Commit bf16332

Browse files
authored
Merge pull request #13293 from TeamNewPipe/getQuantity-inconsistency
Fix inconsistency in getQuantity and add docs
2 parents 56fb31d + e22b046 commit bf16332

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/src/main/java/org/schabi/newpipe/util/Localization.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,24 @@ private static double round(final double value, final int scale) {
426426
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
427427
}
428428

429+
/**
430+
* A wrapper around {@code context.getResources().getQuantityString()} with some safeguard.
431+
*
432+
* @param context the Android context
433+
* @param pluralId the ID of the plural resource
434+
* @param zeroCaseStringId the resource ID of the string to use in case {@code count=0},
435+
* or 0 if the plural resource should be used in the zero case too
436+
* @param count the number that should be used to pick the correct plural form
437+
* @param formattedCount the formatting parameter to substitute inside the plural resource,
438+
* ideally just {@code count} converted to string
439+
* @return the formatted string with the correct pluralization
440+
*/
429441
private static String getQuantity(@NonNull final Context context,
430442
@PluralsRes final int pluralId,
431443
@StringRes final int zeroCaseStringId,
432444
final long count,
433445
final String formattedCount) {
434-
if (count == 0) {
446+
if (count == 0 && zeroCaseStringId != 0) {
435447
return context.getString(zeroCaseStringId);
436448
}
437449

0 commit comments

Comments
 (0)