diff --git a/web/components/votes/vote-buttons.tsx b/web/components/votes/vote-buttons.tsx index dd7b3ba4..8b261b2b 100644 --- a/web/components/votes/vote-buttons.tsx +++ b/web/components/votes/vote-buttons.tsx @@ -5,6 +5,7 @@ import toast from 'react-hot-toast' import {api} from 'web/lib/api' import {useState, useEffect, useRef} from 'react' import {useUser} from "web/hooks/use-user"; +import {useT} from "web/lib/locale"; export type VoteChoice = 'for' | 'abstain' | 'against' @@ -31,10 +32,10 @@ function VoteButton(props: { } const priorities = [ - {label: 'Urgent', value: 3}, - {label: 'High', value: 2}, - {label: 'Medium', value: 1}, - {label: 'Low', value: 0}, + {key: "vote.urgent", label: 'Urgent', value: 3}, + {key: "vote.high", label: 'High', value: 2}, + {key: "vote.medium", label: 'Medium', value: 1}, + {key: "vote.low", label: 'Low', value: 0}, ] as const export function VoteButtons(props: { @@ -50,6 +51,7 @@ export function VoteButtons(props: { const [showPriority, setShowPriority] = useState(false) const containerRef = useRef(null) const disabled = disabledProp || loading !== null + const t = useT() // Close the dropdown when clicking outside or pressing Escape useEffect(() => { @@ -78,15 +80,23 @@ export function VoteButtons(props: { try { setLoading(choice) if (!user) { - toast.error('Please sign in to vote') + toast.error(t('vote.sign_in_required', 'Please sign in to vote')) return } await api('vote', {voteId, choice, priority}) - toast.success(`Voted ${choice}${choice === 'for' ? ` with priority ${priority}` : ''}`) + const choiceLabel = t( + `vote.${choice}`, + choice === 'for' ? 'For' : choice === 'abstain' ? 'Abstain' : 'Against' + ) + let votedMsg = `${t('vote.voted', 'Voted')} ${choiceLabel}` + if (choice === 'for') { + votedMsg += ` ${t('vote.with_priority', 'with priority')} ${priority}` + } + toast.success(votedMsg) await onVoted?.() } catch (e) { console.error(e) - toast.error('Failed to vote — please try again') + toast.error(t('vote.failed', 'Failed to vote — please try again')) } finally { setLoading(null) } @@ -108,7 +118,7 @@ export function VoteButtons(props: { handleVote('for')} /> @@ -129,7 +139,7 @@ export function VoteButtons(props: { await sendVote('for', p.value) }} > - {p.label} priority + {t(p.key, p.label)} ))} @@ -138,14 +148,14 @@ export function VoteButtons(props: { handleVote('abstain')} /> handleVote('against')} /> diff --git a/web/components/votes/vote-item.tsx b/web/components/votes/vote-item.tsx index eeb7729c..22d61161 100644 --- a/web/components/votes/vote-item.tsx +++ b/web/components/votes/vote-item.tsx @@ -7,6 +7,7 @@ import {VoteButtons} from 'web/components/votes/vote-buttons' import Link from "next/link"; import {STATUS_CHOICES} from "common/votes/constants"; import {useUserInStore} from "web/hooks/use-user-supabase"; +import {useT} from 'web/lib/locale' export type Vote = rowFor<'votes'> & { votes_for: number @@ -32,6 +33,7 @@ export function VoteItem(props: { onVoted?: () => void | Promise }) { const {vote, onVoted} = props + const t = useT() // console.debug('creator', creator, vote) return ( @@ -42,7 +44,7 @@ export function VoteItem(props: { - {!!vote.priority ?
Priority: {vote.priority.toFixed(0)}%
:

} + {!!vote.priority ?
{t('vote.priority', 'Priority')}: {vote.priority.toFixed(0)}%
:

} {!vote.is_anonymous && }
diff --git a/web/messages/fr.json b/web/messages/fr.json index 2642e569..a867c6a5 100644 --- a/web/messages/fr.json +++ b/web/messages/fr.json @@ -149,6 +149,18 @@ "vote.toast.create_failed": "Échec de la création de la proposition — réessayez ou contactez-nous...", "vote.toast.created": "Proposition créée", "vote.creator.placeholder": "Veuillez décrire votre proposition ici", + "vote.sign_in_required": "Veuillez vous connecter pour voter", + "vote.voted": "Vote enregistré", + "vote.with_priority": "avec priorité", + "vote.failed": "Échec du vote — veuillez réessayer", + "vote.for": "Pour", + "vote.abstain": "Abstention", + "vote.against": "Contre", + "vote.priority": "Priorité", + "vote.urgent": "Urgent", + "vote.high": "Haute", + "vote.medium": "Moyenne", + "vote.low": "Faible", "signin.seo.title": "Se connecter", "signin.seo.description": "Connectez-vous à votre compte", "signin.title": "Se connecter",