Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(locale): filter and cleanup PersonEntryDefintions data #3266

Draft
wants to merge 17 commits into
base: refactor/person/sex
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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