faker-js / faker

Generate massive amounts of fake data in the browser and node.js
https://fakerjs.dev
Other
11.85k stars 877 forks source link

Localization lastName is not working #2833

Closed undermuz closed 3 weeks ago

undermuz commented 3 weeks ago

Pre-Checks

Describe the bug

This code produces base last names:

import { fakerRU as faker } from "@faker-js/faker";

console.log(faker.person.lastName());

Expected: this code produces localizated last names

Minimal reproduction code

https://codesandbox.io/p/sandbox/faker-js-ru-not-working-forked-cthnpl?file=%2Fsrc%2Findex.ts%3A20%2C41

import { fakerRU, ru as localization } from "@faker-js/faker";

//THIS TEMP FIX:
// import { base, ru, Faker } from "@faker-js/faker";

// const customFaker = new Faker({
//   locale: [ru, base],
// });

const faker = fakerRU;

let maxIterations = 1000;
let found = false;
let i = 0;

console.log(localization);

const allLastNames = [
  ...localization.person.female_last_name,
  ...localization.person.male_last_name,
];

console.log(allLastNames);

while (!found && i++ < maxIterations) {
  const text = faker.person.lastName();

  console.log(text);

  found = allLastNames.some((t) => t === text);

  if (found) {
    console.log("Found", text);
    break;
  }
}

if (!found) console.log("Not found");

Additional Context

No response

Environment Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12600
    Memory: 16.03 GB / 31.75 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @faker-js/faker: ^8.4.1 => 8.4.1

Which module system do you use?

Used Package Manager

npm

ST-DDT commented 3 weeks ago

Potential dublicate of https://github.com/faker-js/faker/issues/1677

matthewmayer commented 3 weeks ago

This affects locales that have a male_last_name and female_last_name file but no last_name file.

Specifically:

sk
id_ID
lv
ru
uk
az
uz_UZ_latin

We can solve this by adding a last_name.ts file with mergeArrays. This is already done for these locales:

cs_CZ
dv
mk