fix(i18n): localize PDF import error messages
Review surfaced 3 critical paths where hardcoded French leaked into
the EN UI:
- src/pdf/import.ts ImportError default message
- src/pdf/attachment.ts IncompatibleReportVersionError message
- src/app/routes/HomeRoute.tsx propagated err.message verbatim
Refactor:
- ImportError carries a typed `kind` discriminant
('invalid_pdf' | 'incompatible_version' | 'no_attachment') plus
optional `foundVersion`. Removes hardcoded localized strings.
- IncompatibleReportVersionError keeps `foundVersion` only; message
collapses to an internal sentinel.
- HomeRoute resolves the user-facing message via the active i18n
dict using `err.kind`, with `{version}` template substitution for
the incompatible-version case.
- 3 new dict keys (fr+en): home.import.error_invalid_pdf,
home.import.error_no_attachment, home.import.error_incompatible_version
- pdf.roundtrip v1 case asserts ImportError instance + kind +
foundVersion instead of grepping the message text.
154/154 tests pass, lint clean, typecheck clean, build OK.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa3eb51394
commit
9916c42484
6 files changed
+61
-16
No files matched your search
@@ -29,7 +29,22 @@ export default function HomeRoute() {
|
||||
hydrate(report)
|
||||
navigate('/editor')
|
||||
} catch (err) {
|
||||
setError(err instanceof ImportError ? err.message : t('home.import.error_generic'))
|
||||
if (err instanceof ImportError) {
|
||||
if (err.kind === 'incompatible_version') {
|
||||
setError(
|
||||
t('home.import.error_incompatible_version').replace(
|
||||
'{version}',
|
||||
String(err.foundVersion ?? '?'),
|
||||
),
|
||||
)
|
||||
} else if (err.kind === 'invalid_pdf') {
|
||||
setError(t('home.import.error_invalid_pdf'))
|
||||
} else {
|
||||
setError(t('home.import.error_no_attachment'))
|
||||
}
|
||||
} else {
|
||||
setError(t('home.import.error_generic'))
|
||||
}
|
||||
} finally {
|
||||
setBusy(false)
|
||||
if (fileRef.current) fileRef.current.value = ''
|
||||
|
||||
Reference in new issue
Block a user