Closed Max-Riley closed 6 years ago
Hi Maxfield,
Thank you for your suggestion. I really appreciate it.
I agree it would be a better developer experience to throw an exception when the user passes in an invalid locale instead of running into a NullReferenceException
at method invocation. This would be an overall improvement we can take a closer look at.
As for changing over Bogus' locale codes wholesale to ISO 639x
locale codes, I feel this is a significant breaking change. Generally, I'm okay with breaking changes if the benefits of the changes outweigh the costs of breaking people's code. However, I'm not sure a change like this would meet that threshold.
Maybe a better approach to interoperability with CultureInfo.CurrentCulture
is to offer an extension method that maps culture names in the .NET Framework to Bogus locale codes like the following:
var bogusLocale = CultureInfo.CurrentCulture.ToBogusLocale();
var lorem = new Lorem(bogusLocale);
Or maybe accept a CultureInfo
in the constructor:
var lorem = new Lorem(CultureInfo.CurrentCulture);
Also, I think it's important for Bogus to maintain its own locale codes (in line with faker.js) because there are some .NET Framework locales that won't have a direct mapping like en_au_ocker
.
Thanks, Brian
:crown: :gem: "I know everything that shine ain't always gold..."
Either way seems quite doable even a mapping between the supported languages of ISO 639x and supported locales of faker.js so it can keep in line with faker.js.
Either way seems quite awesome! Thank you for the wonderful code!
Hi Maxfield,
Bogus v22.0.5
has been released.
Changes include:
.ToBogusLocale()
extension method on CultureInfo
to help translate .NET Framework locale codes to Bogus locale codes.Hope that helps!
Thanks, Brian
:car: :blue_car: "Let the good times roll..."
Seems a few of these locales dont follow the iso 639x standard. Is there any road-map or want to support a standardized list of locales accepted that can be universal? as per ISO 639x Values support in C# is limited due to the locale codes not following the ISO standard for language culture names and the 639X values.
a few being:
Also if you enter an invalid string for the Locale, you don't know the locale is invalid until you try to invoke a method.