Four-Language Coffee — i18n

Take a village roastery's shop into four languages with i18next: fallback, detection, SSR, hreflang. 14 levels, right in the browser.

What the levels ask

  1. Dadap Coffee's Japanese is only half translated, and Mrs. Sato in Osaka opens the shop today. She reads Japanese and English. Fill the hole in src/i18n.js so the lines nobody translated yet still read for her.
  2. Three buyers open the shop: Mr. Hughes (an en-GB phone), Mrs. Anneke (an nl-NL phone; she reads English too) and Mr. Faisal (an ar-SA phone). The server takes almost a second to answer for a file it lacks. Fill the hole in src/i18n.js with the languages the shop really serves.
  3. The catalog now has a file of its own, catalog.json. Card is bound to the catalog namespace, but its order button uses a line from the shop, and the Arabic catalog came flat. Fill the button's line in src/App.jsx and the key separator in src/i18n.js.
  4. After an order, the buyer is greeted by their account name: ひなた珈琲 for Mrs. Sato, Hughes & Daughters for Mr. Hughes. Each translator chose where the name goes in their sentence. Fill the escape setting in src/i18n.js and the thank-you line in src/App.jsx.
  5. Mr. Faisal's phone is in English, and he taps العربية in the shop's corner. The header, the menu and the cards switch to Arabic, but the roastery's address at the bottom has to follow too. Fill the hole in the Footer component in src/App.jsx.
  6. Arabic reads from the right. Mr. Hanif reads Mr. Faisal's screen as he switches to Arabic, to English, then to Arabic again. Fill the hole in the languageChanged handler in src/i18n.js so the html tag always knows its language and direction.
  7. Mr. Faisal's phone is in English. On day one he opens an Arabic link (/?lng=ar), on day two a bookmark, on day three he taps English, on day four the Arabic link again. Fill the detector's two holes in src/i18n.js: the order of the sources it checks and where it keeps his choice.
  8. The catalog file loads only when Mrs. Sato taps カタログ, over a second from Sukamaju to Osaka. While it travels, the shop's header and menu must stay on screen and the cards must not show key names. Fill the react setting in src/i18n.js and how Catalog is mounted in src/App.jsx.
  9. Now the shop's server renders the page with i18next-http-middleware, and the phone takes over with hydrateRoot. Mr. Faisal opens /en/ though his old cookie says Arabic. Fill the html tag's attributes in server.jsx and the detector's order in src/i18n.js.
  10. At nine in the morning three buyers open the shop at once: Mr. Faisal (/ar/), Mrs. Sato (/ja/) and Mr. Hughes (/en/). The server renders all three together, and each render waits for its catalogs. Fill the hole in server.jsx that prepares the i18next object for one request.
  11. The search engine reads the shop's four pages: /id/, /en/, /ja/ and /ar/. It has to know the four are one shop in different languages, and which page to give a reader from another country. Fill three holes in server.jsx that write the alternate links into the page's head.
  12. Pull request #31 drops COD and adds an import duties line, as an Indonesian sentence nobody has translated yet. Fill the command in .github/workflows/translations.yml and one setting in i18next-parser.config.js. CI has to go red, and name the new key and the key no longer used.

And more, 14 levels in all.