[PR #7428] [MERGED] feat: i18n plugin #7305

Closed
opened 2026-03-13 13:31:24 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7428
Author: @himself65
Created: 1/16/2026
Status: Merged
Merged: 1/21/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/16/i18n


📝 Commits (2)

📊 Changes

13 files changed (+988 additions, -4 deletions)

View changed files

📝 .cspell/alt-languages.txt (+9 -1)
📝 docs/components/sidebar-content.tsx (+17 -0)
docs/content/docs/plugins/i18n.mdx (+219 -0)
packages/i18n/package.json (+69 -0)
packages/i18n/src/client.ts (+26 -0)
packages/i18n/src/i18n.test.ts (+348 -0)
packages/i18n/src/index.ts (+195 -0)
packages/i18n/src/types.ts (+67 -0)
packages/i18n/tsconfig.json (+8 -0)
packages/i18n/tsdown.config.ts (+9 -0)
packages/i18n/vitest.config.ts (+3 -0)
📝 pnpm-lock.yaml (+15 -3)
📝 tsconfig.json (+3 -0)

📄 Description

Summary by cubic

Add an i18n plugin to translate Better Auth error messages based on user locale. Includes configurable locale detection, a client plugin for type inference, docs, and tests.

  • New Features

    • Translates API error messages using provided dictionaries; keeps originalMessage.
    • Configurable detection order: header, cookie, session, callback (parses Accept-Language with quality and base locale; cookie detection uses parseCookies).
    • Validates defaultLocale; falls back to "en" or first available; throws when translations are empty.
    • Supports custom getLocale, cookie name, and user session field.
    • Adds i18nClient for type inference; non-error responses are unchanged.
    • Documentation and comprehensive tests included.
  • Migration

    • Install @better-auth/i18n and add i18n({ translations, defaultLocale, detection }) to your auth config.
    • Provide non-English translations; English is already built in.
    • Optionally configure localeCookie, userLocaleField, and getLocale callback.
    • Ensure defaultLocale exists in translations or rely on fallback.

Written for commit 949baed078. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7428 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/16/2026 **Status:** ✅ Merged **Merged:** 1/21/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/16/i18n` --- ### 📝 Commits (2) - [`f07874d`](https://github.com/better-auth/better-auth/commit/f07874dd18c4c8b8106016b66b7bd70c3f312ace) feat: i18n plugin - [`949baed`](https://github.com/better-auth/better-auth/commit/949baed07843da30f01c672e400a921af0c63977) chore: fix doc ### 📊 Changes **13 files changed** (+988 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `.cspell/alt-languages.txt` (+9 -1) 📝 `docs/components/sidebar-content.tsx` (+17 -0) ➕ `docs/content/docs/plugins/i18n.mdx` (+219 -0) ➕ `packages/i18n/package.json` (+69 -0) ➕ `packages/i18n/src/client.ts` (+26 -0) ➕ `packages/i18n/src/i18n.test.ts` (+348 -0) ➕ `packages/i18n/src/index.ts` (+195 -0) ➕ `packages/i18n/src/types.ts` (+67 -0) ➕ `packages/i18n/tsconfig.json` (+8 -0) ➕ `packages/i18n/tsdown.config.ts` (+9 -0) ➕ `packages/i18n/vitest.config.ts` (+3 -0) 📝 `pnpm-lock.yaml` (+15 -3) 📝 `tsconfig.json` (+3 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Add an i18n plugin to translate Better Auth error messages based on user locale. Includes configurable locale detection, a client plugin for type inference, docs, and tests. - **New Features** - Translates API error messages using provided dictionaries; keeps originalMessage. - Configurable detection order: header, cookie, session, callback (parses Accept-Language with quality and base locale; cookie detection uses parseCookies). - Validates defaultLocale; falls back to "en" or first available; throws when translations are empty. - Supports custom getLocale, cookie name, and user session field. - Adds i18nClient for type inference; non-error responses are unchanged. - Documentation and comprehensive tests included. - **Migration** - Install @better-auth/i18n and add i18n({ translations, defaultLocale, detection }) to your auth config. - Provide non-English translations; English is already built in. - Optionally configure localeCookie, userLocaleField, and getLocale callback. - Ensure defaultLocale exists in translations or rely on fallback. <sup>Written for commit 949baed07843da30f01c672e400a921af0c63977. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:31:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7305