-
-
Notifications
You must be signed in to change notification settings - Fork 501
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
Is there a way to produce random addresses that are country specific? #318
Comments
Hi Thomas, It looks like the faker.js Bogus/Source/Bogus/data/en_GB.locale.json Lines 76 to 87 in 4f65c5e
I think you'll have to resort to using the following workaround: void Main()
{
var f = new Faker("en_GB");
var country = f.Address.UkCountry();
country.Dump();
var country2 = f.Address.UkCountry2();
country2.Dump();
}
public static class AddressExtensionsForUk
{
public static string UkCountry(this Bogus.DataSets.Address address)
{
var countries = new [] {
"England",
"Scotland",
"Wales",
"Northern Ireland"
};
return address.Random.ArrayElement(countries);
}
public static string UkCountry2(this Bogus.DataSets.Address address){
var array = Database.Get(nameof(address), "uk_country", "en_GB") as BArray;
return address.Random.ArrayElement(array);
}
} Hope that helps! Thanks, |
…hod in `Bogus.Extensions.UnitedKingdom`.
Hi Thomas, Added The following code now works in Bogus using Bogus.Extensions.UnitedKingdom;
void Main()
{
var f = new Faker("en_GB");
var uk_country = f.Address.CountryOfUnitedKingdom();
uk_country.Dump();
} Update to Thanks, |
Awesome! Thanks for your help 👍 |
Trying to generate addresses unique to the UK i.e. country can only be England, Wales, Scotland, Northern Ireland. Counties seems to work. The code I'm using is below, but it's printing out random country names in English
The text was updated successfully, but these errors were encountered: