diff --git a/Source/Bogus.Tests/HandlebarsTests/ArgumentsTest.cs b/Source/Bogus.Tests/HandlebarsTests/ArgumentsTest.cs index 90e7b11c..e24f257e 100644 --- a/Source/Bogus.Tests/HandlebarsTests/ArgumentsTest.cs +++ b/Source/Bogus.Tests/HandlebarsTests/ArgumentsTest.cs @@ -14,6 +14,23 @@ public ArgumentsTest(ITestOutputHelper console) this.console = console; } + [Fact] + public void can_instantiate_faker_with_locale_type() + { + var faker = new Faker(LocaleType.pt_BR); + } + + [Fact] + public void can_instantiate_faker_t_with_locale_type() + { + var faker = new Faker(LocaleType.fr); + } + + [Fact] + public void can_instantiate_dataset_with_locale_type() + { + var dataset = new DataSet(LocaleType.ko); + } [Fact] public void can_parse_random_number_request_without_arguments() diff --git a/Source/Bogus/DataSet.cs b/Source/Bogus/DataSet.cs index 6bc0f406..fdab5f3b 100644 --- a/Source/Bogus/DataSet.cs +++ b/Source/Bogus/DataSet.cs @@ -30,6 +30,17 @@ public DataSet(string locale = "en") this.Category = ResolveCategory(this.GetType()); } + /// + /// Initializes a new instance of the class. + /// + /// The locale wanting to be set. + /// + /// When the given isn't found. + /// + public DataSet(LocaleType localeType) : this(localeType.ToString()) + { + } + /// /// Gets or sets the category name inside the locale. /// @@ -39,7 +50,7 @@ public DataSet(string locale = "en") /// Gets or sets the current locale of the data set. /// public string Locale { get; set; } - + /// /// See . /// diff --git a/Source/Bogus/Faker.cs b/Source/Bogus/Faker.cs index 9a821b03..76d64dc1 100644 --- a/Source/Bogus/Faker.cs +++ b/Source/Bogus/Faker.cs @@ -42,7 +42,14 @@ public Faker(string locale = "en") this.Music = this.Notifier.Flow(new Music()); - this.Hashids = new Hashids(); + this.Hashids = new Hashids(); + } + + /// + /// Create a Faker with a specific locale. + /// + public Faker(LocaleType localeType) : this(localeType.ToString()) + { } Dictionary IHasContext.Context { get; } = new Dictionary(); diff --git a/Source/Bogus/Faker[T].cs b/Source/Bogus/Faker[T].cs index e7b9e14a..0900a0a9 100644 --- a/Source/Bogus/Faker[T].cs +++ b/Source/Bogus/Faker[T].cs @@ -124,14 +124,14 @@ public Faker Clone() /// The current locale. /// public string Locale { get; set; } - + /// /// Creates a Faker with default 'en' locale. /// public Faker() : this("en", null) { } - + /// /// Creates a Faker with a locale /// @@ -139,6 +139,13 @@ public Faker(string locale) : this(locale, null) { } + /// + /// Creates a Faker with a locale + /// + public Faker(LocaleType localeType) : this(localeType.ToString(), null) + { + } + /// /// Creates a Faker with a locale. /// @@ -147,7 +154,7 @@ public Faker(string locale) : this(locale, null) public Faker(string locale = "en", IBinder binder = null) { this.binder = binder ?? new Binder(); - this.Locale = locale; + this.Locale = locale; FakerHub = new Faker(locale); TypeProperties = this.binder.GetMembers(typeof(T)); this.CreateActions[Default] = faker => Activator.CreateInstance(); diff --git a/Source/Bogus/ILocaleAware.cs b/Source/Bogus/ILocaleAware.cs index 1f00400d..56e3921d 100644 --- a/Source/Bogus/ILocaleAware.cs +++ b/Source/Bogus/ILocaleAware.cs @@ -19,4 +19,260 @@ public interface ILocaleAware public interface IHasContext { Dictionary Context { get; } -} \ No newline at end of file +} + +/// +/// Represents all locales available for use, with language or dialect information and respective country or region. +/// +public enum LocaleType +{ + /// + /// Afrikaans language (South Africa). + /// + af_ZA, + + /// + /// Arabic language. + /// + ar, + + /// + /// Azerbaijani language (Azerbaijan). + /// + az, + + /// + /// Czech language (Czech Republic). + /// + cz, + + /// + /// German language (Germany). + /// + de, + + /// + /// German language (Austria). + /// + de_AT, + + /// + /// German language (Switzerland). + /// + de_CH, + + /// + /// Greek language (Greece). + /// + el, + + /// + /// English language. + /// + en, + + /// + /// English language (Australia). + /// + en_AU, + + /// + /// English language (Australia Ocker). + /// + en_AU_ocker, + + /// + /// English language in Bork dialect (fictional/humorous). + /// + en_BORK, + + /// + /// English language (Canada). + /// + en_CA, + + /// + /// English language (United Kingdom). + /// + en_GB, + + /// + /// English language (Ireland). + /// + en_IE, + + /// + /// English language (India). + /// + en_IND, + + /// + /// English language (Nigeria). + /// + en_NG, + + /// + /// English language (United States). + /// + en_US, + + /// + /// English language (South Africa). + /// + en_ZA, + + /// + /// Spanish language. + /// + es, + + /// + /// Spanish language (Mexico). + /// + es_MX, + + /// + /// Persian language (Iran). + /// + fa, + + /// + /// Finnish language (Finland). + /// + fi, + + /// + /// French language (France). + /// + fr, + + /// + /// French language (Canada). + /// + fr_CA, + + /// + /// French language (Switzerland). + /// + fr_CH, + + /// + /// Georgian language (Georgia). + /// + ge, + + /// + /// Croatian language (Croatia). + /// + hr, + + /// + /// Indonesian language (Indonesia). + /// + id_ID, + + /// + /// Italian language (Italy). + /// + it, + + /// + /// Japanese language (Japan). + /// + ja, + + /// + /// Korean language (South Korea). + /// + ko, + + /// + /// Latvian language (Latvia). + /// + lv, + + /// + /// Norwegian language (Bokmål dialect, Norway). + /// + nb_NO, + + /// + /// Nepali language (Nepal). + /// + ne, + + /// + /// Dutch language (Netherlands). + /// + nl, + + /// + /// Dutch language (Belgium). + /// + nl_BE, + + /// + /// Polish language (Poland). + /// + pl, + + /// + /// Portuguese language (Brazil). + /// + pt_BR, + + /// + /// Portuguese language (Portugal). + /// + pt_PT, + + /// + /// Romanian language (Romania). + /// + ro, + + /// + /// Russian language (Russia). + /// + ru, + + /// + /// Slovak language (Slovakia). + /// + sk, + + /// + /// Swedish language (Sweden). + /// + sv, + + /// + /// Turkish language (Turkey). + /// + tr, + + /// + /// Ukrainian language (Ukraine). + /// + uk, + + /// + /// Vietnamese language (Vietnam). + /// + vi, + + /// + /// Chinese language (Simplified, China). + /// + zh_CN, + + /// + /// Chinese language (Traditional, Taiwan). + /// + zh_TW, + + /// + /// Zulu language (South Africa). + /// + zu_ZA +}