Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1d02393
refactor(person): refine definitions of PersonEntryDefinitions
ST-DDT Nov 12, 2024
e5a397c
chore: dont breaking change sexType()
ST-DDT Nov 12, 2024
5989b95
chore: fix tests
ST-DDT Nov 12, 2024
926c959
Merge branch 'next' into refactor/person/sex
ST-DDT Nov 13, 2024
ffaafd3
chore: use sexType method
ST-DDT Nov 13, 2024
23e8f40
chore: edit after meeting
ST-DDT Nov 15, 2024
cdfad57
chore: update snapshots
ST-DDT Nov 15, 2024
b61595c
Merge branch 'next' into refactor/person/sex
ST-DDT Nov 15, 2024
b5f6a65
temp(script): filter PersonEntryDefinitions
ST-DDT Nov 15, 2024
3b60f8a
chore: sort alphabetically
ST-DDT Nov 15, 2024
9c874c1
chore: log stats
ST-DDT Nov 15, 2024
3d4fd2f
Merge branch 'refactor/person/sex' into refactor/person/sex-localeData
ST-DDT Nov 15, 2024
4f00862
chore: log stats
ST-DDT Nov 15, 2024
37f3c96
chore: log stats
ST-DDT Nov 15, 2024
9b28f06
Merge branch 'next' into refactor/person/sex
ST-DDT Nov 21, 2024
cd834b4
Merge remote-tracking branch 'origin/refactor/person/sex' into refact…
ST-DDT Nov 25, 2024
49cb2d7
Merge branch 'next' into refactor/person/sex
ST-DDT Dec 3, 2024
38c0a31
Merge branch 'refactor/person/sex' into refactor/person/sex-localeData
ST-DDT Dec 3, 2024
f87c9f9
chore: improve stats logging
ST-DDT Dec 3, 2024
0f0886c
chore: revert logging
ST-DDT Dec 3, 2024
f55095f
chore: run generate:locales
ST-DDT Dec 3, 2024
538faf2
chore: update snapshots
ST-DDT Dec 3, 2024
ab927a6
chore: restore pt person prefix comments
ST-DDT Dec 3, 2024
8753216
chore: fix sk company patterns
ST-DDT Dec 3, 2024
fb732cc
Merge branch 'next' into refactor/person/sex
ST-DDT Dec 9, 2024
6e7289b
Merge branch 'refactor/person/sex' into refactor/person/sex-localeData
ST-DDT Dec 19, 2024
7db34bd
chore: fix locale patterns
ST-DDT Dec 24, 2024
69bcc13
Merge branch 'next' into refactor/person/sex
ST-DDT Dec 24, 2024
caf6f65
refactor: new distribution
ST-DDT Dec 24, 2024
39c0ebf
Merge branch 'refactor/person/sex' into refactor/person/sex-localeData
ST-DDT Dec 24, 2024
0bcfa45
chore: update snapshots
ST-DDT Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scripts/generate-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { constants } from 'node:fs';
import { access, readFile, readdir, stat, writeFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { PersonEntryDefinition } from '../dist';
import type { LocaleDefinition, MetadataDefinition } from '../src/definitions';
import { keys } from '../src/internal/keys';
import { formatMarkdown, formatTypescript } from './apidocs/utils/format';
Expand Down Expand Up @@ -326,9 +327,56 @@ async function updateLocaleFileHook(
console.log(`${filePath} <-> ${locale} @ ${definitionKey} -> ${entryName}`);
}

if (definitionKey === 'person' && entryName != null) {
await normalizePersonFile(filePath);
}

return normalizeLocaleFile(filePath, definitionKey);
}

async function normalizePersonFile(filePath: string) {
const { default: data } = (await import(`file:${filePath}`)) as {
default: PersonEntryDefinition<string>;
};
const { female = [], generic = [], male = [] } = data ?? {};

// Revert merging of female and male => generic
for (let i = generic.length; i >= 0; --i) {
if (female.includes(generic[i]) !== male.includes(generic[i])) {
generic.splice(i, 1);
}
}

// Remove generic entries from females and detect new generic entries
for (let i = female.length; i >= 0; --i) {
if (generic.includes(female[i])) {
female.splice(i, 1);
} else if (male.includes(female[i])) {
generic.push(female[i]);
female.splice(i, 1);
}
}

// Remove generic entries from males
for (let i = male.length; i >= 0; --i) {
if (generic.includes(male[i])) {
male.splice(i, 1);
}
}

const newData = {
generic: generic.length > 0 ? generic.sort() : undefined,
female: female.length > 0 ? female.sort() : undefined,
male: male.length > 0 ? male.sort() : undefined,
};

const newContent = `export default ${JSON.stringify(newData)};`;

if (female.length > 0 || generic.length > 0 || male.length > 0) {
await writeFile(filePath, await formatTypescript(newContent));
}
}

