[PR #7430] [MERGED] fix(i18n): validate defaultLocale exists in translations #24208

Closed
opened 2026-04-15 22:14:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: himself65/2026/01/16/i18nHead: copilot/sub-pr-7428


📝 Commits (3)

  • f2a0b48 Initial plan
  • 33b1e2b fix: validate defaultLocale exists in translations or use fallback
  • 44ab137 chore: remove unnecessary comment

📊 Changes

2 files changed (+128 additions, -3 deletions)

View changed files

📝 packages/i18n/src/i18n.test.ts (+109 -0)
📝 packages/i18n/src/index.ts (+19 -3)

📄 Description

  • Fix hardcoded defaultLocale to validate it exists in translations
  • Use first available locale as fallback if defaultLocale not provided or doesn't exist
  • Add tests for edge cases (no "en" locale, empty translations)
  • Validate changes with existing tests
  • Remove unnecessary comment per review feedback

Changes Made

The defaultLocale was hardcoded to "en" which could cause issues if users provide translations without an "en" key. The fix implements the following logic:

  1. If defaultLocale is provided and exists in translations → use it
  2. Else if "en" exists in translations → use "en"
  3. Else if any locale exists → use the first available locale
  4. Otherwise → throw an error (empty translations)

Added comprehensive tests to cover all scenarios including edge cases where "en" is not provided.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Summary by cubic

Addresses review feedback on the i18n plugin from PR #7428 by refining the plugin API and locale fallback behavior, tightening types, and adding missing tests to improve clarity and safety.

Written for commit 44ab13705b. 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/7430 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/16/2026 **Status:** ✅ Merged **Merged:** 1/17/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `himself65/2026/01/16/i18n` ← **Head:** `copilot/sub-pr-7428` --- ### 📝 Commits (3) - [`f2a0b48`](https://github.com/better-auth/better-auth/commit/f2a0b48812cb2c6910cfdd07a8963c085c20967c) Initial plan - [`33b1e2b`](https://github.com/better-auth/better-auth/commit/33b1e2bb835aa79c021979d94a517904ad1b3f70) fix: validate defaultLocale exists in translations or use fallback - [`44ab137`](https://github.com/better-auth/better-auth/commit/44ab13705bf3903c1a9586545521d5817fa974c6) chore: remove unnecessary comment ### 📊 Changes **2 files changed** (+128 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/i18n/src/i18n.test.ts` (+109 -0) 📝 `packages/i18n/src/index.ts` (+19 -3) </details> ### 📄 Description - [x] Fix hardcoded defaultLocale to validate it exists in translations - [x] Use first available locale as fallback if defaultLocale not provided or doesn't exist - [x] Add tests for edge cases (no "en" locale, empty translations) - [x] Validate changes with existing tests - [x] Remove unnecessary comment per review feedback ## Changes Made The `defaultLocale` was hardcoded to "en" which could cause issues if users provide translations without an "en" key. The fix implements the following logic: 1. If `defaultLocale` is provided and exists in translations → use it 2. Else if "en" exists in translations → use "en" 3. Else if any locale exists → use the first available locale 4. Otherwise → throw an error (empty translations) Added comprehensive tests to cover all scenarios including edge cases where "en" is not provided. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Addresses review feedback on the i18n plugin from PR #7428 by refining the plugin API and locale fallback behavior, tightening types, and adding missing tests to improve clarity and safety. <sup>Written for commit 44ab13705bf3903c1a9586545521d5817fa974c6. 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-04-15 22:14:05 -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#24208