feat(i18n): add fr/en dicts + useT hook

This commit is contained in:
Bastien Chanot committed 2026-05-20 07:00:31 +02:00
1 parent a57047505d
commit 359104ce88
6 files changed
+358

No files matched your search

+135
View File
@@ -0,0 +1,135 @@
import type { Dict } from './types'
export const en: Dict = {
'common.cancel': 'Cancel',
'common.save': 'Save',
'common.confirm': 'Confirm',
'common.delete': 'Delete',
'common.add': 'Add',
'common.back': 'Back',
'common.home': 'Home',
'common.understood': 'Got it',
'common.collapse': 'Collapse',
'common.expand': 'Expand',
'common.move_up': 'Move up',
'common.move_down': 'Move down',
'common.none': 'None',
'common.back_to_home': 'Back to home',
'home.new_report.title': 'New report',
'home.new_report.description': 'Start a new osteopathic report for an animal.',
'home.new_report.cta': 'Start',
'home.import.title': 'Import a PDF',
'home.import.description': 'Reopen a previous report generated by this app to follow up.',
'home.import.cta': 'Choose a PDF',
'home.import.loading': 'Reading…',
'home.import.error_generic': 'Failed to read the PDF.',
'not_found.title': 'Page not found',
'not_found.description': 'The requested path does not exist.',
'new_report.title': 'New report',
'new_report.date_label': 'Report date',
'new_report.submit': 'Start the report',
'editor.export': 'Export as PDF',
'editor.exporting': 'Generating…',
'editor.export_failed': 'PDF generation failed. Retry or contact support.',
'editor.edit_infos': 'Edit info',
'editor.edit_dialog_title': 'Edit information',
'editor.disclaimer_title': 'Legal scope of animal osteopathy',
'observation.section_title': 'Observations',
'observation.add': '+ New observation',
'observation.empty': 'No observation. Click "+ New observation" then on the zones in the diagram.',
'observation.badge_n': 'Observation #',
'observation.zone_label_singular': 'zone',
'observation.zone_label_plural': 'zones',
'observation.finding_label_singular': 'finding',
'observation.finding_label_plural': 'findings',
'observation.zones_label': 'Selected zones',
'observation.zones_empty': 'Click on the zones in the diagram to add them to this observation.',
'observation.findings_catalog_label': 'Findings (catalog)',
'observation.findings_pick_zone_first': 'Pick a zone to access the catalog.',
'observation.findings_no_catalog':
'No catalog available for these zones. Use the free text below.',
'observation.findings_free_label': 'Findings (free text)',
'observation.free_placeholder': 'Additional observation (free text)',
'observation.free_aria': 'Free observation',
'observation.severity_label': 'Severity',
'observation.comment_label': 'Comment',
'observation.comment_placeholder': 'Detailed clinical notes…',
'observation.vertebrae_button': 'Vertebrae…',
'observation.vertebrae_button_title': 'Specify vertebrae for this zone',
'observation.remove_zone': 'Remove',
'observation.expand_aria': 'Expand observation',
'observation.collapse_aria': 'Collapse observation',
'findings.back_to_parent': 'Back to previous level',
'findings.back': '← Back',
'findings.no_options': 'No option available at this level.',
'findings.open': 'Open',
'findings.vet_referral': 'Refer to a veterinarian',
'findings.selected_singular': 'finding selected',
'findings.selected_plural': 'findings selected',
'form.practitioner.legend': 'Practitioner',
'form.practitioner.name': 'Full name *',
'form.practitioner.cabinet': 'Practice / clinic',
'form.practitioner.contact': 'Contact (phone, email…)',
'form.practitioner.siret': 'SIRET',
'form.animal.legend': 'Animal & owner',
'form.animal.species': 'Species *',
'form.animal.name': 'Animal name *',
'form.animal.breed': 'Breed',
'form.animal.age': 'Age',
'form.owner.name': 'Owner name *',
'conclusion.section_title': 'Conclusion & recommendations',
'conclusion.conclusion': 'Conclusion',
'conclusion.recommendations': 'Recommendations',
'conclusion.next_appointment': 'Next appointment',
'conclusion.next_kind_date': 'Date',
'conclusion.next_kind_period': 'Free period',
'conclusion.next_kind_none': 'None',
'conclusion.next_period_placeholder': 'e.g. in 3 weeks',
'vertebra.title_prefix': 'Specify vertebrae — ',
'vertebra.region.C': 'Cervical',
'vertebra.region.T': 'Thoracic',
'vertebra.region.L': 'Lumbar',
'vertebra.region.S': 'Sacral',
'vertebra.region.Cd': 'Caudal',
'vertebra.check_all': 'Select all',
'vertebra.uncheck_all': 'Clear all',
'severity.aria': 'Severity',
'severity.légère': 'mild',
'severity.modérée': 'moderate',
'severity.sévère': 'severe',
'pdf.eyebrow.observation': 'OBSERVATION',
'pdf.eyebrow.synthesis': 'SYNTHESIS',
'pdf.title.conclusion': 'Conclusion',
'pdf.section.zones': 'ZONES',
'pdf.section.findings_prefix': 'FINDINGS — ',
'pdf.section.free_findings': 'FREE FINDINGS',
'pdf.section.severity': 'SEVERITY',
'pdf.section.comment': 'COMMENT',
'pdf.section.conclusion': 'CONCLUSION',
'pdf.section.recommendations': 'RECOMMENDATIONS',
'pdf.section.next_appointment': 'NEXT APPOINTMENT',
'pdf.view.general': 'GENERAL VIEW',
'pdf.view.detail_prefix': 'DETAIL VIEW — ',
'pdf.empty': '—',
'pdf.owner_prefix': 'Owner: ',
'pdf.siret_prefix': 'SIRET ',
'pdf.export_date_prefix': 'Exported on ',
'pdf.title.suffix.bilan': 'Osteo report — ',
'pdf.subject': 'Animal osteopathic report',
'lang.switch_to_fr': 'Passer en français',
'lang.switch_to_en': 'Switch to English',
'lang.fr': 'FR',
'lang.en': 'EN',
}
+150
View File
@@ -0,0 +1,150 @@
import type { Dict } from './types'
export const fr: Dict = {
// common
'common.cancel': 'Annuler',
'common.save': 'Enregistrer',
'common.confirm': 'Valider',
'common.delete': 'Supprimer',
'common.add': 'Ajouter',
'common.back': 'Retour',
'common.home': 'Accueil',
'common.understood': 'Compris',
'common.collapse': 'Réduire',
'common.expand': 'Développer',
'common.move_up': 'Monter',
'common.move_down': 'Descendre',
'common.none': 'Aucun',
'common.back_to_home': "Retour à l'accueil",
// home
'home.new_report.title': 'Nouveau bilan',
'home.new_report.description': "Démarrer un nouveau bilan d'ostéopathie sur un animal.",
'home.new_report.cta': 'Commencer',
'home.import.title': 'Importer un PDF',
'home.import.description':
"Reprendre un bilan précédent généré par cette application pour effectuer un suivi.",
'home.import.cta': 'Choisir un PDF',
'home.import.loading': 'Lecture…',
'home.import.error_generic': 'Erreur de lecture du PDF.',
// not found
'not_found.title': 'Page introuvable',
'not_found.description': "Le chemin demandé n'existe pas.",
// new report
'new_report.title': 'Nouveau bilan',
'new_report.date_label': 'Date du bilan',
'new_report.submit': 'Démarrer le bilan',
// editor
'editor.export': 'Exporter en PDF',
'editor.exporting': 'Génération…',
'editor.export_failed': 'Échec de la génération du PDF. Réessayez ou contactez le support.',
'editor.edit_infos': 'Modifier les infos',
'editor.edit_dialog_title': 'Modifier les informations',
'editor.disclaimer_title': "Périmètre légal de l'ostéopathie animale",
// observation list / card
'observation.section_title': 'Observations',
'observation.add': '+ Nouvelle observation',
'observation.empty':
'Aucune observation. Cliquez sur "+ Nouvelle observation" puis sur les zones du schéma.',
'observation.badge_n': 'Observation #',
'observation.zone_label_singular': 'zone',
'observation.zone_label_plural': 'zones',
'observation.finding_label_singular': 'constat',
'observation.finding_label_plural': 'constats',
'observation.zones_label': 'Zones sélectionnées',
'observation.zones_empty': 'Cliquez sur les zones du schéma pour les ajouter à cette observation.',
'observation.findings_catalog_label': 'Constats (référentiel)',
'observation.findings_pick_zone_first': 'Sélectionnez une zone pour accéder au référentiel.',
'observation.findings_no_catalog':
'Aucun référentiel disponible pour ces zones. Utilisez le texte libre ci-dessous.',
'observation.findings_free_label': 'Constats (texte libre)',
'observation.free_placeholder': 'Observation additionnelle (texte libre)',
'observation.free_aria': 'Observation libre',
'observation.severity_label': 'Sévérité',
'observation.comment_label': 'Commentaire',
'observation.comment_placeholder': 'Notes cliniques détaillées…',
'observation.vertebrae_button': 'Vertèbres…',
'observation.vertebrae_button_title': 'Préciser les vertèbres pour cette zone',
'observation.remove_zone': 'Retirer',
'observation.expand_aria': "Développer l'observation",
'observation.collapse_aria': "Réduire l'observation",
// findings tree picker
'findings.back_to_parent': 'Retour au niveau précédent',
'findings.back': '← Retour',
'findings.no_options': 'Aucune option disponible à ce niveau.',
'findings.open': 'Ouvrir',
'findings.vet_referral': 'Référer au vétérinaire',
'findings.selected_singular': 'constat sélectionné',
'findings.selected_plural': 'constats sélectionnés',
// forms
'form.practitioner.legend': 'Praticien',
'form.practitioner.name': 'Nom complet *',
'form.practitioner.cabinet': 'Cabinet / clinique',
'form.practitioner.contact': 'Contact (téléphone, email…)',
'form.practitioner.siret': 'SIRET',
'form.animal.legend': 'Animal & propriétaire',
'form.animal.species': 'Espèce *',
'form.animal.name': "Nom de l'animal *",
'form.animal.breed': 'Race',
'form.animal.age': 'Âge',
'form.owner.name': 'Nom du propriétaire *',
// conclusion panel
'conclusion.section_title': 'Conclusion & recommandations',
'conclusion.conclusion': 'Conclusion',
'conclusion.recommendations': 'Recommandations',
'conclusion.next_appointment': 'Prochain rendez-vous',
'conclusion.next_kind_date': 'Date',
'conclusion.next_kind_period': 'Période libre',
'conclusion.next_kind_none': 'Aucun',
'conclusion.next_period_placeholder': 'ex. dans 3 semaines',
// vertebra picker
'vertebra.title_prefix': 'Préciser les vertèbres — ',
'vertebra.region.C': 'Cervicales',
'vertebra.region.T': 'Thoraciques',
'vertebra.region.L': 'Lombaires',
'vertebra.region.S': 'Sacrales',
'vertebra.region.Cd': 'Caudales',
'vertebra.check_all': 'Tout cocher',
'vertebra.uncheck_all': 'Tout décocher',
// severity
'severity.aria': 'Sévérité',
'severity.légère': 'légère',
'severity.modérée': 'modérée',
'severity.sévère': 'sévère',
// pdf
'pdf.eyebrow.observation': 'OBSERVATION',
'pdf.eyebrow.synthesis': 'SYNTHÈSE',
'pdf.title.conclusion': 'Conclusion',
'pdf.section.zones': 'ZONES',
'pdf.section.findings_prefix': 'CONSTATS — ',
'pdf.section.free_findings': 'CONSTATS LIBRES',
'pdf.section.severity': 'SÉVÉRITÉ',
'pdf.section.comment': 'COMMENTAIRE',
'pdf.section.conclusion': 'CONCLUSION',
'pdf.section.recommendations': 'RECOMMANDATIONS',
'pdf.section.next_appointment': 'PROCHAIN RENDEZ-VOUS',
'pdf.view.general': 'VUE GÉNÉRALE',
'pdf.view.detail_prefix': 'VUE DÉTAIL — ',
'pdf.empty': '—',
'pdf.owner_prefix': 'Propriétaire : ',
'pdf.siret_prefix': 'SIRET ',
'pdf.export_date_prefix': 'Exporté le ',
'pdf.title.suffix.bilan': 'Bilan ostéo — ',
'pdf.subject': "Bilan d'ostéopathie animalière",
// language switcher
'lang.switch_to_fr': 'Passer en français',
'lang.switch_to_en': 'Switch to English',
'lang.fr': 'FR',
'lang.en': 'EN',
}
+9
View File
@@ -0,0 +1,9 @@
import { fr } from './fr'
import { en } from './en'
import type { Dict, Locale } from './types'
export const dicts: Record<Locale, Dict> = { fr, en }
export function getDict(locale: Locale): Dict {
return dicts[locale]
}
+17
View File
@@ -0,0 +1,17 @@
import { useLocaleStore } from '@/state/localeStore'
import { getDict } from './index'
export function useT(): (key: string) => string {
const locale = useLocaleStore((s) => s.locale)
const dict = getDict(locale)
return (key: string) => {
const v = dict[key]
if (v === undefined) {
if (import.meta.env?.DEV) {
console.warn(`i18n: missing key "${key}" for locale "${locale}"`)
}
return key
}
return v
}
}
+18
View File
@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest'
import { fr } from '@/i18n/fr'
import { en } from '@/i18n/en'
describe('i18n dicts', () => {
it('fr and en share the exact same key set', () => {
const frKeys = Object.keys(fr).sort()
const enKeys = Object.keys(en).sort()
expect(frKeys).toEqual(enKeys)
})
it('every value is a non-empty string', () => {
for (const k of Object.keys(fr)) {
expect(fr[k].length).toBeGreaterThan(0)
expect(en[k].length).toBeGreaterThan(0)
}
})
})
+29
View File
@@ -0,0 +1,29 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
})
describe('useT', () => {
it('returns the FR value for a known key', () => {
const { result } = renderHook(() => useT())
expect(result.current('common.cancel')).toBe('Annuler')
})
it('returns the EN value after switching locale', () => {
const { result } = renderHook(() => useT())
act(() => useLocaleStore.getState().setLocale('en'))
expect(result.current('common.cancel')).toBe('Cancel')
})
it('returns the key literal and warns when key is missing', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
const { result } = renderHook(() => useT())
expect(result.current('nonexistent.key')).toBe('nonexistent.key')
expect(warn).toHaveBeenCalled()
warn.mockRestore()
})
})