/**
* Normalizes the data of a locale file based on a set of rules.
* Those include:
Expand Down
19 changes: 17 additions & 2 deletions src/definitions/person.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import type { LocaleEntry } from './definitions';

/**
* Entries that are dependent on a person's sex.
*/
export type PersonEntryDefinition<T> =
| {
/**
* Values that are primarily attributable to only males.
*/
female: T[];
/**
* Values that cannot clearly be attributed to a specific sex or are used for both sexes.
*/
generic?: T[];
/**
* Values that are primarily attributable to only females.
*/
male: T[];
female: T[];
}
| {
female?: never;
/**
* Values that cannot clearly be attributed to a specific sex or are used both sexes.
*/
generic: T[];
male?: never;
female?: never;
};

type SimplePersonEntryDefinition = PersonEntryDefinition<string>;
Expand Down
221 changes: 0 additions & 221 deletions src/locales/af_ZA/person/first_name.ts
Original file line number Diff line number Diff line change
@@ -1,225 +1,4 @@
export default {
generic: [
'Adam',
'Adriaan',
'Alan',
'Albert',
'Alexander',
'Alicia',
'Allen',
'Alma',
'Amanda',
'Amelia',
'Andre',
'Angelique',
'Angie',
'Anita',
'Anna',
'Annelie',
'Annette',
'Anthony',
'Antoinette',
'Audrey',
'Belinda',
'Bennie',
'Bernadette',
'Bernard',
'Bernice',
'Billy',
'Bobbie',
'Brenda',
'Brian',
'Bridgette',
'Cameron',
'Carla',
'Carmen',
'Cecil',
'Cecile',
'Charl',
'Charlene',
'Charlotte',
'Chris',
'Christopher',
'Cindy',
'Clara',
'Conrad',
'Craig',
'Dale',
'Daniel',
'Dante',
'David',
'Debbie',
'Dennis',
'Derek',
'Derrick',
'Duanne',
'Earl',
'Eddie',
'Edith',
'Edna',
'Edward',
'Elaine',
'Eleanor',
'Elisa',
'Ellen',
'Eloise',
'Elsa',
'Erik',
'Erika',
'Ernest',
'Estelle',
'Ethel',
'Eugene',
'Francois',
'Frankie',
'George',
'Gerald',
'Geraldine',
'Gerhard',
'Hannes',
'Harry',
'Harvey',
'Hazel',
'Heidi',
'Helen',
'Henrie',
'Herman',
'Hugo',
'Ian',
'Ida',
'Iwan',
'Jaco',
'Jacobus',
'Jacques',
'Jan',
'Jana',
'Janet',
'Jenna',
'Jenny',
'Jimmy',
'Joe',
'Johan',
'Johannes',
'Jolanda',
'Joshua',
'Juanita',
'Julian',
'Karen',
'Karl',
'Karla',
'Katrina',
'Katryn',
'Kayla',
'Kenneth',
'Kerry',
'Kevin',
'Kimberly',
'Krista',
'Kristie',
'Kristin',
'Kristina',
'Krystal',
'Leona',
'Leonard',
'Leticia',
'Linda',
'Lisa',
'Louis',
'Lucille',
'Lukas',
'Lydia',
'Lynda',
'Lynette',
'Margaret',
'Marie',
'Mark',
'Markus',
'Marlene',
'Martin',
'Mathuys',
'Maureen',
'Melanie',
'Melinda',
'Melissa',
'Michael',
'Micheal',
'Michele',
'Mike',
'Monica',
'Monique',
'Morne',
'Nadine',
'Natalie',
'Natasha',
'Neil',
'Nick',
'Nicoleen',
'Nina',
'Olivia',
'Oscar',
'Paul',
'Paula',
'Pauline',
'Phillip',
'Pieter',
'Raymond',
'Renette',
'Rhonda',
'Riaan',
'Richard',
'Rick',
'Rigard',
'Rita',
'Robert',
'Robin',
'Robyn',
'Roland',
'Ronald',
'Rosalie',
'Rosemarie',
'Roy',
'Ruben',
'Rudolph',
'Rudy',
'Rufus',
'Russell',
'Sandra',
'Sara',
'Shaun',
'Shawn',
'Simon',
'Sonia',
'Sonja',
'Stefanie',
'Stephaans',
'Stephen',
'Steve',
'Steven',
'Sue-Marie',
'Susan',
'Tanya',
'Tasha',
'Theo',
'Theunis',
'Theuns',
'Thomas',
'Tommie',
'Vanessa',
'Vernon',
'Vickie',
'Victor',
'Vincent',
'Wayne',
'Wesley',
'Wessel',
'Wilbur',
'Willem',
'William',
'Willie',
'Wilma',
'Yvette',
'Yvonne',
],
female: [
'Alicia',
'Alma',
Expand Down
4 changes: 2 additions & 2 deletions src/locales/ar/location/street_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'{{location.street_prefix}} {{person.first_name.generic}}',
'{{location.street_prefix}} {{person.last_name.generic}}',
'{{location.street_prefix}} {{person.firstName}}',
'{{location.street_prefix}} {{person.lastName}}',
];
Loading
Loading