faker-js / faker

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

Email addresses are unknown on fakerHE in Hebrew #2776

Closed mordi9 closed 7 months ago

mordi9 commented 7 months ago

Pre-Checks

Describe the bug

When using faker.internet.email() with fakerHE, unknown email addresses are obtained, consisting of random characters. For example:

Suggested solution: Add support for names in email addresses using simple pronunciation-hyphenation translation, which will allow creating more correct email addresses, even if the translation is not accurate.

Advantages: Creating more realistic email addresses. Improving the usability of fakerHE for Hebrew users. effect: This change will affect all fakerHE users who use faker.internet.email() to create Hebrew email addresses.

Code to create a translation using according to pronunciation


const hebrewAlphabet = {
  "א": "a",
  "ב": "b",
  "ג": "g",
  "ד": "d",
  "ה": "h",
  "ו": "v",
  "ז": "z",
  "ח": "ch",
  "ט": "t",
  "י": "y",
  "כ": "k",
  "ך": "kh",
  "ל": "l",
  "ם": "m",
  "מ": "m",
  "ן": "n",
  "נ": "n",
  "ס": "s",
  "ע": "a",
  "פ": "f",
  "ף": "ph",
  "צ": "ts",
  "ץ": "ts",
  "ק": "k",
  "ר": "r",
  "ש": "sh",
  "ת": "t",
  "ו": "v",
};

function pronounce(word) {
  let pronouncedWord = "";
  for (let i = 0; i < word.length; i++) {
    pronouncedWord += hebrewAlphabet[word[i]];
  }
  return pronouncedWord;
}

function translate(text) {
  const words = text.split(" ");
  const translatedWords = words.map(word => pronounce(word));
  return translatedWords.join(" ");
}

translate(inputText);

Minimal reproduction code

const { fakerHE: faker } = require('@faker-js/faker');
const contacts = [];
for (let i = 0; i < 10; i++) {
    contacts.push({
      name: faker.person.fullName(),
      email: faker.internet.email(),
      phone: faker.phone.number(),
      location: faker.location.street() + " "  + faker.location.buildingNumber() + " " + faker.location.city()
    });
}

Additional Context

No response

Environment Info

node.js v18.16.0

Which module system do you use?

Used Package Manager

npm

ST-DDT commented 7 months ago

FFR:

The username method uses a charMapping that you could extend for HE.

Contributions welcome.