Skip to content

Add UI translations (i18n) with English and Spanish - #256

Open
ufortstephen wants to merge 1 commit into
DhanushNehru:mainfrom
ufortstephen:i18n-spanish
Open

ufortstephen wants to merge 1 commit into
DhanushNehru:mainfrom
ufortstephen:i18n-spanish

Conversation

@ufortstephen

@ufortstephen ufortstephen commented Nov 11, 2026 •

Copy link
Copy Markdown

Part of #247 (the i18n layer with English and Spanish. Hindi and Tamil will follow in separate PRs, so the issue can stay open.)

PR Fixes:

  • i18n layer: react-i18next, set up in src/i18n.js. Messages are JSON files in src/locales/ (en.json, es.json) and ship with the bundle, so nothing extra is fetched.
  • Strings moved to keys: the editor (buttons, settings, output panel, snackbar messages), the header, the sign-in buttons and their alerts in AuthContext, the stars prompt, both selects, the dark-mode toggle label and the footer. Theme names in constants.js and the people's names in the footer stay as they are.
  • Language switcher: a button in the header next to the theme toggle (globe icon, language name, menu with a check on the current one). Each language is listed by its own name, and on narrow screens the button shows just the code (EN/ES). The choice is saved in localStorage (uiLanguage). With no saved choice it uses the browser language, and regional variants work too (es-MX gets Spanish). <html lang> follows the active language.
  • Fallback: a key missing from a language shows the English text.
  • CONTRIBUTING.md: new "How to add a language" section.
  • Tests: src/i18n.test.js covers the English default, switching to Spanish, falling back to English for a missing key, and checks that es.json has no keys en.json lacks. setupTests.js loads i18n so the existing tests run in English and pass unchanged.

⚠️ Spanish translations are drafts

es.json was drafted with localize.dev, which I'm building, and I corrected a few things by hand: sentence case, "lenguaje" rather than "idioma" for the programming-language select, shorter select labels so they fit the 150px fields, and the product name left untranslated. It hasn't been reviewed by a native speaker yet, so please don't merge until a fluent Spanish speaker has reviewed src/locales/es.json. Suggestions on the file are welcome.

English output

Every English string is the same text as before, with two small differences:

  • The star count uses i18next plurals, so a count of 0 reads "0 stars" instead of "0 star". It only shows for a moment before the count loads.
  • If the stars request fails with a network error, the message is now always "Unable to retrieve repository stars. Please try again later." Before, it showed the browser's raw error ("Failed to fetch").

Dependencies

i18next@23, react-i18next@14 and i18next-browser-languagedetector@8. Newer i18next majors declare a TypeScript 5 peer, which conflicts with the TypeScript 4.9 that react-scripts 5 installs. These versions avoid that, so npm ci keeps working without --legacy-peer-deps.

Checklist before requesting a review

  • I have pull latest changes from main branch
  • I have tested the changes locally
  • I have run npm run lint:fix locally
  • I have performed a self-review of my code
  • I assure there is no similar/duplicate pull request regarding same issue

Tested: npm run lint is clean, npm test passes (29 tests), npm run build succeeds, and I went through the signed-out page and the editor in English and Spanish in the browser (switching languages, settings, import/export, output panel).

@vercel

vercel Bot commented Nov 11, 2026

Copy link
Copy Markdown

@ufortstephen is attempting to deploy a commit to the Dhanush Nehru's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sets up react-i18next with JSON messages in src/locales/ and moves the
editor, header, sign-in, stars and footer text to translation keys.
Adds a language switcher in the header that saves the choice in
localStorage and otherwise follows the browser language. Missing keys
fall back to English. The Spanish messages are drafts awaiting review
by a fluent speaker.

Adds a "How to add a language" section to CONTRIBUTING.md.

Part of DhanushNehru#247
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
custom-code-editor Ready Ready Preview Nov 11, 2026 10:15am UTC

@DhanushNehru

Copy link
Copy Markdown
Owner

Thanks, the code, tests and preview check out. Before merging, src/locales/es.json still needs review from a fluent Spanish speaker, as agreed in #247. Please leave any corrections directly on that file and confirm when the Spanish review is complete.

This branch was successfully deployed

1 active deployment
Preview — 92a10a01 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants