diff --git a/frontend/src/utils/kinship/en.js b/frontend/src/utils/kinship/en.js index 033d78d..17d01db 100644 --- a/frontend/src/utils/kinship/en.js +++ b/frontend/src/utils/kinship/en.js @@ -3,6 +3,32 @@ 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) +function ordinal(n) { + switch (n) { + case 1: + return "First" + case 2: + return "Second" + case 3: + return "Third" + default: + return `{n}th` + } +} + +function times(n) { + switch (n) { + case 1: + return "once" + case 2: + return "twice" + case 3: + return "thrice" + default: + return `${n} times` + } +} + export default function nameEn(path) { const { ups, downs, hasSpouse, sex } = kinshipFacts(path) @@ -36,10 +62,8 @@ export default function nameEn(path) { else if (ups >= 2 && downs >= 2) { const degree = Math.min(ups, downs) - 1 const removed = Math.abs(ups - downs) - if (degree === 1 && removed === 0) label = 'First cousin' - else if (degree === 1) label = 'First cousin once removed' - else if (removed === 0) label = `Cousin, degree ${degree}` - else label = 'Distant cousin' + if (removed === 0) label = `${ordinal(degree)} cousin` + else label = `${ordinal(degree)} cousin, ${times(removed)} removed` } else label = `${ups + downs} steps apart` 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 6cdaf85..e093005 100644 --- a/frontend/src/utils/kinship/kinship.test.js +++ b/frontend/src/utils/kinship/kinship.test.js @@ -67,6 +67,11 @@ describe('nommage anglais', () => { expect(bothEn(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law']) 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']) }) it('une langue inconnue retombe sur l’anglais', () => {