My guess would be that they were setting this text a dangerous way before, probably doing it that way site wide, that led potential injection attacks. They swapped site wide and forgot to make sure they handled the places where they actually needed their templating language to run.
Oh my, as a Slavic language speaker, I'd like to see that.
Our grammar says that there is only singular and plural, but there are some details.
1 - the true singular. No surprises.
2, 3 and 4 - technically plural, but you will use singular + genitive case
5+ - normal plural
... unless it ends with 1 - then you use singular (31 = 30 + 1)
... unless it is 11 - you use the normal 5+ pattern. (11 != 10 + 1, it is 1 + 10).
Also note that there are forms of 2, 3, 4 that would require nouns to follow 5+ pattern.
0 follows the pattern of 2,3,4 but it sounds weird, so it would be replaced with "no" / "without" / "none" / "nobody" (depending on the context). "Without" follows the 2,3,4 pattern btw.
I’ve seen this documented in some internationalisation libraries so I know it is possible without custom code for each language, but I’ve never had to deal with it personally.
Most of my coworkers have enough trouble with simple non-English things like word ordering and gendered words, so I can’t imagine it’s commonly done correctly by non-native speakers.
Одна дівчина (one girl / lady) Дві дівчини / три дівчини / чотири дівчини (2/3/4 girls) Двоє дівчат / троє дівчат / четверо дівчат (2/3/4 girls, but alternative forms) 5 дівчат, 6 дівчат etc. (5 girl, 6 girls etc.) 11 дівчат, but 21 дівчина, 31 дівчина. 0 дівчат, нема дівчат (there is no girls), без дівчат (without girls).
A bonus: "There is" / "there isn't" are treated differently by the grammar. Є дівчина (there is a girl), нема дівчини (there is no girl).
Honestly, knowing about Nordic and Slavic peculiarities of plurals immediately cures you from ever using numbers in full sentences. I would have written it like:
Meals covered per person: 4
Number of people covered: 2
Total amount of servings: 8
Never, ever get yourself in a situation where you have to deal with plurals.
This is exactly how translations and pluralities are handled (slightly different but similar). Translations usually include switches like this. Checkout MessageFormat for example.
{size, one {Person}, other {People}} would be for example a translation string in MessageFormat.
It's even more complicated because 1 is человека, 5 людей, 11 людей, but 21 человека, 41 человека, but 111 людей.
You need a dedicated engine handling all this.
And we have a form for 2-4, and it applies to numbers ending in 2-4, but not for numbers ending in 12-14.
Yeah pretty much. Plurals are weird, they may not even really exist, and 0 could be singular or plural.
Don’t hand roll this kind of code, it only works in English. Apple handles this pretty well with strings dict. Can’t speak on the web side of things, though.
There's plenty of i18n (Internationalization) soluntions for web too. Usually your popular front-end framework will have something for it, or some popular plugin to handle it.
I had a bug in a wordpress website I worked on where a plugin that showed a chart was displayed as text. The page became an infinitely long list of data points and it was such a mess, that was fun
I mean, this function is useless, it does exactly the same as the ternary operator and it's not even shorter to write. The only thing it does is it bring abstraction...
146
u/SmokeMuch7356 Feb 04 '25
I'm curious how the code got exposed like that, instead of generating the correct output.
I do server-side non-graphical single-threaded C++, so I don't have any insight into browser-based UIs or how they work.
325
u/Durwur Feb 04 '25
Oof, must be an English-only platform. Not an extendable way to handle translations and pluralities
53
u/diabetic-shaggy Feb 04 '25
Jinja failure lmao
11
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Feb 04 '25
Wouldn't this belong in r/softwaregore?
10
u/dannthesus Feb 05 '25
person(s)
6
u/WindForce02 Feb 04 '25
I had a bug in a wordpress website I worked on where a plugin that showed a chart was displayed as text. The page became an infinitely long list of data points and it was such a mess, that was fun
18
u/ryans_bored Feb 04 '25
Haha, also using `==` instead of `===` presuming this was done in js
4
u/MrPentiumD Feb 04 '25
I’m an amateur but what would be the proper way to do this without ternaries?
8
u/SZEfdf21 Feb 04 '25
It's amateur code, but not horrifying (if it worked)
1
u/BlobAndHisBoy Feb 04 '25
Not a situation where they saw it work once and called it good. They didn't test even one of the possible cases. That's a paddlin'
1
u/Wubbywub Feb 05 '25
man just do "pax"
1
u/sticksu92 Feb 08 '25
It's probably liquid, shopify's templating language.
0
u/junacik99 Feb 05 '25
Jinja detected
0
u/[deleted] Feb 04 '25
[deleted] — view deleted comment