SurfSense/surfsense_web/components/LanguageSwitcher.tsx
Claude f536b13d13
Replace Chinese with Latvian translations and address PR review feedback
Translations:
- Add complete Latvian translations (lv.json)
- Remove Chinese translations (zh.json)
- Update i18n routing to support en/lv locales
- Update LanguageSwitcher component for Latvian
- Update LocaleContext to use Latvian messages

PR Review Improvements:
- Create shared handleSessionExpired() utility in auth-utils.ts
- Refactor use-user.ts, use-chats.ts, use-search-space.ts to use shared utility
- Add session_expired error message to auth-errors.ts
- Consistent redirect to /login?error=session_expired
2025-11-18 21:42:34 +00:00

55 lines
1.4 KiB
TypeScript

"use client";
import { Globe } from "lucide-react";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useLocaleContext } from "@/contexts/LocaleContext";
/**
* Language switcher component
* Allows users to change the application language
* Persists preference in localStorage
*/
export function LanguageSwitcher() {
const { locale, setLocale } = useLocaleContext();
// Supported languages configuration
const languages = [
{ code: "en" as const, name: "English", flag: "🇺🇸" },
{ code: "lv" as const, name: "Latviešu", flag: "🇱🇻" },
];
/**
* Handle language change
* Updates locale in context and localStorage
*/
const handleLanguageChange = (newLocale: string) => {
setLocale(newLocale as "en" | "lv");
};
return (
<Select value={locale} onValueChange={handleLanguageChange}>
<SelectTrigger className="w-[160px]">
<Globe className="mr-2 h-4 w-4" />
<SelectValue>
{languages.find((lang) => lang.code === locale)?.name || "English"}
</SelectValue>
</SelectTrigger>
<SelectContent>
{languages.map((language) => (
<SelectItem key={language.code} value={language.code}>
<span className="flex items-center gap-2">
<span>{language.flag}</span>
<span>{language.name}</span>
</span>
</SelectItem>
))}
</SelectContent>
</Select>
);
}