3 ms·
Fun fact - I had to localize this kind of logic to my language (Polish). I realized quickly it's fucked up. This is roughly the logic: function strFromNum
by ajuc 2y ago
Fun fact - I had to localize this kind of logic to my language (Polish). I realized quickly it's fucked up.
This is roughly the logic:
function strFromNumOfObjects(n) {
if (n === 1) {
return "obiekt";
}
let last_digit = (n%10);
let penultimate_digit = Math.trunc((n%100)/10);
if ((penultimate_digit == 0 || penultimate_digit >= 2) && last_digit > 1 && last_digit <= 4) {
return "obiekty";
}
return "obiektów";
}
Basically pluralizing words in Polish is a fizz-buzz problem :) In other Slavic languages it should be similar BTW
- morbicer 2y agoYeah, Slavic languages are hard but there is an ICU standard that's somewhat usable https://devpal.co/icu-message-editor/?data=Zarezerwowa%C5%82e%C5%9B%20%7BbookedRooms%2C%20plural%2C%0A%20%20%20%20one%7Bjeden%20obiekt%7D%0A%20%20%20%20few%7B%20obiekty%7D%0A%20%20%20%20other%7B%20obiekt%C3%B3w%7D%0A%7D https://devpal.co/icu-message-editor/?data=Zarezerwowa%C5%82...