#15512: fix(web-search): normalize Chinese language codes for Brave API
agents
size: S
trusted-contributor
Cluster:
Web Search Provider Enhancements
Fixes #15479
## What
Add normalization for Chinese language codes before sending to Brave API
## Why
Brave Search API requires specific enum values (`zh-hans`, `zh-hant`, `zh-CN`, `zh-TW`) but OpenClaw documentation implies generic ISO codes (`zh`) are valid. Users naturally use `zh` which causes 422 errors.
## How
- Added `normalizeBraveSearchLang()` function that maps common ISO variants to Brave-compatible enums:
- `zh` → `zh-hans` (default to simplified)
- `zh-cn` → `zh-hans`
- `zh-tw` / `zh-hk` → `zh-hant`
- Added `normalizeBraveUiLang()` function for UI language codes:
- `zh` → `zh-CN`
- `zh-cn` → `zh-CN`
- `zh-tw` → `zh-TW`
- `zh-hk` → `zh-HK`
- Applied normalization before setting URL parameters for Brave API
## Testing
- [x] Added unit tests for language normalization functions
- [x] Added integration tests verifying Chinese codes are normalized in API calls
- [x] `pnpm check` passes
- [x] `pnpm test:e2e` passes for affected files
## AI-Assisted 🤖
This PR was built with AI assistance (Claude via OpenClaw).
- [x] Code reviewed and understood
- [x] Tested locally
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change adds Brave-specific normalization for Chinese language codes before constructing the Brave Search API request URL. Two helper functions map common ISO variants (e.g., `zh`, `zh-CN`, `zh-TW`, `zh-HK`) to Brave’s expected enums for `search_lang` (`zh-hans`/`zh-hant`) and `ui_lang` (`zh-CN`/`zh-TW`/`zh-HK`).
The normalization is applied only for the Brave provider in `runWebSearch` when setting URL query parameters, and it’s surfaced via `__testing` for unit coverage. E2E tests were updated to assert the normalized parameters are present in the outgoing Brave request URL.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are small, localized to Brave request parameter construction, and covered by added unit and e2e assertions. No behavioral impact for non-Chinese language codes and no changes to authentication or network behavior beyond query param normalization.
- No files require special attention
<sub>Last reviewed commit: 722006f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19031: fix(web-search): normalize ui_lang parameter for Brave Search API
by moxunjinmu · 2026-02-17
85.2%
#18994: fix(web-search): normalize bare ui_lang codes to full Brave locales
by Phineas1500 · 2026-02-17
85.0%
#19314: feat: add Brave web_search baseUrl override (AI-assisted)
by mrutunjay-kinagi · 2026-02-17
75.1%
#19379: feat: increase Brave search MAX_SEARCH_COUNT to 20 (AI-assisted)
by liyishuai · 2026-02-17
73.4%
#19084: fix: Brave Search baseUrl and Inter-session Message Role
by jackjin1997 · 2026-02-17
73.2%
#10586: feat: Add Chinese (zh-CN) localization support
by Maxsong-0 · 2026-02-06
71.5%
#8715: fix(web-search): safer provider resolution & Perplexity auto-detection
by abhijeet117 · 2026-02-04
70.3%
#13370: Tools: rewrite Grok parser, add Tavily provider, multi-provider con...
by a-anand-91119 · 2026-02-10
70.3%
#17686: fix(memory): support non-ASCII characters in FTS query tokenization
by Phineas1500 · 2026-02-16
70.3%
#9490: Add Internationalization (i18n) Support
by luuman · 2026-02-05
69.5%