diff --git a/lib/name.ts b/lib/name.ts index 50e3cdc..1863497 100644 --- a/lib/name.ts +++ b/lib/name.ts @@ -1,13 +1,44 @@ +import type { Localizer } from './locales'; +import { BeninLocale } from './locales/benin'; +import { EfikLocale } from './locales/efik'; +import { EnglishLocale } from './locales/english'; +import { HausaLocale } from './locales/hausa'; +import { IgboLocale } from './locales/igbo'; +import { UrhoboLocale } from './locales/urhobo'; +import { YorubaLocale } from './locales/yoruba'; import type { Random } from './random'; -import { Gender, type Locale } from './types'; +import { Gender, Locale } from './types'; export class Name { private locale: Locale; private random: Random; + private localizer: Localizer; constructor(locale: Locale, random: Random) { this.locale = locale; this.random = random; + this.localizer = this.setLocalizer(); + } + + private setLocalizer(): Localizer { + switch (this.locale) { + case Locale.BENIN: + return new BeninLocale(this.random); + case Locale.YORUBA: + return new YorubaLocale(this.random); + case Locale.IGBO: + return new IgboLocale(this.random); + case Locale.HAUSA: + return new HausaLocale(this.random); + case Locale.EFIK: + return new EfikLocale(this.random); + case Locale.URHOBO: + return new UrhoboLocale(this.random); + case Locale.ENGLISH: + return new EnglishLocale(this.random); + default: + throw new Error(`Locale "${this.locale}" not supported`); + } } private selectRandomGender(): Gender { @@ -16,11 +47,14 @@ export class Name { firstName(gender?: Gender): string { const chosenGender = gender ?? this.selectRandomGender(); - return ''; + return this.localizer.firstName(chosenGender); + } + + lastName(): string { + return this.localizer.lastName(); + } - // if (gender === 0) { - // return ngFaker.random.arrayElement(ngFaker.definitions.name.male_first_name); - // } - // return ngFaker.random.arrayElement(ngFaker.definitions.name.female_first_name); + prefix(): string { + return this.localizer.prefix(); } } diff --git a/lib/types.ts b/lib/types.ts index f0e2c03..338f5c1 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -5,6 +5,7 @@ export enum Locale { HAUSA, EFIK, BENIN, + URHOBO, } export enum Gender {