Skip to content

feat: ship Spanish and Portuguese for every built-in code, and accept i18next's t as-is - #44

Merged
hseshadr merged 2 commits into
mainfrom
feat/i18n-messages
Oct 15, 2026
Merged

hseshadr merged 2 commits into
mainfrom
feat/i18n-messages

Conversation

@hseshadr

Copy link
Copy Markdown
Collaborator

Claim touched: "one sentence a person can read" — now in the user's language. The code and the Problem Details type stay fixed in every language.

Why

describe(code, params, t) already looks codes up in your i18next as errors.<code>, but nothing shipped in another language and the README mentioned it once, deep in "Try it". Harish read it as English-only.

What

  • locales/es.json, locales/pt.json: all 24 built-in codes (core + ai + bundle + starter), nested i18next JSON with {{name}} placeholders, exported as @gainratio/errors/locales/<lang>.json. Data only. Still zero runtime/peer dependencies (i18next is a devDependency for tests).
  • Translator type for describe's t. TFunction is unchanged and still accepted. Before this, passing i18next's own t / getFixedT() failed to type-check under exactOptionalPropertyTypes (TS2769), which is why consumers wrote adapters.
  • README: one line before "Try it", plus a "Show errors in the user's language" section. The example (examples/languages.mjs) and its pasted output are executed by test/readme.contract.test.ts against real i18next. API.md and ARCHITECTURE.md updated. CHANGELOG comes from this feat: commit via release-please.

Evidence

Check Result
pnpm gate exit 0, 337 tests, 100% statements/branches/functions/lines
Red run: delete errors.ai.provider.out_of_credits from es.json 2 failed: has a sentence for every built-in code (diff - "errors.ai.provider.out_of_credits"), describes every registered code in Spanish and Portuguese
Red run: {{field}} -> {field} in pt.json 2 failed: placeholder parity + {{name}} style
Red run: pass getFixedT without the new type pnpm typecheck TS2769 x9
Packed tarball in a fresh project node languages.mjs prints es / pt-BR / fr->en correctly; tsc --strict --exactOptionalPropertyTypes accepts describe(..., i18next.t)
Node 22.13 (engines floor) example runs

Back-compat: no existing test changed except the README contract (one new section added to the ordered list, "Try it" check generalized to two examples). English output for every call without t is unchanged.

Not done here: Spanish/Portuguese wording is not reviewed by a native speaker; a test checks keys and placeholders only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GRdR6TpVeKiz2Tr4hEGsEo

hseshadr and others added 2 commits October 15, 2026 10:59
… i18next's t as-is

describe(code, params, t) already looked each code up in your i18next as
errors.<code>, but the package shipped no translations and the README only
mentioned it in passing, so it read as English-only.

- locales/es.json and locales/pt.json: all 24 built-in codes as nested
  i18next JSON with {{name}} placeholders, exported as
  @gainratio/errors/locales/<lang>.json. Data only, no new runtime code,
  still zero dependencies.
- New Translator type for describe's t. TFunction is unchanged and still
  fits, but i18next's own t and getFixedT() now type-check without a
  wrapper under exactOptionalPropertyTypes.
- README: one line up top, and a "Show errors in the user's language"
  section whose example and output a test runs against real i18next.
- test/locales.test.ts: every code present in es and pt, placeholders
  match the English, pt-BR -> pt and unknown -> English in real i18next,
  the package exports the files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRdR6TpVeKiz2Tr4hEGsEo
Northstar punch list for #44.
- i18next HTML-escapes values by default, so "a/b" came back as
  "a&#x2F;b" in the translated sentence and the Problem Details title.
  The example and docs now set escapeValue: false; a test pins both the
  plain result and the escaped default.
- Reworded five es and six pt sentences that read as calques.
- Docs say the pt file is Brazilian Portuguese; GETTING_STARTED lists
  locales/ and the second README example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRdR6TpVeKiz2Tr4hEGsEo
@hseshadr
hseshadr merged commit df35d55 into main Oct 15, 2026
3 checks passed
@hseshadr
hseshadr deleted the feat/i18n-messages branch October 15, 2026 18:13
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.

1 participant