Hello World

Messages that change shape

All chapters

Part 2 · Words

Messages that change shape

Chapter 7 13 min read 8 sections

Every English-speaking developer has written this line at some point:

const label = count === 1 ? `${count} file` : `${count} files`
$label = $count === 1 ? "{$count} file" : "{$count} files";

It works in English. Now hand it to a Polish translator. Polish has three forms of "file" that matter here: 1 plik, 2 pliki, 5 plików. Your ternary only has room for two. Whichever two forms the translator picks, a Polish user will see broken grammar somewhere between 2 and 24 files.

<title id="g1-title">Polish message counts with two forms and with plural rules</title> A Polish notification list built with an English-style ternary uses one form for everything but 1, so 2 and 22 messages come out ungrammatical. With Polish plural rules, 2 and 22 take nowe wiadomości (few) and 5 takes nowych wiadomości (many). TWO FORMS count === 1 ? one : otherPowiadomieniaMasz 1 nową wiadomośćMasz 2 nowych wiadomościMasz 5 nowych wiadomościMasz 22 nowych wiadomości 2–4 and 22–24 need "nowe" PLURAL RULES {count, plural, one {…} few {…} many {…}}PowiadomieniaMasz 1 nową wiadomośćoneMasz 2 nowe wiadomościfewMasz 5 nowych wiadomościmanyMasz 22 nowe wiadomościfew

The problem isn't the Polish translation. The problem is that the code decided how the sentence works before the translator ever saw it. This chapter is about giving that decision back to the people who know the language.

Keep reading

The rest of this chapter is for readers of the book

Get the book to read the rest of this chapter and every other one, the field guide and the glossary, and to download the whole book as a PDF.

Still to come in this chapter

  • Interpolate, don't concatenate
  • Plurals
  • Gender
  • ICU MessageFormat
  • Project Fluent
  • Relative time
  • Checklist
  • Further reading