← Back to PRs

#15512: fix(web-search): normalize Chinese language codes for Brave API

by brandonwise open 2026-02-13 15:06 View on GitHub →
agents size: S trusted-contributor
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