-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
How to generate a middleName? #381
Comments
I don't believe the dataset has a middle name. I've been using a second
FirstName instead. For my locale that works out well enough. Are Middle
names in ru similar to first names?
…On Wed, Jul 14, 2021, 12:42 AM bloodgang94 ***@***.***> wrote:
How will the middle name be generated?
I use the ru locale. In the class name I did not find a property
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#381>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEAWF7MCFROBR2DF4JHUWF3TXUPVDANCNFSM5AKXDXUA>
.
|
If you do not need it to be 100% correct, you can reuse FirstName and if it is Fathers` name, you can modify rule to add "ич" or "ович" to the end, so "Иван" would become "Иванович". .RuleFor(u => u.MiddleName, f => f.Person.FirstName() + "ович") Then again if you want it gender safe - you need to build some more logic to add "овна" in case person gender is woman. |
It's super great to see the community help with these questions. Great work! To add to the solutions in this issue; Bogus does contain an Bogus/Source/Bogus/data/ru.locale.json Lines 1368 to 1372 in 9fc7614
If you want to access this raw data in C#, you'll need to use lower-level APIs via the raw DB as shown below: void Main()
{
var f = new Faker("ru");
Enumerable.Range(0, 5)
.Select(_ => f.Name.GetRuMiddleName(Name.Gender.Male))
.Dump();
Enumerable.Range(0, 5)
.Select(_ => f.Name.GetRuMiddleName(Name.Gender.Female))
.Dump();
}
public static class RuNameExtensions
{
public static string GetRuMiddleName(this Bogus.DataSets.Name name, Name.Gender gender)
{
BArray middleNameData;
if( gender == Bogus.DataSets.Name.Gender.Male ){
middleNameData = (BArray)Bogus.Database.Get("name", "male_middle_name", "ru");
}
else
{
middleNameData = (BArray)Bogus.Database.Get("name", "female_middle_name", "ru");
}
return name.Random.ArrayElement(middleNameData);
}
} I have no idea if this middle name data for the |
How will the middle name be generated?
I use the ru locale. In the class name I did not find a property
The text was updated successfully, but these errors were encountered: