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:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 07:36:34 +02:00
1 parent fa3eb51394
commit 9916c42484
6 files changed
+61 -16

No files matched your search

+9 -1
View File
@@ -83,6 +83,14 @@ describe('PDF roundtrip', () => {
afRelationship: AFRelationship.Data,
})
const pdfBytes = await doc.save()
await expect(importReportFromPdf(pdfBytes)).rejects.toThrow(/v1/)
try {
await importReportFromPdf(pdfBytes)
throw new Error('expected rejection')
} catch (err) {
expect(err).toBeInstanceOf(ImportError)
const e = err as ImportError
expect(e.kind).toBe('incompatible_version')
expect(e.foundVersion).toBe(1)
}
})
})