Skip to content
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions app/components/landing/header/language-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@ import { Globe } from 'lucide-react'
import { useEffect, useState } from 'react'
import { useFetcher, useLoaderData } from 'react-router'
import { Button } from '~/components/ui/button'
import { type loader } from '~/root'

export default function LanguageSelector() {
const data = useLoaderData<typeof loader>()
const data = useLoaderData()
const fetcher = useFetcher()
const [locale, setLocale] = useState(data.locale || 'en')
// When loader locale changes (e.g. after login), sync state
useEffect(() => {
if (!data?.locale) return
setLocale(data.locale)
void (async () => {
try {
await i18next.changeLanguage(data.locale)
} catch (e) {
// Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler
}
await i18next.changeLanguage(data.locale)
})()
}, [data.locale])

const toggleLanguage = () => {
const newLocale = locale === 'en' ? 'de' : 'en' // Toggle between "en" and "de"
setLocale(newLocale)
Expand Down
Loading