faker
faker copied to clipboard
feat(name): add ```hyphenated``` option to ```lastName()```
Clear and concise description of the problem
I want the ability to generate hyphenated last names so that it seems just a little bit more realistic. The function only generates single last names currently.
Suggested solution
Add a boolean option hyphenated?
Alternative
No response
Additional context
No response
IMO there are three possible solutions.
- Extend the locales
- Add parameter
- Random chance
As I'm not sure whether this actually a thing in all locales, maybe we should add it to the locale files directly?
@ST-DDT Yes, I don't think hyphenated last names are a thing in all locales. On another somewhat related note, what about locales with two or more surnames? Some Spanish names have multiple surnames.
On another somewhat related note, what about locales with two or more surnames? Some Spanish names have multiple surnames.
IMO if you request a single surname, you only get one (hyphenated or not). We could/should use a name pattern for that.
https://github.com/faker-js/faker/blob/a64cbde7c9cb05d97617708710c572b23a382f6d/src/locales/en/name/name.ts#L2-L7
This is the old format that was never usable.
But I think, we should revive it using faker.fake and treat all {{patterns}} that don't refer to methods as references to the locale data. (Basically an automatic faker.random.arrayElement(faker.definitions.<pattern>))
That way we can generate firstname lastname, lastname firstname or firstname lastname lastname easily per locale.
On another somewhat related note, what about locales with two or more surnames? Some Spanish names have multiple surnames.
IMO if you request a single surname, you only get one (hyphenated or not). We could/should use a name pattern for that.
https://github.com/faker-js/faker/blob/a64cbde7c9cb05d97617708710c572b23a382f6d/src/locales/en/name/name.ts#L2-L7
This is the old format that was never usable. But I think, we should revive it using
faker.fakeand treat all{{patterns}}that don't refer to methods as references to the locale data. (Basically an automaticfaker.random.arrayElement(faker.definitions.<pattern>))That way we can generate
firstname lastname,lastname firstnameorfirstname lastname lastnameeasily per locale.
Yes, this method would work really well.
This is the old format that was never usable. But I think, we should revive it using
faker.fakeand treat all{{patterns}}that don't refer to methods as references to the locale data. (Basically an automaticfaker.random.arrayElement(faker.definitions.<pattern>)) That way we can generatefirstname lastname,lastname firstnameorfirstname lastname lastnameeasily per locale.Yes, this method would work really well.
I created PR #927 for that (depends on #884)
The locale data/fake name pattern needs to be updated accordingly.
I am interested in this issue. May I be assigned, please?
I am interested in this issue. May I be assigned, please?
Sure!
@ST-DDT Yes, I don't think hyphenated last names are a thing in all locales. On another somewhat related note, what about locales with two or more surnames? Some Spanish names have multiple surnames.
Sorry to just pop in, I just wanted to add that some locales (United Kingdom for example) use both hyphenated and non-hyphenated (with the latter having terrible support sadly) - for example: Olivia Newton-John and Andrew Lloyd Webber. There are also some compounded surnames with more than 2 surnames which also may or may not be hyphenated (although as far as I am aware, these are less common)
IMO if you request a single surname, you only get one (hyphenated or not). We could/should use a name pattern for that.
https://github.com/faker-js/faker/blob/a64cbde7c9cb05d97617708710c572b23a382f6d/src/locales/en/name/name.ts#L2-L7
This is the old format that was never usable. But I think, we should revive it using
faker.fakeand treat all{{patterns}}that don't refer to methods as references to the locale data. (Basically an automaticfaker.random.arrayElement(faker.definitions.<pattern>))That way we can generate
firstname lastname,lastname firstnameorfirstname lastname lastnameeasily per locale.
I think this would mean that such combinations can be generated by specifying different patterns?
@markscamilleri Yes, but then it would only work for the fullName method. I think, if two ore more names (hypenated or space separated) are possible for surnames in the UK, then we should add some samples to the en(_GB?).person.last_name locale data directly. However, if these are multiple surnames like I think Spainish has (father's and mother's surname?), then it should be added to the pattern list.
@conner-c Any progress so far?
@markscamilleri Yes, but then it would only work for the fullName method. I think, if two ore more names (hypenated or space separated) are possible for surnames in the UK, then we should add some samples to the en(_GB?).person.last_name locale data directly. However, if these are multiple surnames like I think Spainish has (father's and mother's surname?), then it should be added to the pattern list.
Thanks @ST-DDT! Well techncally, they're multiple surnames combined into one (usually to keep both family names after marriage) - however on legal documentation (birth certificates, passports, ID cards and drivers licenses) these would be treated as a single surname. So I guess it would make more sense to have these in samples in the locale data.
Such surnames are also allowed in other en locales so I think it makes more sense to add this to the en sample list rather than the GB specific one.
I think this would be different to what @conner-c is working on? If it is, I'm happy to open up another issue and work on it.
I think this would be different to what @conner-c is working on? If it is, I'm happy to open up another issue and work on it.
No, I think that is exactly what conner-c is working on. If they dont react in a week or so you can take over.
I have been busy, so I have not had much time to work on it. It seems like @markscamilleri is currently displaying more interest than me and seems to have a better understanding of the issue. Feel free to unassign me and assign them to the issue. Sorry for such a late response.
Now that the fullName pattern code has landed this can be revisited
Seems there are two possible strategies
-
In some locales add a hyphenated name pattern with two lastNames and a low percentage weight (similar to how it is already works for
eswith double surnames) -
Add a few sample hyphenated patterns directly into the last_name definitions.
This could be fixed via #1819
We should discuss if we want hyphenated patterns in the default en locale?
A few samples from major English speaking countries.
Australia - 3% https://mccrindle.com.au/article/blog/last-name-mash-ups-give-fascinating-insights-into-changing-social-trends/ US - 5-6% https://www.nytimes.com/2011/11/24/fashion/babies-surnames-to-hyphenate-or-not.html / https://www.researchgate.net/publication/340388866_Women's_Marital_Surname_Change_by_Bride's_Age_and_Jurisdiction_of_Residence_A_Replication UK - 11% https://www.theguardian.com/lifeandstyle/2017/nov/02/keeping-up-with-smith-joneses-no-longer-posh-double-barrelled-surname India - ??% https://timesofindia.indiatimes.com/city/delhi/whats-in-a-sires-name/articleshow/2982.cms https://en.wikipedia.org/wiki/Double-barrelled_name#Non-Western_surname_traditions
My feeling is we should probably have {{person.last_name}}-{{person.last_name}} with a say 5% weight for en, allow other en-FOO locales to override if needed, and have {{person.last_name}} with 100% weight for locales with no pattern at the moment (e.g. ja) so they dont fall back to the en locale rules unexpectedly. Then if we get additional information about other locales we could add double or hyphenated patterns for them later.
Please accept my apologies for not working on this. I wanted to work on it, but I went through some life events that left me unable to deidcate the time for it. I understand I should have spoken up earlier but I was still hoping I could contribute to this.
Thanks for letting us know. If you ever have time and interest to contribute again, feel free to do so. I hope you will have a great time.