Translations
Translations move every word on the page into locale files, one per language, in app/locales/. A template reads them by key with t():
<a href={ link('/') }>{ t('nav.shop') }</a>
Nested keys flatten to dots, so { "nav": { "shop": "Shop" } } is nav.shop. puzzle.config.js turns translations on and lists the languages. A visitor starts in the language they last picked, else their browser's language if the app has it, else defaultLocale. A key a locale leaves out falls back to the default locale's text, so a half-done translation still renders.
Plurals. An entry whose keys are plural forms (zero, one, two, few, many, other) picks a form from a count:
{ t('playlist.count', { count: albums.length }) }
{count} inside the text prints the number. The form comes from the language's own rules: English has one and other, French counts 0 as singular too, and Polish needs few and many as well. A zero form, when the entry has one, wins for an exact 0 in every language. That is why pluralize() from the last lesson is for apps in English only: it adds an English s. In a translated app, counts go through t().
Music is now set up with English: the header reads its links from en.json, and the language switcher beside it lists the configured locales. fr.json has been started.
Your turn
- In
puzzle.config.js, add'fr'tolocales. A Français button appears in the header. - Click it. The shop link is French, the rest falls back to English.
- Finish
fr.json: translatenav.playlistandplaylist.title, and add the pluralplaylist.countwithzero,oneandotherforms (Aucun album pour l'instant,{count} album,{count} albums). - In
Playlist.pzl, swappluralize()fort('playlist.count', { count: albums.length }), then try the playlist empty and full, in both languages.
Switching language rebuilds the page in place. Store records survive it, so the playlist keeps its albums.