4 ms·
I've seen some pretty wild conditional string interpolation where there were like 3-4 separate phrases that each had a number of different options, something ak
by adpirz 2y ago
I've seen some pretty wild conditional string interpolation where there were like 3-4 separate phrases that each had a number of different options, something akin to `${a ? 'You' : 'we'} {b ? 'did' : 'will do' } {c ? 'thing' : 'things' }`.
When I was first onboarding to this project, I was tasked with updating a component and simply tried to find three of the words I saw in the UI, and this was before we implemented a straightforward path-based routing system. It took me far too long just to find what I was going to be working on, and that's the day I distinctly remember learning this lesson. I was pretty junior, but I'd later return to this code and threw it all away for a number of easily greppable strings.
- ctxc 2y agoTangential: I love it when UIs say "1 object" and "2 objects". Shows attention to detail. As opposed to "1 objects" or "1 object(s)". A UI filled with "(s)", ughh
- petepete 2y agoMoreso when it's not tripped up by "1 sheeps" or "1 diagnoses".
- gnuvince 2y agoI like the more robotic "Objects: 1" or "Objects: 2", since it avoids the pluralization problems entirely (e.g., in French 0 is singular, but in English it's plural; some words have special when pluralized, such as child -> children or attorney general -> attorneys general). And related to this article, it's more greppable/awkable, e.g. `awk /^Objects:/ && $2 > 10`.
- ajuc 2y agoFun 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...
- nox101 2y agoSounds like you're going to have a bad time https://www.foo.be/docs/tpj/issues/vol4_1/tpj0401-0013.html https://www.foo.be/docs/tpj/issues/vol4_1/tpj0401-0013.html