By Adam Podstawczyński. Please feel free to copy and distribute this material. Please retain author information.

Why your $variable will not work in Polish

Illustrated version, cool but not easy on the eyes ----->

Plain version, easy on the eyes but uncool |

You are a programmer or content author, and naturally you want to use variables to make content dynamic, customizable. You substitute certain keywords such as product names with variables so that your company can introduce a new product later without changing the code. You think that the sentence Our $product was the best-selling snack in $year is a convenient solution, because your company's snacks always sell best in a given year; it's just that they are not always the same snacks. That's OK, because all you have to do next year is change the definition of $product from white chocolate to raspberry lollipop, and leave the rest, i.e. $year++, to the code. Done! Obviously, the same code localized to 20 languages will work too. In the end, we have all our product definitions translated ($product = "biała czekolada" will simply change to $product = "lizak malinowy"), so it must work.

But it won't.

The reason is that language is not Lego blocks. When you substitute a word with another one in an English sentence, you may visualize substituting a white block in your Lego castle with a red block of the same size. But trying to apply the same logic to other languages is like trying to substitute that white Lego block with a living giant tiger prawn. The poor crustacean will wriggle, it won't feel good at all in the squarish surroundings, and it won't fit in.

Nasza biała czekolada była najlepiej sprzedającym się przysmakiem roku 2012.

Nasza lizak malinowy była najlepiej sprzedającym się przysmakiem roku 2013.

Polish grammar distinguishes between genders, it has at least 3 of them (yes!), and they affect, among other things, pronouns and verbs. So when the gender of $product changes, in Polish both our and was will change too. "That's a funny language!," you must be thinking now "but I'm a programmer so I can work around that!." Of course, you can. You can ask the translator to specify $gender for each localized $product and write 

switch ($gender) {	
	case "masculine"	{ $our = "Nasz"  ; $was = "był"  }
	case "feminine"		{ $our = "Nasza" ; $was = "była" }
	case "neutral"		{ $our = "Nasze" ; $was = "było" }

And it will work... sort of. More precisely, it will work only if the $product is in Nominative position in a sentence. Polish declines words by cases as well as by gender. So while $our $product is delicious will sound OK providing the translator defines $gender correctly, a sentence like Łukasz is a big fan of $product will not, because $product is in Genitive case here instead of Nominative. We have several cases for singulars and several for plurals, so depending on where white chocolate occurs in the sentence, it can become biała czekolada, białej czekolady, białej czekoladzie, białą czekoladę, białą czekoladą, biała czekolado, białe czekolady, białych czekolad, białym czekoladom, białymi czekoladami, białych czekoladach. And defining several variables such as $product_in_Nominative, $product_in_Locative, etc. won't help, because the declensions affect neighboring words (such as adjectives and numerals) too. And good luck automating the rules for declined suffixes: they differ depending on many aspects of a noun, including gender, animacy, and more.

"All right, all right, I see your point, I'm not gonna use variables in sentences," I hear you saying now. "But it sure can't do any harm to substitute only numbers with variables? Nothing can go wrong, can it?"

Well, it can.

Polish, similarly to some other Slavic languages, has more than one plural form. So while if ($number == 1) {$product = "prawn"} else {$product = "prawns"} might work for you, it will not work in Polish, because we have 1 krewetka, 2 krewetki but 5 krewetek. And the pattern reiterates, alternating between the two plurals above 21, so we say 23 or 144 krewetki but 76 or 1538 krewetek. And this is only for standalone expressions of $number $product format which can be solved by an algorithm if you want to do that. But don't try to build sentences out of it, because multiple plurals combine with genders and with cases, and will influence -- and be influenced by -- the surrounding words. 

"That's just plain crazy," you must be thinking now. But this is just how languages, not only Polish, work. They are much less predictable than we would wish them to be, and this is what makes them so interesting. 

Just don't use variables in text localizable to any language without thinking of a giant tiger prawn trying to wriggle out of a Lego wall.