Android – Plurals usage for seconds, minutes, hours, days

Question:

Greetings! Tell me how to use Plurals more correctly in terms of seconds, minutes, hours, days to display the time that is "left" and "passed"

<plurals name="second_plurals">
        <item quantity="zero">секунд</item>
        <item quantity="one">%1$d секунда</item>
        <item quantity="few">%1$d секунды</item>
        <item quantity="many">%1$d секунд</item>
        <item quantity="other">%1$d секунд</item>
</plurals>

zero, one, two is understandable, but for example few is as far as I understand from 2x to 5, and 5 will no longer be "seconds" and "seconds". And then – with many, for example 101 seconds, 102 seconds, … i.e. there must be rules for one, two. How to account for this difference?

Answer:

Article

zero is a string for zero, the absence of anything; in some languages ​​- also for numbers ending in zero; one – a string for numbers ending in one; in some languages ​​- only for one;

two – for numbers ending in two, or only for two;

few – here, under the word "several", specifics are no longer hidden, the processing depends entirely on the language rules; for example, for the Russian language, this refers to numbers ending in 2, 3 and 4 (just like that, despite the presence of the rule "two");

many – similarly, "non-specific" category, you can understand it as "something more few"; in Russian – from the five and above;

other – everything else.

In short, unique rules are formulated for each language separately.
At the end of the article, there is an example that should clear up all misunderstandings:

<plurals name="plurals_2">
    <item quantity="zero">нет андроидов</item>
    <item quantity="one">%1$d андроид</item>
    <item quantity="two">%1$d андроида</item>
    <item quantity="few">%1$d андроида</item>
    <item quantity="many">%1$d андроидов</item>
    <item quantity="other">%1$d андроидов</item>
</plurals>



// Выведем данные в формате: 8 = many : 8 андроидов
for (int i = 0; i < 30; i++) {
    String pluralTest = this.getResources().getQuantityString(R.plurals.plurals_1, i, i);
    String pluralAndroid = this.getResources().getQuantityString(R.plurals.plurals_2, i, i);
    android.util.Log.i("Plurals", pluralTest + " : " + pluralAndroid);
}

Result:

0 = many : 0 андроидов
1 = one : 1 андроид
2 = few : 2 андроида
3 = few : 3 андроида
4 = few : 4 андроида
5 = many : 5 андроидов
6 = many : 6 андроидов
7 = many : 7 андроидов
8 = many : 8 андроидов
9 = many : 9 андроидов
10 = many : 10 андроидов
11 = many : 11 андроидов
12 = many : 12 андроидов
13 = many : 13 андроидов
14 = many : 14 андроидов
15 = many : 15 андроидов
16 = many : 16 андроидов
17 = many : 17 андроидов
18 = many : 18 андроидов
19 = many : 19 андроидов
20 = many : 20 андроидов
21 = one : 21 андроид
22 = few : 22 андроида
23 = few : 23 андроида
24 = few : 24 андроида
25 = many : 25 андроидов
26 = many : 26 андроидов
27 = many : 27 андроидов
28 = many : 28 андроидов
29 = many : 29 андроидов

Total for the Russian language:
Zero is used for zero
For numbers ending in 1 (except for numbers ending in 11 ) use one
For numbers ending in 2 (except for numbers ending in 12 ), two are used (only in Russian, the rule few is used for these numbers)
For numbers ending in 3, 4 (except for numbers ending in 13 , 14 ), use few
For everyone else, many are used.
other is used for other cases, which are not in Russian.
Regardless, one and other are a mandatory minimum that should always be specified.

The same article describes an issue with plurals on API <3.0. There all plurals work according to the rules of the English language. The solution to this problem is also described there – to use the android-i18n-plurals library,

P. S. All of the above I took from the above article, and if

I mastered it according to this article. The question remained open

it means only one thing – poorly mastered.

Scroll to Top