Merge pull request #204 from Arc676/cousins

Fix some English relations
This commit is contained in:
IliesAllali authored and GitHub committed 2026-11-04 16:38:05 +01:00
commit 419fa4cda0
2 files changed
+44 -23

No files matched your search

+31 -21
View File
@@ -3,11 +3,28 @@ 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) {
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) {
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) {
return n === 2 ? 'Grand' : `Great-${'great-'.repeat(n - 3)}grand`
}
export default function nameEn(path) {
const { ups, downs, hasSpouse, sex } = kinshipFacts(path)
// « Spouse » reste neutre : husband et wife supposeraient un mariage
if (hasSpouse && ups === 0 && downs === 0) return 'Spouse'
// « Partner » reste neutre au lieu de supposer un mariage
if (hasSpouse && ups === 0 && downs === 0) return 'Partner'
if (hasSpouse) {
// L'anglais distingue l'ordre : le parent du conjoint (in-law) n'est pas le conjoint du parent (step)
@@ -19,28 +36,21 @@ export default function nameEn(path) {
let label
if (downs === 0 && ups > 0) {
if (ups === 1) label = g(sex, 'Father', 'Mother', 'Parent')
else if (ups === 2) label = g(sex, 'Grandfather', 'Grandmother', 'Grandparent')
else if (ups === 3) label = g(sex, 'Great-grandfather', 'Great-grandmother', 'Great-grandparent')
else label = `Ancestor, ${ups} generations up`
label = ups === 1 ? g(sex, 'Father', 'Mother', 'Parent') : `${grule(ups)}${g(sex, 'father', 'mother', 'parent')}`
} else if (ups === 0 && downs > 0) {
if (downs === 1) label = g(sex, 'Son', 'Daughter', 'Child')
else if (downs === 2) label = g(sex, 'Grandson', 'Granddaughter', 'Grandchild')
else if (downs === 3) label = g(sex, 'Great-grandson', 'Great-granddaughter', 'Great-grandchild')
else label = `Descendant, ${downs} generations down`
} else if (ups === 1 && downs === 1) label = g(sex, 'Brother', 'Sister', 'Sibling')
else if (ups === 2 && downs === 1) label = g(sex, 'Uncle', 'Aunt', 'Uncle/Aunt')
else if (ups === 3 && downs === 1) label = g(sex, 'Great-uncle', 'Great-aunt', 'Great-uncle/aunt')
else if (ups === 1 && downs === 2) label = g(sex, 'Nephew', 'Niece', 'Nephew/Niece')
else if (ups === 1 && downs === 3) label = g(sex, 'Grandnephew', 'Grandniece', 'Grandnephew/niece')
else if (ups >= 2 && downs >= 2) {
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) {
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 (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'
} else label = `${ups + downs} steps apart`
label = removed === 0 ? `${ordinal(degree)} cousin` : `${ordinal(degree)} cousin ${times(removed)} removed`
}
return hasSpouse ? `${label} by marriage` : label
}
+13 -2
View File
@@ -56,17 +56,28 @@ describe('nommage français', () => {
describe('nommage anglais', () => {
it('genre le mot quand le sexe est connu', () => {
expect(bothEn(['up'])).toEqual(['Father', 'Mother', 'Parent'])
expect(bothEn(['up', 'up'])).toEqual(['Grandfather', 'Grandmother', 'Grandparent'])
expect(bothEn(['up', 'up', 'up', 'up'])).toEqual(['Great-great-grandfather', 'Great-great-grandmother', 'Great-great-grandparent'])
expect(bothEn(['down', 'down'])).toEqual(['Grandson', 'Granddaughter', 'Grandchild'])
expect(bothEn(['sibling'])).toEqual(['Brother', 'Sister', 'Sibling'])
expect(bothEn(['up', 'sibling'])).toEqual(['Uncle', 'Aunt', 'Uncle/Aunt'])
expect(bothEn(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nephew/Niece'])
expect(bothEn(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nibling'])
expect(bothEn(['spouse', 'up'])).toEqual(['Father-in-law', 'Mother-in-law', 'Parent-in-law'])
expect(bothEn(['up', 'spouse'])).toEqual(['Stepfather', 'Stepmother', 'Stepparent'])
expect(bothEn(['spouse', 'down'])).toEqual(['Stepson', 'Stepdaughter', 'Stepchild'])
expect(bothEn(['down', 'spouse'])).toEqual(['Son-in-law', 'Daughter-in-law', 'Child-in-law'])
expect(bothEn(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
expect(bothEn(['spouse'])).toEqual(['Spouse', 'Spouse', 'Spouse'])
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', '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', () => {