From 7fee10478d3c306d8aacd76e5f50039a1878843e Mon Sep 17 00:00:00 2001 From: IliesAllali Date: Sun, 1 Nov 2026 20:41:25 +0100 Subject: [PATCH] =?UTF-8?q?kinship=20en=20:=204th=20cousin,=20great-uncle,?= =?UTF-8?q?=20sans=20virgule=20avant=20=C2=AB=20removed=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ordinal() : il manquait le $, un cousin au 4e degré s'affichait « {n}th cousin » - Great-uncle et great-great-uncle, la forme courante, au lieu de granduncle - « First cousin once removed », sans virgule - Style du dépôt (guillemets simples, sans points-virgules) Co-Authored-By: Claude Opus 5.5 --- frontend/src/utils/kinship/en.js | 85 +++++----------------- frontend/src/utils/kinship/kinship.test.js | 12 ++- 2 files changed, 27 insertions(+), 70 deletions(-) diff --git a/frontend/src/utils/kinship/en.js b/frontend/src/utils/kinship/en.js index a069651..71e49d0 100644 --- a/frontend/src/utils/kinship/en.js +++ b/frontend/src/utils/kinship/en.js @@ -3,39 +3,21 @@ import { kinshipFacts } from './facts.js' // Mot genré quand le sexe de la personne nommée est connu, forme neutre ou double sinon const g = (sex, male, female, neutral) => (sex === 'male' ? male : sex === 'female' ? female : neutral) +// 1st, 2nd, 3rd, 4th… 11th, 12th, 13th, 21st function ordinal(n) { - switch (n) { - case 1: - return "First" - case 2: - return "Second" - case 3: - return "Third" - default: - return `{n}th` - } + const words = ['First', 'Second', 'Third'] + if (n <= 3) return words[n - 1] + const suffix = n % 100 >= 11 && n % 100 <= 13 ? 'th' : ({ 1: 'st', 2: 'nd', 3: 'rd' }[n % 10] || 'th') + return `${n}${suffix}` } function times(n) { - switch (n) { - case 1: - return "once" - case 2: - return "twice" - case 3: - return "thrice" - default: - return `${n} times` - } + return ['once', 'twice', 'thrice'][n - 1] || `${n} times` } +// Règle des G : autant de G que de générations d'écart (grandfather, great-grandfather, great-great-grandfather) function grule(n) { - switch (n - 1) { - case 1: - return "Grand" - default: - return `Great-${"great-".repeat(n - 3)}grand` - } + return n === 2 ? 'Grand' : `Great-${'great-'.repeat(n - 3)}grand` } export default function nameEn(path) { @@ -54,50 +36,21 @@ export default function nameEn(path) { let label if (downs === 0 && ups > 0) { - switch (ups) { - case 1: - label = g(sex, 'Father', 'Mother', 'Parent') - break; - default: - label = `${grule(ups)}${g(sex, 'father', 'mother', 'parent')}` - break; - } + label = ups === 1 ? g(sex, 'Father', 'Mother', 'Parent') : `${grule(ups)}${g(sex, 'father', 'mother', 'parent')}` } else if (ups === 0 && downs > 0) { - switch (downs) { - case 1: - label = g(sex, 'Son', 'Daughter', 'Child') - break; - default: - label = `${grule(downs)}${g(sex, 'son', 'daughter', 'child')}` - break; - } - } else if (downs == 1) { - switch (ups) { - case 1: - label = g(sex, 'Brother', 'Sister', 'Sibling') - break; - case 2: - label = g(sex, 'Uncle', 'Aunt', 'Uncle/Aunt') - break; - default: - label = `${grule(ups - 1)}${g(sex, 'uncle', 'aunt', 'uncle/aunt')}` - break; - } + label = downs === 1 ? g(sex, 'Son', 'Daughter', 'Child') : `${grule(downs)}${g(sex, 'son', 'daughter', 'child')}` + } else if (downs === 1) { + if (ups === 1) label = g(sex, 'Brother', 'Sister', 'Sibling') + else if (ups === 2) label = g(sex, 'Uncle', 'Aunt', 'Uncle/Aunt') + // Great-uncle plutôt que granduncle : c'est la forme courante + else label = `Great-${'great-'.repeat(ups - 3)}${g(sex, 'uncle', 'aunt', 'uncle/aunt')}` } else if (ups === 1) { - switch (downs) { - case 2: - label = g(sex, 'Nephew', 'Niece', 'Nibling') - break; - default: - label = `${grule(downs - 1)}${g(sex, 'nephew', 'niece', 'nibling')}` - break; - } - } else if (ups >= 2 && downs >= 2) { + label = downs === 2 ? g(sex, 'Nephew', 'Niece', 'Nibling') : `${grule(downs - 1)}${g(sex, 'nephew', 'niece', 'nibling')}` + } else { const degree = Math.min(ups, downs) - 1 const removed = Math.abs(ups - downs) - if (removed === 0) label = `${ordinal(degree)} cousin` - else label = `${ordinal(degree)} cousin, ${times(removed)} removed` - } else label = `${ups + downs} steps apart` + label = removed === 0 ? `${ordinal(degree)} cousin` : `${ordinal(degree)} cousin ${times(removed)} removed` + } return hasSpouse ? `${label} by marriage` : label } diff --git a/frontend/src/utils/kinship/kinship.test.js b/frontend/src/utils/kinship/kinship.test.js index 69ad459..f268b4d 100644 --- a/frontend/src/utils/kinship/kinship.test.js +++ b/frontend/src/utils/kinship/kinship.test.js @@ -70,10 +70,14 @@ describe('nommage anglais', () => { expect(bothEn(['spouse'])).toEqual(['Partner', 'Partner', 'Partner']) expect(bothEn(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin']) expect(bothEn(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin']) - expect(bothEn(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin, once removed', 'First cousin, once removed', 'First cousin, once removed']) - expect(bothEn(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin, thrice removed', 'Third cousin, thrice removed', 'Third cousin, thrice removed']) - expect(bothEn(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin, twice removed', 'First cousin, twice removed', 'First cousin, twice removed']) - expect(bothEn(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin, 4 times removed', 'First cousin, 4 times removed', 'First cousin, 4 times removed']) + expect(bothEn(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin once removed', 'First cousin once removed', 'First cousin once removed']) + expect(bothEn(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin thrice removed', 'Third cousin thrice removed', 'Third cousin thrice removed']) + expect(bothEn(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin twice removed', 'First cousin twice removed', 'First cousin twice removed']) + expect(bothEn(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin 4 times removed', 'First cousin 4 times removed', 'First cousin 4 times removed']) + expect(bothEn(['up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down', 'down'])).toEqual(['4th cousin', '4th cousin', '4th cousin']) + expect(bothEn(['up', 'up', 'sibling'])).toEqual(['Great-uncle', 'Great-aunt', 'Great-uncle/aunt']) + expect(bothEn(['up', 'up', 'up', 'sibling'])).toEqual(['Great-great-uncle', 'Great-great-aunt', 'Great-great-uncle/aunt']) + expect(bothEn(['sibling', 'down', 'down'])).toEqual(['Grandnephew', 'Grandniece', 'Grandnibling']) }) it('une langue inconnue retombe sur l’anglais', () => {