mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-16 09:23:07 +01:00
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:
@@ -533,8 +533,13 @@ export const useJellyseerr = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const jellyseerrLocale = useMemo(() => {
|
const jellyseerrLocale = useMemo(() => {
|
||||||
return jellyseerrUser?.settings?.locale || "en";
|
const locale = jellyseerrUser?.settings?.locale || "en";
|
||||||
}, [jellyseerrUser]);
|
// 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 {
|
return {
|
||||||
jellyseerrApi,
|
jellyseerrApi,
|
||||||
|
|||||||
Reference in New Issue
Block a user