-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_switch.tsx
61 lines (54 loc) · 1.55 KB
/
language_switch.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useForm, usePage } from '@inertiajs/react'
import i18next from 'i18next'
import { Select } from '#containers/ui/select'
import { tuyau } from '#resources/core/tuyau'
import { Loader } from '#components/ui/loader'
export function LanguageSwitch() {
const {
props: { locale },
} = usePage()
const { data, setData, errors, processing, post } = useForm({
language: locale,
})
function handleChange() {
if (processing) return
post(tuyau.$url('language.update', { params: { locale: data.language as string } }))
i18next.changeLanguage(data.language as string)
document.documentElement.setAttribute('lang', data.language as string)
}
if (processing)
return (
<div className="flex items-center justify-center min-w-[140px]">
<Loader />
</div>
)
return (
<form onChange={handleChange}>
<Select
hideSelected
className="min-w-[140px]"
name="language"
options={[
{
label: (
<span className="inline-flex items-center mt-1">
🇬🇧 <span className="ml-2 font-medium mb-1">English</span>
</span>
),
value: 'en',
},
{
label: (
<span className="inline-flex items-center mt-1">
🇫🇷 <span className="ml-2 font-medium mb-1">Français</span>
</span>
),
value: 'fr',
},
]}
disabled={processing}
{...{ data, setData, errors }}
/>
</form>
)
}