refactor: improve locale handling with regex-based region detection

Address reviewer feedback by implementing regex check to detect if locale already contains region code. This prevents invalid BCP 47 tags like "zh-CN-CN" while maintaining backward compatibility.

- Use /^[a-z]{2,3}-/i regex to detect existing region in locale
- Only append region if locale doesn't already contain it
- Centralize logic in useJellyseerr hook for DRY principle
- All 7 usage points automatically benefit from this fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zhangchuang
2025-11-18 09:44:15 +08:00
committed by Bo2
parent b630e0784b
commit 07a0a48613

View File

@@ -533,8 +533,13 @@ export const useJellyseerr = () => {
);
const jellyseerrLocale = useMemo(() => {
return jellyseerrUser?.settings?.locale || "en";
}, [jellyseerrUser]);
const locale = jellyseerrUser?.settings?.locale || "en";
// Use regex to check if locale already contains region code (e.g., zh-CN, pt-BR)
// If not, append the region to create a valid BCP 47 locale string
return /^[a-z]{2,3}-/i.test(locale)
? locale
: `${locale}-${jellyseerrRegion}`;
}, [jellyseerrUser, jellyseerrRegion]);
return {
jellyseerrApi,