feat: translate SubmitForm and StatusView with next-intl

This commit is contained in:
2026-08-10 15:35:21 +02:00
parent a89095b5c4
commit e7af883953
2 changed files with 26 additions and 26 deletions
+15 -17
View File
@@ -1,6 +1,7 @@
'use client'
import { useEffect, useState } from 'react'
import { useTranslations, useLocale } from 'next-intl'
type DownloadData = {
uuid: string
@@ -15,6 +16,8 @@ type DownloadData = {
}
export function StatusView({ uuid }: { uuid: string }) {
const t = useTranslations('status')
const locale = useLocale()
const [data, setData] = useState<DownloadData | null>(null)
const [notFound, setNotFound] = useState(false)
@@ -42,35 +45,35 @@ export function StatusView({ uuid }: { uuid: string }) {
return () => { active = false }
}, [uuid])
if (notFound) return <p>Telechargement introuvable.</p>
if (!data) return <p>Chargement...</p>
if (notFound) return <p>{t('notFound')}</p>
if (!data) return <p>{t('loading')}</p>
if (data.status === 'PENDING' || data.status === 'PROCESSING') {
return (
<div>
<p>Statut : {data.status === 'PENDING' ? 'En attente' : 'En cours...'}</p>
<p>Cette page se rafraichit automatiquement toutes les 5 secondes.</p>
<p>{data.status === 'PENDING' ? t('pending') : t('processing')}</p>
<p>{t('polling')}</p>
</div>
)
}
if (data.status === 'DONE' && data.downloadToken) {
const sizeMb = data.fileSize
? `(${(Number(data.fileSize) / 1_048_576).toFixed(1)} Mo)`
? `(${(Number(data.fileSize) / 1_048_576).toFixed(1)} MB)`
: ''
return (
<div>
<p>Telechargement pret {sizeMb}</p>
<p>{t('ready')} {sizeMb}</p>
<a
href={`/api/download/${data.downloadToken}`}
download={data.fileName ?? undefined}
>
Telecharger {data.fileName}
{t('download')} {data.fileName}
</a>
{data.tokenExpiresAt && (
<p style={{ fontSize: '0.85rem', color: '#666' }}>
Lien valable jusqu&apos;au{' '}
{new Date(data.tokenExpiresAt).toLocaleString('fr-FR')}
{t('linkExpires')}{' '}
{new Date(data.tokenExpiresAt).toLocaleString(locale)}
</p>
)}
</div>
@@ -80,7 +83,7 @@ export function StatusView({ uuid }: { uuid: string }) {
if (data.status === 'FAILED') {
return (
<div>
<p>Echec du telechargement.</p>
<p>{t('failed')}</p>
<pre style={{ background: '#fee', padding: '0.5rem', overflowX: 'auto' }}>
{data.errorMsg}
</pre>
@@ -89,13 +92,8 @@ export function StatusView({ uuid }: { uuid: string }) {
}
if (data.status === 'FILE_DELETED') {
return (
<p>
Le fichier a expire et a ete supprime. Le telechargement n&apos;est plus
disponible.
</p>
)
return <p>{t('deleted')}</p>
}
return <p>Statut inconnu : {data.status}</p>
return <p>{t('unknown')}: {data.status}</p>
}