From 743729cb48edce233ca2bc9cae8c34ee49cba874 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 16 Feb 2024 22:00:21 +1100 Subject: [PATCH] target typed new. and collection expressions (#1362) --- .../ArticlePrefixSortTests.cs | 2 +- .../CollectionHumanizeTests.cs | 14 +- src/Humanizer.Tests.Shared/DateHumanize.cs | 2 +- src/Humanizer.Tests.Shared/InflectorTests.cs | 442 +++++++++--------- .../ResourceKeyTests.cs | 129 +++-- src/Humanizer/HeadingExtensions.cs | 7 +- .../Formatters/MalteseFormatter.cs | 6 +- .../AfrikaansNumberToWordsConverter.cs | 9 +- .../ArabicNumberToWordsConverter.cs | 25 +- .../ArmenianNumberToWordsConverter.cs | 9 +- .../AzerbaijaniNumberToWordsConverter.cs | 9 +- .../BanglaNumberToWordsConverter.cs | 83 ++-- ...azilianPortugueseNumberToWordsConverter.cs | 15 +- .../BulgarianNumberToWordsConverter.cs | 20 +- .../CentralKurdishNumberToWordsConverter.cs | 6 +- .../ChineseNumberToWordsConverter.cs | 2 +- .../CroatianNumberToWordsConverter.cs | 14 +- .../CzechNumberToWordsConverter.cs | 32 +- .../DutchNumberToWordsConverter.cs | 29 +- .../EnglishNumberToWordsConverter.cs | 6 +- .../FarsiNumberToWordsConverter.cs | 6 +- .../FinnishNumberToWordsConverter.cs | 6 +- .../FrenchNumberToWordsConverterBase.cs | 4 +- .../GermanNumberToWordsConverterBase.cs | 22 +- .../GreekNumberToWordsConverter.cs | 12 +- .../HebrewNumberToWordsConverter.cs | 25 +- .../IcelandicNumberToWordsConverter.cs | 30 +- .../IndianNumberToWordsConverter.cs | 16 +- .../Italian/ItalianCardinalNumberCruncher.cs | 24 +- .../Italian/ItalianOrdinalNumberCruncher.cs | 6 +- .../JapaneseNumberToWordsConverter.cs | 11 +- .../KoreanNumberToWordsConverter.cs | 8 +- .../LatvianNumberToWordsConverter.cs | 8 +- .../LithuanianNumberToWordsConverter.cs | 12 +- .../LuxembourgishNumberToWordsConverter.cs | 22 +- .../MalteseNumberToWordsConvertor.cs | 18 +- .../NorwegianBokmalNumberToWordsConverter.cs | 6 +- .../PolishNumberToWordsConverter.cs | 38 +- .../PortugueseNumberToWordsConverter.cs | 12 +- .../RomanianCardinalNumberConverter.cs | 36 +- .../RomanianOrdinalNumberConverter.cs | 24 +- .../RussianNumberToWordsConverter.cs | 14 +- .../SerbianCyrlNumberToWordsConverter.cs | 14 +- .../SerbianNumberToWordsConverter.cs | 14 +- .../SlovenianNumberToWordsConverter.cs | 14 +- .../SpanishNumberToWordsConverter.cs | 61 ++- .../SwedishNumberToWordsConverter.cs | 24 +- .../TamilNumberToWordsConverter.cs | 12 +- .../TurkishNumberToWordConverter.cs | 11 +- .../UkrainianNumberToWordsConverter.cs | 14 +- .../UzbekCyrlNumberToWordConverter.cs | 6 +- .../UzbekLatnNumberToWordConverter.cs | 6 +- .../VietnameseNumberToWordsConverter.cs | 4 +- src/Humanizer/Localisation/Resources.cs | 2 +- src/Humanizer/MetricNumeralExtensions.cs | 27 +- src/Humanizer/RomanNumeralExtensions.cs | 2 +- src/Humanizer/StringHumanizeExtensions.cs | 2 +- src/Humanizer/TimeSpanHumanizeExtensions.cs | 4 +- 58 files changed, 714 insertions(+), 724 deletions(-) diff --git a/src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs b/src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs index 8a8943662..a37fc8e3a 100644 --- a/src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs +++ b/src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs @@ -12,7 +12,7 @@ public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expe [Fact] public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException() { - string[] items = { }; + string[] items = []; void action() => EnglishArticle.AppendArticlePrefix(items); Assert.Throws(action); } diff --git a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs index a6ce3f23e..307461759 100644 --- a/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs @@ -56,12 +56,12 @@ public void HumanizeUsesOxfordComma() Assert.Equal("A String, Another String, or A Third String", collection.Humanize("or")); } - private readonly List _testCollection = new List - { - new SomeClass { SomeInt = 1, SomeString = "One" }, - new SomeClass { SomeInt = 2, SomeString = "Two" }, - new SomeClass { SomeInt = 3, SomeString = "Three" } - }; + private readonly List _testCollection = + [ + new() { SomeInt = 1, SomeString = "One" }, + new() { SomeInt = 2, SomeString = "Two" }, + new() { SomeInt = 3, SomeString = "Three" } + ]; [Fact] public void HumanizeDefaultsToToString() => @@ -128,4 +128,4 @@ public void HumanizeTrimsItemsByDefault() => /// private static readonly Func dummyFormatter = input => input; } -} +} \ No newline at end of file diff --git a/src/Humanizer.Tests.Shared/DateHumanize.cs b/src/Humanizer.Tests.Shared/DateHumanize.cs index a18628f22..d15da5bf1 100644 --- a/src/Humanizer.Tests.Shared/DateHumanize.cs +++ b/src/Humanizer.Tests.Shared/DateHumanize.cs @@ -2,7 +2,7 @@ { public class DateHumanize { - private static readonly object LockObject = new object(); + private static readonly object LockObject = new(); private static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow, CultureInfo culture) { diff --git a/src/Humanizer.Tests.Shared/InflectorTests.cs b/src/Humanizer.Tests.Shared/InflectorTests.cs index 80cfefafb..9c622a276 100644 --- a/src/Humanizer.Tests.Shared/InflectorTests.cs +++ b/src/Humanizer.Tests.Shared/InflectorTests.cs @@ -156,241 +156,241 @@ internal class PluralTestSource : IEnumerable { public IEnumerator GetEnumerator() { - yield return new object[] { "search", "searches" }; - yield return new object[] { "switch", "switches" }; - yield return new object[] { "fix", "fixes" }; - yield return new object[] { "box", "boxes" }; - yield return new object[] { "process", "processes" }; - yield return new object[] { "address", "addresses" }; - yield return new object[] { "case", "cases" }; - yield return new object[] { "stack", "stacks" }; - yield return new object[] { "wish", "wishes" }; - yield return new object[] { "fish", "fish" }; - - yield return new object[] { "category", "categories" }; - yield return new object[] { "query", "queries" }; - yield return new object[] { "ability", "abilities" }; - yield return new object[] { "agency", "agencies" }; - yield return new object[] { "movie", "movies" }; - - yield return new object[] { "archive", "archives" }; - - yield return new object[] { "index", "indices" }; - - yield return new object[] { "wife", "wives" }; - yield return new object[] { "safe", "saves" }; - yield return new object[] { "half", "halves" }; - - yield return new object[] { "glove", "gloves" }; - yield return new object[] { "move", "moves" }; - - yield return new object[] { "salesperson", "salespeople" }; - yield return new object[] { "person", "people" }; - - yield return new object[] { "spokesman", "spokesmen" }; - yield return new object[] { "man", "men" }; - yield return new object[] { "woman", "women" }; - yield return new object[] { "freshman", "freshmen" }; - yield return new object[] { "chairman", "chairmen" }; - yield return new object[] { "human", "humans" }; - yield return new object[] { "personnel", "personnel" }; - yield return new object[] { "staff", "staff" }; - yield return new object[] { "training", "training" }; - - yield return new object[] { "basis", "bases" }; - yield return new object[] { "diagnosis", "diagnoses" }; - - yield return new object[] { "datum", "data" }; - yield return new object[] { "medium", "media" }; - yield return new object[] { "analysis", "analyses" }; - - yield return new object[] { "node_child", "node_children" }; - yield return new object[] { "child", "children" }; - - yield return new object[] { "experience", "experiences" }; - yield return new object[] { "day", "days" }; - - yield return new object[] { "comment", "comments" }; - yield return new object[] { "foobar", "foobars" }; - yield return new object[] { "newsletter", "newsletters" }; - - yield return new object[] { "old_news", "old_news" }; - yield return new object[] { "news", "news" }; - - yield return new object[] { "series", "series" }; - yield return new object[] { "species", "species" }; - - yield return new object[] { "quiz", "quizzes" }; - - yield return new object[] { "perspective", "perspectives" }; - - yield return new object[] { "ox", "oxen" }; - yield return new object[] { "photo", "photos" }; - yield return new object[] { "buffalo", "buffaloes" }; - yield return new object[] { "tomato", "tomatoes" }; - yield return new object[] { "dwarf", "dwarves" }; - yield return new object[] { "elf", "elves" }; - yield return new object[] { "information", "information" }; - yield return new object[] { "equipment", "equipment" }; - yield return new object[] { "bus", "buses" }; - yield return new object[] { "status", "statuses" }; - yield return new object[] { "status_code", "status_codes" }; - yield return new object[] { "mouse", "mice" }; - - yield return new object[] { "louse", "lice" }; - yield return new object[] { "house", "houses" }; - yield return new object[] { "octopus", "octopi" }; - yield return new object[] { "alias", "aliases" }; - yield return new object[] { "portfolio", "portfolios" }; - yield return new object[] { "criterion", "criteria" }; - - yield return new object[] { "vertex", "vertices" }; - yield return new object[] { "matrix", "matrices" }; - - yield return new object[] { "axis", "axes" }; - yield return new object[] { "testis", "testes" }; - yield return new object[] { "crisis", "crises" }; - - yield return new object[] { "corn", "corn" }; - yield return new object[] { "milk", "milk" }; - yield return new object[] { "rice", "rice" }; - yield return new object[] { "shoe", "shoes" }; - - yield return new object[] { "horse", "horses" }; - yield return new object[] { "prize", "prizes" }; - yield return new object[] { "edge", "edges" }; + yield return ["search", "searches"]; + yield return ["switch", "switches"]; + yield return ["fix", "fixes"]; + yield return ["box", "boxes"]; + yield return ["process", "processes"]; + yield return ["address", "addresses"]; + yield return ["case", "cases"]; + yield return ["stack", "stacks"]; + yield return ["wish", "wishes"]; + yield return ["fish", "fish"]; + + yield return ["category", "categories"]; + yield return ["query", "queries"]; + yield return ["ability", "abilities"]; + yield return ["agency", "agencies"]; + yield return ["movie", "movies"]; + + yield return ["archive", "archives"]; + + yield return ["index", "indices"]; + + yield return ["wife", "wives"]; + yield return ["safe", "saves"]; + yield return ["half", "halves"]; + + yield return ["glove", "gloves"]; + yield return ["move", "moves"]; + + yield return ["salesperson", "salespeople"]; + yield return ["person", "people"]; + + yield return ["spokesman", "spokesmen"]; + yield return ["man", "men"]; + yield return ["woman", "women"]; + yield return ["freshman", "freshmen"]; + yield return ["chairman", "chairmen"]; + yield return ["human", "humans"]; + yield return ["personnel", "personnel"]; + yield return ["staff", "staff"]; + yield return ["training", "training"]; + + yield return ["basis", "bases"]; + yield return ["diagnosis", "diagnoses"]; + + yield return ["datum", "data"]; + yield return ["medium", "media"]; + yield return ["analysis", "analyses"]; + + yield return ["node_child", "node_children"]; + yield return ["child", "children"]; + + yield return ["experience", "experiences"]; + yield return ["day", "days"]; + + yield return ["comment", "comments"]; + yield return ["foobar", "foobars"]; + yield return ["newsletter", "newsletters"]; + + yield return ["old_news", "old_news"]; + yield return ["news", "news"]; + + yield return ["series", "series"]; + yield return ["species", "species"]; + + yield return ["quiz", "quizzes"]; + + yield return ["perspective", "perspectives"]; + + yield return ["ox", "oxen"]; + yield return ["photo", "photos"]; + yield return ["buffalo", "buffaloes"]; + yield return ["tomato", "tomatoes"]; + yield return ["dwarf", "dwarves"]; + yield return ["elf", "elves"]; + yield return ["information", "information"]; + yield return ["equipment", "equipment"]; + yield return ["bus", "buses"]; + yield return ["status", "statuses"]; + yield return ["status_code", "status_codes"]; + yield return ["mouse", "mice"]; + + yield return ["louse", "lice"]; + yield return ["house", "houses"]; + yield return ["octopus", "octopi"]; + yield return ["alias", "aliases"]; + yield return ["portfolio", "portfolios"]; + yield return ["criterion", "criteria"]; + + yield return ["vertex", "vertices"]; + yield return ["matrix", "matrices"]; + + yield return ["axis", "axes"]; + yield return ["testis", "testes"]; + yield return ["crisis", "crises"]; + + yield return ["corn", "corn"]; + yield return ["milk", "milk"]; + yield return ["rice", "rice"]; + yield return ["shoe", "shoes"]; + + yield return ["horse", "horses"]; + yield return ["prize", "prizes"]; + yield return ["edge", "edges"]; /* Tests added by Bas Jansen */ - yield return new object[] { "goose", "geese" }; - yield return new object[] { "deer", "deer" }; - yield return new object[] { "sheep", "sheep" }; - yield return new object[] { "wolf", "wolves" }; - yield return new object[] { "volcano", "volcanoes" }; - yield return new object[] { "aircraft", "aircraft" }; - yield return new object[] { "alumna", "alumnae" }; - yield return new object[] { "alumnus", "alumni" }; - yield return new object[] { "fungus", "fungi" }; - - yield return new object[] { "water", "water" }; - yield return new object[] { "waters", "waters" }; - yield return new object[] { "semen", "semen" }; - yield return new object[] { "sperm", "sperm" }; - - yield return new object[] { "wave", "waves" }; - - yield return new object[] { "campus", "campuses" }; - - yield return new object[] { "is", "are" }; - - yield return new object[] { "addendum", "addenda" }; - yield return new object[] { "alga", "algae" }; - yield return new object[] { "appendix", "appendices" }; - yield return new object[] { "bias", "biases" }; - yield return new object[] { "bison", "bison" }; - yield return new object[] { "blitz", "blitzes" }; - yield return new object[] { "buzz", "buzzes" }; - yield return new object[] { "cactus", "cacti" }; - yield return new object[] { "corps", "corps" }; - yield return new object[] { "curriculum", "curricula" }; - yield return new object[] { "database", "databases" }; - yield return new object[] { "die", "dice" }; - yield return new object[] { "echo", "echoes" }; - yield return new object[] { "ellipsis", "ellipses" }; - yield return new object[] { "elk", "elk" }; - yield return new object[] { "emphasis", "emphases" }; - yield return new object[] { "embargo", "embargoes" }; - yield return new object[] { "focus", "foci" }; - yield return new object[] { "foot", "feet" }; - yield return new object[] { "fuse", "fuses" }; - yield return new object[] { "grass", "grass" }; - yield return new object[] { "hair", "hair" }; - yield return new object[] { "hero", "heroes" }; - yield return new object[] { "hippopotamus", "hippopotami" }; - yield return new object[] { "hoof", "hooves" }; - yield return new object[] { "iris", "irises" }; - yield return new object[] { "larva", "larvae" }; - yield return new object[] { "leaf", "leaves" }; - yield return new object[] { "loaf", "loaves" }; - yield return new object[] { "luggage", "luggage" }; - yield return new object[] { "means", "means" }; - yield return new object[] { "mail", "mail" }; - yield return new object[] { "millennium", "millennia" }; - yield return new object[] { "moose", "moose" }; - yield return new object[] { "mosquito", "mosquitoes" }; - yield return new object[] { "mud", "mud" }; - yield return new object[] { "nucleus", "nuclei" }; - yield return new object[] { "neurosis", "neuroses" }; - yield return new object[] { "oasis", "oases" }; - yield return new object[] { "offspring", "offspring" }; - yield return new object[] { "paralysis", "paralyses" }; - yield return new object[] { "phenomenon", "phenomena" }; - yield return new object[] { "potato", "potatoes" }; - yield return new object[] { "radius", "radii" }; - yield return new object[] { "salmon", "salmon" }; - yield return new object[] { "scissors", "scissors" }; - yield return new object[] { "shrimp", "shrimp" }; - yield return new object[] { "someone", "someone" }; - yield return new object[] { "stimulus", "stimuli" }; - yield return new object[] { "swine", "swine" }; - yield return new object[] { "syllabus", "syllabi" }; - yield return new object[] { "that", "those" }; - yield return new object[] { "thief", "thieves" }; - yield return new object[] { "this", "these" }; - yield return new object[] { "tie", "ties" }; - yield return new object[] { "tooth", "teeth" }; - yield return new object[] { "torpedo", "torpedoes" }; - yield return new object[] { "trellis", "trellises" }; - yield return new object[] { "trout", "trout" }; - yield return new object[] { "tuna", "tuna" }; - yield return new object[] { "vertebra", "vertebrae" }; - yield return new object[] { "veto", "vetoes" }; - yield return new object[] { "virus", "viruses" }; - yield return new object[] { "walrus", "walruses" }; - yield return new object[] { "waltz", "waltzes" }; - yield return new object[] { "zombie", "zombies" }; - - yield return new object[] { "cookie", "cookies" }; - yield return new object[] { "bookie", "bookies" }; - yield return new object[] { "rookie", "rookies" }; - yield return new object[] { "roomie", "roomies" }; - yield return new object[] { "smoothie", "smoothies" }; + yield return ["goose", "geese"]; + yield return ["deer", "deer"]; + yield return ["sheep", "sheep"]; + yield return ["wolf", "wolves"]; + yield return ["volcano", "volcanoes"]; + yield return ["aircraft", "aircraft"]; + yield return ["alumna", "alumnae"]; + yield return ["alumnus", "alumni"]; + yield return ["fungus", "fungi"]; + + yield return ["water", "water"]; + yield return ["waters", "waters"]; + yield return ["semen", "semen"]; + yield return ["sperm", "sperm"]; + + yield return ["wave", "waves"]; + + yield return ["campus", "campuses"]; + + yield return ["is", "are"]; + + yield return ["addendum", "addenda"]; + yield return ["alga", "algae"]; + yield return ["appendix", "appendices"]; + yield return ["bias", "biases"]; + yield return ["bison", "bison"]; + yield return ["blitz", "blitzes"]; + yield return ["buzz", "buzzes"]; + yield return ["cactus", "cacti"]; + yield return ["corps", "corps"]; + yield return ["curriculum", "curricula"]; + yield return ["database", "databases"]; + yield return ["die", "dice"]; + yield return ["echo", "echoes"]; + yield return ["ellipsis", "ellipses"]; + yield return ["elk", "elk"]; + yield return ["emphasis", "emphases"]; + yield return ["embargo", "embargoes"]; + yield return ["focus", "foci"]; + yield return ["foot", "feet"]; + yield return ["fuse", "fuses"]; + yield return ["grass", "grass"]; + yield return ["hair", "hair"]; + yield return ["hero", "heroes"]; + yield return ["hippopotamus", "hippopotami"]; + yield return ["hoof", "hooves"]; + yield return ["iris", "irises"]; + yield return ["larva", "larvae"]; + yield return ["leaf", "leaves"]; + yield return ["loaf", "loaves"]; + yield return ["luggage", "luggage"]; + yield return ["means", "means"]; + yield return ["mail", "mail"]; + yield return ["millennium", "millennia"]; + yield return ["moose", "moose"]; + yield return ["mosquito", "mosquitoes"]; + yield return ["mud", "mud"]; + yield return ["nucleus", "nuclei"]; + yield return ["neurosis", "neuroses"]; + yield return ["oasis", "oases"]; + yield return ["offspring", "offspring"]; + yield return ["paralysis", "paralyses"]; + yield return ["phenomenon", "phenomena"]; + yield return ["potato", "potatoes"]; + yield return ["radius", "radii"]; + yield return ["salmon", "salmon"]; + yield return ["scissors", "scissors"]; + yield return ["shrimp", "shrimp"]; + yield return ["someone", "someone"]; + yield return ["stimulus", "stimuli"]; + yield return ["swine", "swine"]; + yield return ["syllabus", "syllabi"]; + yield return ["that", "those"]; + yield return ["thief", "thieves"]; + yield return ["this", "these"]; + yield return ["tie", "ties"]; + yield return ["tooth", "teeth"]; + yield return ["torpedo", "torpedoes"]; + yield return ["trellis", "trellises"]; + yield return ["trout", "trout"]; + yield return ["tuna", "tuna"]; + yield return ["vertebra", "vertebrae"]; + yield return ["veto", "vetoes"]; + yield return ["virus", "viruses"]; + yield return ["walrus", "walruses"]; + yield return ["waltz", "waltzes"]; + yield return ["zombie", "zombies"]; + + yield return ["cookie", "cookies"]; + yield return ["bookie", "bookies"]; + yield return ["rookie", "rookies"]; + yield return ["roomie", "roomies"]; + yield return ["smoothie", "smoothies"]; //Issue #789 - yield return new object[] { "cache", "caches" }; + yield return ["cache", "caches"]; //Issue #975, added by Alex Boutin - yield return new object[] { "ex", "exes" }; - yield return new object[] { "", "" }; + yield return ["ex", "exes"]; + yield return ["", ""]; //Issue #1100 - yield return new object[] { "doe", "does" }; - yield return new object[] { "hoe", "hoes" }; - yield return new object[] { "toe", "toes" }; - yield return new object[] { "woe", "woes" }; + yield return ["doe", "does"]; + yield return ["hoe", "hoes"]; + yield return ["toe", "toes"]; + yield return ["woe", "woes"]; //Issue #1132 - yield return new object[] { "metadata", "metadata" }; + yield return ["metadata", "metadata"]; //Issue #1154 - yield return new object[] { "a", "as" }; - yield return new object[] { "A", "As" }; - yield return new object[] { "s", "ss" }; - yield return new object[] { "S", "Ss" }; - yield return new object[] { "z", "zs" }; - yield return new object[] { "Z", "Zs" }; - yield return new object[] { "1", "1s" }; + yield return ["a", "as"]; + yield return ["A", "As"]; + yield return ["s", "ss"]; + yield return ["S", "Ss"]; + yield return ["z", "zs"]; + yield return ["Z", "Zs"]; + yield return ["1", "1s"]; //Issue #1252 - yield return new object[] { "pliers", "pliers" }; - yield return new object[] { "sheers", "sheers" }; - yield return new object[] { "valve", "valves" }; - yield return new object[] { "clothes", "clothes" }; - yield return new object[] { "lens", "lenses" }; - yield return new object[] { "apparatus", "apparatus" }; - yield return new object[] { "clove", "cloves" }; - yield return new object[] { "chassis", "chassis" }; - yield return new object[] { "explosive", "explosives" }; - yield return new object[] { "debris", "debris" }; + yield return ["pliers", "pliers"]; + yield return ["sheers", "sheers"]; + yield return ["valve", "valves"]; + yield return ["clothes", "clothes"]; + yield return ["lens", "lenses"]; + yield return ["apparatus", "apparatus"]; + yield return ["clove", "cloves"]; + yield return ["chassis", "chassis"]; + yield return ["explosive", "explosives"]; + yield return ["debris", "debris"]; } IEnumerator IEnumerable.GetEnumerator() => diff --git a/src/Humanizer.Tests.Shared/ResourceKeyTests.cs b/src/Humanizer.Tests.Shared/ResourceKeyTests.cs index cb9727b5c..95a4ac396 100644 --- a/src/Humanizer.Tests.Shared/ResourceKeyTests.cs +++ b/src/Humanizer.Tests.Shared/ResourceKeyTests.cs @@ -25,77 +25,74 @@ public void TimeSpanHumanizeKeysExistence(int instance, string expectedResourceK public static IEnumerable DateHumanizeResourceKeys => new[] { - new object[]{0, "DateHumanize_SingleSecondAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past) }, - new object[]{0, "DateHumanize_SingleMinuteAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past) }, - new object[]{0, "DateHumanize_SingleHourAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past) }, - new object[]{0, "DateHumanize_SingleDayAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past) }, - new object[]{0, "DateHumanize_SingleMonthAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past) }, - new object[]{0, "DateHumanize_SingleYearAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past) }, - new object[]{0, "DateHumanize_MultipleSecondsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_MultipleMinutesAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_MultipleHoursAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_MultipleDaysAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_MultipleMonthsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_MultipleYearsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 10) }, - new object[]{0, "DateHumanize_SingleSecondFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_SingleMinuteFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_SingleHourFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_SingleDayFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_SingleMonthFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_SingleYearFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 1) }, - new object[]{0, "DateHumanize_MultipleSecondsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 10) }, - new object[]{0, "DateHumanize_MultipleMinutesFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 10) }, - new object[]{0, "DateHumanize_MultipleHoursFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 10) }, - new object[]{0, "DateHumanize_MultipleDaysFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 10) }, - new object[]{0, "DateHumanize_MultipleMonthsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 10) }, - new object[]{0, "DateHumanize_MultipleYearsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 10) }, - - new object[]{0, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Millisecond, Tense.Past, count: 0) }, - new object[]{1, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 0) }, - new object[]{2, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 0) }, - new object[]{3, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 0) }, - new object[]{4, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 0) }, - new object[]{5, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Week, Tense.Past, count: 0) }, - new object[]{6, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 0) }, - new object[]{7, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 0) }, + [0, "DateHumanize_SingleSecondAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past)], + [0, "DateHumanize_SingleMinuteAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past)], + [0, "DateHumanize_SingleHourAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past)], + [0, "DateHumanize_SingleDayAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past)], + [0, "DateHumanize_SingleMonthAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past)], + [0, "DateHumanize_SingleYearAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past)], + [0, "DateHumanize_MultipleSecondsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 10)], + [0, "DateHumanize_MultipleMinutesAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 10)], + [0, "DateHumanize_MultipleHoursAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 10)], + [0, "DateHumanize_MultipleDaysAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 10)], + [0, "DateHumanize_MultipleMonthsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 10)], + [0, "DateHumanize_MultipleYearsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 10)], + [0, "DateHumanize_SingleSecondFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_SingleMinuteFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_SingleHourFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_SingleDayFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_SingleMonthFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_SingleYearFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 1)], + [0, "DateHumanize_MultipleSecondsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_MultipleMinutesFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_MultipleHoursFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_MultipleDaysFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_MultipleMonthsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_MultipleYearsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 10)], + [0, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Millisecond, Tense.Past, count: 0)], + [1, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 0)], + [2, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 0)], + [3, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 0)], + [4, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 0)], + [5, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Week, Tense.Past, count: 0)], + [6, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 0)], + [7, "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 0)], new object[]{8, "DateHumanize_Now", ResourceKeys.DateHumanize.Now } }; public static IEnumerable TimeSpanHumanizeResourceKeys => new[] { - new object[]{0, "TimeSpanHumanize_SingleMillisecond", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond) }, - new object[]{0, "TimeSpanHumanize_SingleSecond", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second) }, - new object[]{0, "TimeSpanHumanize_SingleMinute", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute) }, - new object[]{0, "TimeSpanHumanize_SingleHour", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour) }, - new object[]{0, "TimeSpanHumanize_SingleDay", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day) }, - new object[]{0, "TimeSpanHumanize_SingleWeek", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week) }, - new object[]{0, "TimeSpanHumanize_SingleMonth", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month) }, - new object[]{0, "TimeSpanHumanize_SingleYear", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year) }, - new object[]{0, "TimeSpanHumanize_MultipleMilliseconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleSeconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleMinutes", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleHours", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleDays", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleWeeks", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleMonths", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 10) }, - new object[]{0, "TimeSpanHumanize_MultipleYears", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year, 10) }, - - new object[]{0, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 0, true) }, - new object[]{1, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 0, true) }, - new object[]{2, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 0, true) }, - new object[]{3, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 0, true) }, - new object[]{4, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 0, true) }, - new object[]{5, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 0, true) }, - new object[]{6, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 0, true) }, - new object[]{7, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year, 0, true) }, - - new object[]{1, "TimeSpanHumanize_MultipleMilliseconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 0) }, - new object[]{2, "TimeSpanHumanize_MultipleSeconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 0) }, - new object[]{3, "TimeSpanHumanize_MultipleMinutes", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 0) }, - new object[]{4, "TimeSpanHumanize_MultipleHours", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 0) }, - new object[]{5, "TimeSpanHumanize_MultipleDays", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 0) }, - new object[]{6, "TimeSpanHumanize_MultipleWeeks", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 0) }, - new object[]{7, "TimeSpanHumanize_MultipleMonths", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 0) }, + [0, "TimeSpanHumanize_SingleMillisecond", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond)], + [0, "TimeSpanHumanize_SingleSecond", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second)], + [0, "TimeSpanHumanize_SingleMinute", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute)], + [0, "TimeSpanHumanize_SingleHour", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour)], + [0, "TimeSpanHumanize_SingleDay", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day)], + [0, "TimeSpanHumanize_SingleWeek", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week)], + [0, "TimeSpanHumanize_SingleMonth", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month)], + [0, "TimeSpanHumanize_SingleYear", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year)], + [0, "TimeSpanHumanize_MultipleMilliseconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 10)], + [0, "TimeSpanHumanize_MultipleSeconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 10)], + [0, "TimeSpanHumanize_MultipleMinutes", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 10)], + [0, "TimeSpanHumanize_MultipleHours", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 10)], + [0, "TimeSpanHumanize_MultipleDays", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 10)], + [0, "TimeSpanHumanize_MultipleWeeks", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 10)], + [0, "TimeSpanHumanize_MultipleMonths", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 10)], + [0, "TimeSpanHumanize_MultipleYears", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year, 10)], + [0, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 0, true)], + [1, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 0, true)], + [2, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 0, true)], + [3, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 0, true)], + [4, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 0, true)], + [5, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 0, true)], + [6, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 0, true)], + [7, "TimeSpanHumanize_Zero", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year, 0, true)], + [1, "TimeSpanHumanize_MultipleMilliseconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Millisecond, 0)], + [2, "TimeSpanHumanize_MultipleSeconds", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Second, 0)], + [3, "TimeSpanHumanize_MultipleMinutes", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Minute, 0)], + [4, "TimeSpanHumanize_MultipleHours", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Hour, 0)], + [5, "TimeSpanHumanize_MultipleDays", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Day, 0)], + [6, "TimeSpanHumanize_MultipleWeeks", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Week, 0)], + [7, "TimeSpanHumanize_MultipleMonths", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Month, 0)], new object[]{8, "TimeSpanHumanize_MultipleYears", ResourceKeys.TimeSpanHumanize.GetResourceKey(TimeUnit.Year, 0) } }; } diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 6f9bc26fa..5e9bdd02b 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -22,8 +22,8 @@ public enum HeadingStyle /// public static class HeadingExtensions { - internal static readonly string[] Headings = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" }; - internal static readonly char[] HeadingArrows = { '↑', '↗', '→', '↘', '↓', '↙', '←', '↖' }; + internal static readonly string[] Headings = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]; + internal static readonly char[] HeadingArrows = ['↑', '↗', '→', '↘', '↓', '↙', '←', '↖']; // https://stackoverflow.com/a/7490772/1720761 /// @@ -46,8 +46,7 @@ public static string ToHeading(this double heading, HeadingStyle style = Heading return Resources.GetResource($"{result}_Short", culture); } - result = Resources.GetResource(result, culture); - return result; + return Resources.GetResource(result, culture); } /// diff --git a/src/Humanizer/Localisation/Formatters/MalteseFormatter.cs b/src/Humanizer/Localisation/Formatters/MalteseFormatter.cs index 86d668555..bddd93cec 100644 --- a/src/Humanizer/Localisation/Formatters/MalteseFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/MalteseFormatter.cs @@ -5,13 +5,13 @@ internal class MalteseFormatter(string localeCode) : { private const string DualPostfix = "_Dual"; - private static readonly string[] DualResourceKeys = new[] - { + private static readonly string[] DualResourceKeys = + [ "DateHumanize_MultipleDaysAgo", "DateHumanize_MultipleDaysFromNow", "DateHumanize_MultipleHoursAgo", "DateHumanize_MultipleHoursFromNow" , "DateHumanize_MultipleMonthsAgo", "DateHumanize_MultipleMonthsFromNow", "DateHumanize_MultipleYearsAgo", "DateHumanize_MultipleYearsFromNow", "TimeSpanHumanize_MultipleDays", "TimeSpanHumanize_MultipleYears", "TimeSpanHumanize_MultipleMonths", "TimeSpanHumanize_MultipleHours", "TimeSpanHumanize_MultipleWeeks" - }; + ]; protected override string GetResourceKey(string resourceKey, int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs index 91b55d56f..52efb83d3 100644 --- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs @@ -1,11 +1,12 @@ namespace Humanizer { - internal class AfrikaansNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class AfrikaansNumberToWordsConverter : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nul", "een", "twee", "drie", "vier", "vyf", "ses", "sewe", "agt", "nege", "tien", "elf", "twaalf", "dertien", "veertien", "vyftien", "sestien", "sewentien", "agtien", "negentien" }; - private static readonly string[] TensMap = { "nul", "tien", "twintig", "dertig", "veertig", "vyftig", "sestig", "sewentig", "tagtig", "negentig" }; + private static readonly string[] UnitsMap = ["nul", "een", "twee", "drie", "vier", "vyf", "ses", "sewe", "agt", "nege", "tien", "elf", "twaalf", "dertien", "veertien", "vyftien", "sestien", "sewentien", "agtien", "negentien"]; + private static readonly string[] TensMap = ["nul", "tien", "twintig", "dertig", "veertig", "vyftig", "sestig", "sewentig", "tagtig", "negentig"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {0, "nulste"}, {1, "eerste"}, diff --git a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs index 760779442..045d641de 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs @@ -1,17 +1,18 @@ namespace Humanizer { - internal class ArabicNumberToWordsConverter : GenderedNumberToWordsConverter + internal class ArabicNumberToWordsConverter : + GenderedNumberToWordsConverter { - private static readonly string[] Groups = { "مئة", "ألف", "مليون", "مليار", "تريليون", "كوادريليون", "كوينتليون", "سكستيليون" }; - private static readonly string[] AppendedGroups = { "", "ألفاً", "مليوناً", "ملياراً", "تريليوناً", "كوادريليوناً", "كوينتليوناً", "سكستيليوناً" }; - private static readonly string[] PluralGroups = { "", "آلاف", "ملايين", "مليارات", "تريليونات", "كوادريليونات", "كوينتليونات", "سكستيليونات" }; - private static readonly string[] OnesGroup = { "", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة", "عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر" }; - private static readonly string[] TensGroup = { "", "عشرة", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون" }; - private static readonly string[] HundredsGroup = { "", "مئة", "مئتان", "ثلاث مئة", "أربع مئة", "خمس مئة", "ست مئة", "سبع مئة", "ثمان مئة", "تسع مئة" }; - private static readonly string[] AppendedTwos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن" }; - private static readonly string[] Twos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان" }; + private static readonly string[] Groups = ["مئة", "ألف", "مليون", "مليار", "تريليون", "كوادريليون", "كوينتليون", "سكستيليون"]; + private static readonly string[] AppendedGroups = ["", "ألفاً", "مليوناً", "ملياراً", "تريليوناً", "كوادريليوناً", "كوينتليوناً", "سكستيليوناً"]; + private static readonly string[] PluralGroups = ["", "آلاف", "ملايين", "مليارات", "تريليونات", "كوادريليونات", "كوينتليونات", "سكستيليونات"]; + private static readonly string[] OnesGroup = ["", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة", "عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"]; + private static readonly string[] TensGroup = ["", "عشرة", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"]; + private static readonly string[] HundredsGroup = ["", "مئة", "مئتان", "ثلاث مئة", "أربع مئة", "خمس مئة", "ست مئة", "سبع مئة", "ثمان مئة", "تسع مئة"]; + private static readonly string[] AppendedTwos = ["مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن"]; + private static readonly string[] Twos = ["مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان"]; - private static readonly string[] FeminineOnesGroup = { "", "واحدة", "اثنتان", "ثلاث", "أربع", "خمس", "ست", "سبع", "ثمان", "تسع", "عشر", "إحدى عشرة", "اثنتا عشرة", "ثلاث عشرة", "أربع عشرة", "خمس عشرة", "ست عشرة", "سبع عشرة", "ثمان عشرة", "تسع عشرة" }; + private static readonly string[] FeminineOnesGroup = ["", "واحدة", "اثنتان", "ثلاث", "أربع", "خمس", "ست", "سبع", "ثمان", "تسع", "عشر", "إحدى عشرة", "اثنتا عشرة", "ثلاث عشرة", "أربع عشرة", "خمس عشرة", "ست عشرة", "سبع عشرة", "ثمان عشرة", "تسع عشرة"]; public override string Convert(long number, GrammaticalGender gender, bool addAnd = true) { @@ -143,7 +144,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn return result.Trim(); } - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {"واحد", "الحادي"}, {"أحد", "الحادي"}, @@ -159,7 +160,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn {"عشرة", "العاشر"}, }; - private static readonly Dictionary FeminineOrdinalExceptions = new Dictionary + private static readonly Dictionary FeminineOrdinalExceptions = new() { {"واحدة", "الحادية"}, {"إحدى", "الحادية"}, diff --git a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs index a39ff8d49..089adc202 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArmenianNumberToWordsConverter.cs @@ -1,11 +1,12 @@ namespace Humanizer { - internal class ArmenianNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class ArmenianNumberToWordsConverter : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "զրո", "մեկ", "երկու", "երեք", "չորս", "հինգ", "վեց", "յոթ", "ութ", "ինը", "տաս", "տասնմեկ", "տասներկու", "տասներեք", "տասնչորս", "տասնհինգ", "տասնվեց", "տասնյոթ", "տասնութ", "տասնինը" }; - private static readonly string[] TensMap = { "զրո", "տաս", "քսան", "երեսուն", "քառասուն", "հիսուն", "վաթսուն", "յոթանասուն", "ութսուն", "իննսուն" }; + private static readonly string[] UnitsMap = ["զրո", "մեկ", "երկու", "երեք", "չորս", "հինգ", "վեց", "յոթ", "ութ", "ինը", "տաս", "տասնմեկ", "տասներկու", "տասներեք", "տասնչորս", "տասնհինգ", "տասնվեց", "տասնյոթ", "տասնութ", "տասնինը"]; + private static readonly string[] TensMap = ["զրո", "տաս", "քսան", "երեսուն", "քառասուն", "հիսուն", "վաթսուն", "յոթանասուն", "ութսուն", "իննսուն"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {0, "զրոյական"}, {1, "առաջին"}, diff --git a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs index f33536b25..ad1632cb7 100644 --- a/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AzerbaijaniNumberToWordsConverter.cs @@ -1,11 +1,12 @@ namespace Humanizer { - internal class AzerbaijaniNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class AzerbaijaniNumberToWordsConverter : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "sıfır", "bir", "iki", "üç", "dörd", "beş", "altı", "yeddi", "səkkiz", "doqquz" }; - private static readonly string[] TensMap = { "sıfır", "on", "iyirmi", "otuz", "qırx", "əlli", "altmış", "yetmiş", "səksən", "doxsan" }; + private static readonly string[] UnitsMap = ["sıfır", "bir", "iki", "üç", "dörd", "beş", "altı", "yeddi", "səkkiz", "doqquz"]; + private static readonly string[] TensMap = ["sıfır", "on", "iyirmi", "otuz", "qırx", "əlli", "altmış", "yetmiş", "səksən", "doxsan"]; - private static readonly Dictionary OrdinalSuffix = new Dictionary + private static readonly Dictionary OrdinalSuffix = new() { {'ı', "ıncı"}, {'i', "inci"}, diff --git a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs index f1cf71165..51779860d 100644 --- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs @@ -1,51 +1,52 @@ namespace Humanizer { - internal class BanglaNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class BanglaNumberToWordsConverter : + GenderlessNumberToWordsConverter { private static readonly string[] UnitsMap = - { - "শূন্য", "এক", "দুই", "তিন", "চার", "পাঁচ", "ছয়", "সাত", "আট", "নয়", "দশ", - "এগারো", "বারো", "তেরো", "চোদ্দ", "পনেরো", "ষোল", "সতেরো", "আঠারো", "উনিশ", "বিশ", - "একুশ", "বাইশ", "তেইশ", "চব্বিশ", "পঁচিশ", "ছাব্বিশ", "সাতাশ", "আঠাশ", "উনতিরিশ", "তিরিশ", - "একতিরিশ", "বত্রিশ", "তেত্রিশ", "চৌঁতিরিশ", "পঁয়তিরিশ", "ছত্রিশ", "সাঁইতিরিশ", "আটতিরিশ", "উনচল্লিশ","চল্লিশ", - "একচল্লিশ", "বিয়াল্লিশ", "তেতাল্লিশ", "চুয়াল্লিশ", "পঁয়তাল্লিশ", "ছেচাল্লিশ", "সাতচল্লিশ", "আটচল্লিশ","উনপঞ্চাশ", "পঞ্চাশ", - "একান্ন", "বাহান্ন", "তিপ্পান্ন", "চুয়ান্ন", "পঞ্চান্ন", "ছাপ্পান্ন", "সাতান্ন", "আটান্ন", "উনষাট","ষাট", - "একষট্টি", "বাষট্টি", "তেষট্টি", "চৌষট্টি", "পঁয়ষট্টি", "ছেষট্টি", "সাতষট্টি", "আটষট্টি", "উনসত্তর","সত্তর", - "একাত্তর", "বাহাত্তর", "তিয়াত্তর", "চুয়াত্তর", "পঁচাত্তর", "ছিয়াত্তর", "সাতাত্তর", "আটাত্তর", "উনআশি", "আশি", - "একাশি", "বিরাশি", "তিরাশি", "চুরাশি", "পঁচাশি", "ছিয়াশি", "সাতাশি", "আটাশি", "উননব্বই", "নব্বই", - "একানব্বই", "বিরানব্বই", "তিরানব্বিই", "চুরানব্বই", "পঁচানব্বই", "ছিয়ানব্বই", "সাতানব্বই", "আটানব্বই","নিরানব্বই" - }; + [ + "শূন্য", "এক", "দুই", "তিন", "চার", "পাঁচ", "ছয়", "সাত", "আট", "নয়", "দশ", + "এগারো", "বারো", "তেরো", "চোদ্দ", "পনেরো", "ষোল", "সতেরো", "আঠারো", "উনিশ", "বিশ", + "একুশ", "বাইশ", "তেইশ", "চব্বিশ", "পঁচিশ", "ছাব্বিশ", "সাতাশ", "আঠাশ", "উনতিরিশ", "তিরিশ", + "একতিরিশ", "বত্রিশ", "তেত্রিশ", "চৌঁতিরিশ", "পঁয়তিরিশ", "ছত্রিশ", "সাঁইতিরিশ", "আটতিরিশ", "উনচল্লিশ","চল্লিশ", + "একচল্লিশ", "বিয়াল্লিশ", "তেতাল্লিশ", "চুয়াল্লিশ", "পঁয়তাল্লিশ", "ছেচাল্লিশ", "সাতচল্লিশ", "আটচল্লিশ","উনপঞ্চাশ", "পঞ্চাশ", + "একান্ন", "বাহান্ন", "তিপ্পান্ন", "চুয়ান্ন", "পঞ্চান্ন", "ছাপ্পান্ন", "সাতান্ন", "আটান্ন", "উনষাট","ষাট", + "একষট্টি", "বাষট্টি", "তেষট্টি", "চৌষট্টি", "পঁয়ষট্টি", "ছেষট্টি", "সাতষট্টি", "আটষট্টি", "উনসত্তর","সত্তর", + "একাত্তর", "বাহাত্তর", "তিয়াত্তর", "চুয়াত্তর", "পঁচাত্তর", "ছিয়াত্তর", "সাতাত্তর", "আটাত্তর", "উনআশি", "আশি", + "একাশি", "বিরাশি", "তিরাশি", "চুরাশি", "পঁচাশি", "ছিয়াশি", "সাতাশি", "আটাশি", "উননব্বই", "নব্বই", + "একানব্বই", "বিরানব্বই", "তিরানব্বিই", "চুরানব্বই", "পঁচানব্বই", "ছিয়ানব্বই", "সাতানব্বই", "আটানব্বই","নিরানব্বই" + ]; private static readonly string[] HundredsMap = - { - "শূন্য", "একশ", "দুইশ", "তিনশ", "চারশ", "পাঁচশ", "ছয়শ", "সাতশ","আটশ", "নয়শ" - }; + [ + "শূন্য", "একশ", "দুইশ", "তিনশ", "চারশ", "পাঁচশ", "ছয়শ", "সাতশ","আটশ", "নয়শ" + ]; - private static readonly Dictionary OrdinalExceptions = new Dictionary - { - {1, "প্রথম"}, - {2, "দ্বিতীয়"}, - {3, "তৃতীয়"}, - {4, "চতুর্থ"}, - {5, "পঞ্চম"}, - {6, "ষষ্ট"}, - {7, "সপ্তম"}, - {8, "অষ্টম"}, - {9, "নবম"}, - {10, "দশম"}, - {11, "একাদশ"}, - {12, "দ্বাদশ"}, - {13, "ত্রয়োদশ"}, - {14, "চতুর্দশ"}, - {15, "পঞ্চদশ"}, - {16, "ষোড়শ"}, - {17, "সপ্তদশ"}, - {18, "অষ্টাদশ"}, - {100, "শত তম"}, - {1000, "হাজার তম"}, - {100000, "লক্ষ তম"}, - {10000000, "কোটি তম"}, - }; + private static readonly Dictionary OrdinalExceptions = new() + { + {1, "প্রথম"}, + {2, "দ্বিতীয়"}, + {3, "তৃতীয়"}, + {4, "চতুর্থ"}, + {5, "পঞ্চম"}, + {6, "ষষ্ট"}, + {7, "সপ্তম"}, + {8, "অষ্টম"}, + {9, "নবম"}, + {10, "দশম"}, + {11, "একাদশ"}, + {12, "দ্বাদশ"}, + {13, "ত্রয়োদশ"}, + {14, "চতুর্দশ"}, + {15, "পঞ্চদশ"}, + {16, "ষোড়শ"}, + {17, "সপ্তদশ"}, + {18, "অষ্টাদশ"}, + {100, "শত তম"}, + {1000, "হাজার তম"}, + {100000, "লক্ষ তম"}, + {10000000, "কোটি তম"}, + }; public override string ConvertToOrdinal(int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs index 95d326bfa..e755f9e78 100644 --- a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -1,14 +1,15 @@ namespace Humanizer { - internal class BrazilianPortugueseNumberToWordsConverter : GenderedNumberToWordsConverter + internal class BrazilianPortugueseNumberToWordsConverter : + GenderedNumberToWordsConverter { - private static readonly string[] PortugueseUnitsMap = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove" }; - private static readonly string[] PortugueseTensMap = { "zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa" }; - private static readonly string[] PortugueseHundredsMap = { "zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos" }; + private static readonly string[] PortugueseUnitsMap = ["zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove"]; + private static readonly string[] PortugueseTensMap = ["zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa"]; + private static readonly string[] PortugueseHundredsMap = ["zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos"]; - private static readonly string[] PortugueseOrdinalUnitsMap = { "zero", "primeiro", "segundo", "terceiro", "quarto", "quinto", "sexto", "sétimo", "oitavo", "nono" }; - private static readonly string[] PortugueseOrdinalTensMap = { "zero", "décimo", "vigésimo", "trigésimo", "quadragésimo", "quinquagésimo", "sexagésimo", "septuagésimo", "octogésimo", "nonagésimo" }; - private static readonly string[] PortugueseOrdinalHundredsMap = { "zero", "centésimo", "ducentésimo", "trecentésimo", "quadringentésimo", "quingentésimo", "sexcentésimo", "septingentésimo", "octingentésimo", "noningentésimo" }; + private static readonly string[] PortugueseOrdinalUnitsMap = ["zero", "primeiro", "segundo", "terceiro", "quarto", "quinto", "sexto", "sétimo", "oitavo", "nono"]; + private static readonly string[] PortugueseOrdinalTensMap = ["zero", "décimo", "vigésimo", "trigésimo", "quadragésimo", "quinquagésimo", "sexagésimo", "septuagésimo", "octogésimo", "nonagésimo"]; + private static readonly string[] PortugueseOrdinalHundredsMap = ["zero", "centésimo", "ducentésimo", "trecentésimo", "quadringentésimo", "quingentésimo", "sexcentésimo", "septingentésimo", "octingentésimo", "noningentésimo"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs index 76f7aceaf..de0524e79 100644 --- a/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BulgarianNumberToWordsConverter.cs @@ -3,36 +3,36 @@ internal class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter { private static readonly string[] UnitsMap = - { + [ "нула", "едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет", "десет", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет" - }; + ]; private static readonly string[] TensMap = - { + [ "нула", "десет", "двадесет", "тридесет", "четиридесет", "петдесет", "шестдесет", "седемдесет", "осемдесет", "деветдесет" - }; + ]; private static readonly string[] HundredsMap = - { + [ "нула", "сто", "двеста", "триста", "четиристотин", "петстотин", "шестстотин", "седемстотин", "осемстотин", "деветстотин" - }; + ]; private static readonly string[] HundredsOrdinalMap = - { + [ string.Empty, "стот", "двест", "трист", "четиристот", "петстот", "шестстот", "седемстот", "осемстот", "деветстот" - }; + ]; private static readonly string[] UnitsOrdinal = - { + [ string.Empty, "първ", "втор", "трет", "четвърт", "пет", "шест", "седм", "осм", "девeт", "десeт", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет" - }; + ]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) => Convert(input, gender, false); diff --git a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs index df4adb350..4e76b02b8 100644 --- a/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.cs @@ -2,9 +2,9 @@ { internal class CentralKurdishNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] KurdishHundredsMap = { "سفر", "سەد", "دوو سەد", "سێ سەد", "چوار سەد", "پێنج سەد", "شەش سەد", "حەوت سەد", "هەشت سەد", "نۆ سەد" }; - private static readonly string[] KurdishTensMap = { "سفر", "دە", "بیست", "سی", "چل", "پەنجا", "شەست", "حەفتا", "هەشتا", "نەوەد" }; - private static readonly string[] KurdishUnitsMap = { "سفر", "یەک", "دوو", "سێ", "چوار", "پێنج", "شەش", "حەوت", "هەشت", "نۆ", "دە", "یازدە", "دوازدە", "سێزدە", "چواردە", "پازدە", "شازدە", "حەڤدە", "هەژدە", "نۆزدە" }; + private static readonly string[] KurdishHundredsMap = ["سفر", "سەد", "دوو سەد", "سێ سەد", "چوار سەد", "پێنج سەد", "شەش سەد", "حەوت سەد", "هەشت سەد", "نۆ سەد"]; + private static readonly string[] KurdishTensMap = ["سفر", "دە", "بیست", "سی", "چل", "پەنجا", "شەست", "حەفتا", "هەشتا", "نەوەد"]; + private static readonly string[] KurdishUnitsMap = ["سفر", "یەک", "دوو", "سێ", "چوار", "پێنج", "شەش", "حەوت", "هەشت", "نۆ", "دە", "یازدە", "دوازدە", "سێزدە", "چواردە", "پازدە", "شازدە", "حەڤدە", "هەژدە", "نۆزدە"]; public override string Convert(long number) { diff --git a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs index 63bab29cc..7755153b2 100644 --- a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs @@ -2,7 +2,7 @@ { internal class ChineseNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" }; + private static readonly string[] UnitsMap = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]; public override string Convert(long number) => Convert(number, false, IsSpecial(number)); diff --git a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs index 0f1aa90a3..8048f4407 100644 --- a/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CroatianNumberToWordsConverter.cs @@ -1,14 +1,10 @@ namespace Humanizer { - internal class CroatianNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class CroatianNumberToWordsConverter(CultureInfo culture) : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nula", "jedan", "dva", "tri", "četiri", "pet", "šest", "sedam", "osam", "devet", "deset", "jedanaest", "dvanaest", "trinaest", "četrnaest", "petnaest", "šestnaest", "sedemnaest", "osemnaest", "devetnaest" }; - private static readonly string[] TensMap = { "nula", "deset", "dvadeset", "trideset", "četrdeset", "petdeset", "šestdeset", "sedamdeset", "osamdeset", "devetdeset" }; - - private readonly CultureInfo _culture; - - public CroatianNumberToWordsConverter(CultureInfo culture) => - _culture = culture; + private static readonly string[] UnitsMap = ["nula", "jedan", "dva", "tri", "četiri", "pet", "šest", "sedam", "osam", "devet", "deset", "jedanaest", "dvanaest", "trinaest", "četrnaest", "petnaest", "šestnaest", "sedemnaest", "osemnaest", "devetnaest"]; + private static readonly string[] TensMap = ["nula", "deset", "dvadeset", "trideset", "četrdeset", "petdeset", "šestdeset", "sedamdeset", "osamdeset", "devetdeset"]; public override string Convert(long input) { @@ -103,7 +99,7 @@ public override string Convert(long input) public override string ConvertToOrdinal(int number) => //TODO: In progress - number.ToString(_culture); + number.ToString(culture); private string Part(string singular, string dual, string trialQuadral, string plural, int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs index b0d464f0b..b8a2aa5f0 100644 --- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs @@ -1,23 +1,19 @@ namespace Humanizer { - internal class CzechNumberToWordsConverter : GenderedNumberToWordsConverter + internal class CzechNumberToWordsConverter(CultureInfo culture) : + GenderedNumberToWordsConverter { - private static readonly string[] BillionsMap = { "miliarda", "miliardy", "miliard" }; - private static readonly string[] MillionsMap = { "milion", "miliony", "milionů" }; - private static readonly string[] ThousandsMap = { "tisíc", "tisíce", "tisíc" }; - private static readonly string[] HundredsMap = { "nula", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set" }; - private static readonly string[] TensMap = { "nula", "deset", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát" }; - private static readonly string[] UnitsMap = { "nula", "jeden", "dva", "tři", "čtyři", "pět", "šest", "sedm", "osm", "devět", "deset", "jedenáct", "dvanáct", "třináct", "čtrnáct", "patnáct", "šestnáct", "sedmnáct", "osmnáct", "devatenáct" }; - - private static readonly string[] UnitsMasculineOverrideMap = { "jeden", "dva" }; - private static readonly string[] UnitsFeminineOverrideMap = { "jedna", "dvě" }; - private static readonly string[] UnitsNeuterOverride = { "jedno", "dvě" }; - private static readonly string[] UnitsIntraOverride = { "jedna", "dva" }; - - private readonly CultureInfo _culture; - - public CzechNumberToWordsConverter(CultureInfo culture) => - _culture = culture; + private static readonly string[] BillionsMap = ["miliarda", "miliardy", "miliard"]; + private static readonly string[] MillionsMap = ["milion", "miliony", "milionů"]; + private static readonly string[] ThousandsMap = ["tisíc", "tisíce", "tisíc"]; + private static readonly string[] HundredsMap = ["nula", "sto", "dvě stě", "tři sta", "čtyři sta", "pět set", "šest set", "sedm set", "osm set", "devět set"]; + private static readonly string[] TensMap = ["nula", "deset", "dvacet", "třicet", "čtyřicet", "padesát", "šedesát", "sedmdesát", "osmdesát", "devadesát"]; + private static readonly string[] UnitsMap = ["nula", "jeden", "dva", "tři", "čtyři", "pět", "šest", "sedm", "osm", "devět", "deset", "jedenáct", "dvanáct", "třináct", "čtrnáct", "patnáct", "šestnáct", "sedmnáct", "osmnáct", "devatenáct"]; + + private static readonly string[] UnitsMasculineOverrideMap = ["jeden", "dva"]; + private static readonly string[] UnitsFeminineOverrideMap = ["jedna", "dvě"]; + private static readonly string[] UnitsNeuterOverride = ["jedno", "dvě"]; + private static readonly string[] UnitsIntraOverride = ["jedna", "dva"]; public override string Convert(long number, GrammaticalGender gender, bool addAnd = true) { @@ -43,7 +39,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn } public override string ConvertToOrdinal(int number, GrammaticalGender gender) => - number.ToString(_culture); + number.ToString(culture); private static string UnitByGender(long number, GrammaticalGender? gender) { diff --git a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs index 0fe5ec67c..b6faa0f29 100644 --- a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs @@ -6,10 +6,11 @@ /// Used the rules as stated here. /// http://www.beterspellen.nl/website/?pag=110 /// - internal class DutchNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class DutchNumberToWordsConverter : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nul", "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht", "negen", "tien", "elf", "twaalf", "dertien", "veertien", "vijftien", "zestien", "zeventien", "achttien", "negentien" }; - private static readonly string[] TensMap = { "nul", "tien", "twintig", "dertig", "veertig", "vijftig", "zestig", "zeventig", "tachtig", "negentig" }; + private static readonly string[] UnitsMap = ["nul", "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht", "negen", "tien", "elf", "twaalf", "dertien", "veertien", "vijftien", "zestien", "zeventien", "achttien", "negentien"]; + private static readonly string[] TensMap = ["nul", "tien", "twintig", "dertig", "veertig", "vijftig", "zestig", "zeventig", "tachtig", "negentig"]; private class Fact { @@ -21,15 +22,15 @@ private class Fact } private static readonly Fact[] Hunderds = - { - new Fact {Value = 1_000_000_000_000_000_000L, Name = "triljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 1_000_000_000_000_000L, Name = "biljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 1_000_000_000_000L, Name = "biljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 1000000000, Name = "miljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 1000000, Name = "miljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 1000, Name = "duizend", Prefix = "", Postfix = " ", DisplayOneUnit = false}, - new Fact {Value = 100, Name = "honderd", Prefix = "", Postfix = "", DisplayOneUnit = false} - }; + [ + new() {Value = 1_000_000_000_000_000_000L, Name = "triljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new() {Value = 1_000_000_000_000_000L, Name = "biljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new() {Value = 1_000_000_000_000L, Name = "biljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new() {Value = 1000000000, Name = "miljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new() {Value = 1000000, Name = "miljoen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new() {Value = 1000, Name = "duizend", Prefix = "", Postfix = " ", DisplayOneUnit = false}, + new() {Value = 100, Name = "honderd", Prefix = "", Postfix = "", DisplayOneUnit = false} + ]; public override string Convert(long input) { @@ -98,14 +99,14 @@ public override string Convert(long input) return word; } - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {"een", "eerste"}, {"drie", "derde"}, {"miljoen", "miljoenste"}, }; - private static readonly char[] EndingCharForSte = { 't', 'g', 'd' }; + private static readonly char[] EndingCharForSte = ['t', 'g', 'd']; public override string ConvertToOrdinal(int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index 15a09d303..146d3ed88 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -2,10 +2,10 @@ { internal class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; - private static readonly string[] TensMap = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; + private static readonly string[] UnitsMap = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]; + private static readonly string[] TensMap = ["zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {1, "first"}, {2, "second"}, diff --git a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs index 55e1f306f..35f9ce57a 100644 --- a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs @@ -2,9 +2,9 @@ { internal class FarsiNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] FarsiHundredsMap = { "صفر", "صد", "دویست", "سیصد", "چهارصد", "پانصد", "ششصد", "هفتصد", "هشتصد", "نهصد" }; - private static readonly string[] FarsiTensMap = { "صفر", "ده", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود" }; - private static readonly string[] FarsiUnitsMap = { "صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه", "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده" }; + private static readonly string[] FarsiHundredsMap = ["صفر", "صد", "دویست", "سیصد", "چهارصد", "پانصد", "ششصد", "هفتصد", "هشتصد", "نهصد"]; + private static readonly string[] FarsiTensMap = ["صفر", "ده", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود"]; + private static readonly string[] FarsiUnitsMap = ["صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه", "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده"]; public override string Convert(long number) { diff --git a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs index c85e1e218..2db4f1cf1 100644 --- a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs @@ -2,10 +2,10 @@ { internal class FinnishNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nolla", "yksi", "kaksi", "kolme", "neljä", "viisi", "kuusi", "seitsemän", "kahdeksan", "yhdeksän", "kymmenen" }; - private static readonly string[] OrdinalUnitsMap = { "nollas", "ensimmäinen", "toinen", "kolmas", "neljäs", "viides", "kuudes", "seitsemäs", "kahdeksas", "yhdeksäs", "kymmenes" }; + private static readonly string[] UnitsMap = ["nolla", "yksi", "kaksi", "kolme", "neljä", "viisi", "kuusi", "seitsemän", "kahdeksan", "yhdeksän", "kymmenen"]; + private static readonly string[] OrdinalUnitsMap = ["nollas", "ensimmäinen", "toinen", "kolmas", "neljäs", "viides", "kuudes", "seitsemäs", "kahdeksas", "yhdeksäs", "kymmenes"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {1, "yhdes" }, {2, "kahdes" } diff --git a/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverterBase.cs b/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverterBase.cs index 36c7ac6ac..64dc825f1 100644 --- a/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverterBase.cs +++ b/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverterBase.cs @@ -2,8 +2,8 @@ { internal abstract class FrenchNumberToWordsConverterBase : GenderedNumberToWordsConverter { - private static readonly string[] UnitsMap = { "zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf" }; - private static readonly string[] TensMap = { "zéro", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "septante", "octante", "nonante" }; + private static readonly string[] UnitsMap = ["zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf"]; + private static readonly string[] TensMap = ["zéro", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "septante", "octante", "nonante"]; public override string Convert(long number, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverterBase.cs b/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverterBase.cs index 637aca997..694bf91da 100644 --- a/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverterBase.cs +++ b/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverterBase.cs @@ -2,17 +2,17 @@ { internal abstract class GermanNumberToWordsConverterBase : GenderedNumberToWordsConverter { - private readonly string[] UnitsMap = { "null", "ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn" }; - private readonly string[] TensMap = { "null", "zehn", "zwanzig", "dreißig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig", "neunzig" }; - private readonly string[] UnitsOrdinal = { string.Empty, "ers", "zwei", "drit", "vier", "fünf", "sechs", "sieb", "ach", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn" }; - private readonly string[] HundredOrdinalSingular = { "einhundert" }; - private readonly string[] HundredOrdinalPlural = { "{0}hundert" }; - private readonly string[] ThousandOrdinalSingular = { "eintausend" }; - private readonly string[] ThousandOrdinalPlural = { "{0}tausend" }; - private readonly string[] MillionOrdinalSingular = { "einmillion", "einemillion" }; - private readonly string[] MillionOrdinalPlural = { "{0}million", "{0}millionen" }; - private readonly string[] BillionOrdinalSingular = { "einmilliard", "einemilliarde" }; - private readonly string[] BillionOrdinalPlural = { "{0}milliard", "{0}milliarden" }; + private readonly string[] UnitsMap = ["null", "ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn"]; + private readonly string[] TensMap = ["null", "zehn", "zwanzig", "dreißig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig", "neunzig"]; + private readonly string[] UnitsOrdinal = [string.Empty, "ers", "zwei", "drit", "vier", "fünf", "sechs", "sieb", "ach", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn"]; + private readonly string[] HundredOrdinalSingular = ["einhundert"]; + private readonly string[] HundredOrdinalPlural = ["{0}hundert"]; + private readonly string[] ThousandOrdinalSingular = ["eintausend"]; + private readonly string[] ThousandOrdinalPlural = ["{0}tausend"]; + private readonly string[] MillionOrdinalSingular = ["einmillion", "einemillion"]; + private readonly string[] MillionOrdinalPlural = ["{0}million", "{0}millionen"]; + private readonly string[] BillionOrdinalSingular = ["einmilliard", "einemilliarde"]; + private readonly string[] BillionOrdinalPlural = ["{0}milliard", "{0}milliarden"]; public override string Convert(long number, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs index 8972945c8..60f3f83c4 100644 --- a/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs @@ -2,17 +2,17 @@ { internal class GreekNumberToWordsConverter : GenderlessNumberToWordsConverter { - private readonly string[] UnitMap = { "μηδέν", "ένα", "δύο", "τρία", "τέσσερα", "πέντε", "έξι", "επτά", "οκτώ", "εννέα", "δέκα", "έντεκα", "δώδεκα" }; + private readonly string[] UnitMap = ["μηδέν", "ένα", "δύο", "τρία", "τέσσερα", "πέντε", "έξι", "επτά", "οκτώ", "εννέα", "δέκα", "έντεκα", "δώδεκα"]; - private readonly string[] UnitsMap = { "μηδέν", "ένα", "δύο", "τρείς", "τέσσερις", "πέντε", "έξι", "επτά", "οκτώ", "εννέα", "δέκα", "έντεκα", "δώδεκα" }; + private readonly string[] UnitsMap = ["μηδέν", "ένα", "δύο", "τρείς", "τέσσερις", "πέντε", "έξι", "επτά", "οκτώ", "εννέα", "δέκα", "έντεκα", "δώδεκα"]; - private readonly string[] TensMap = { "", "δέκα", "είκοσι", "τριάντα", "σαράντα", "πενήντα", "εξήντα", "εβδομήντα", "ογδόντα", "ενενήντα" }; + private readonly string[] TensMap = ["", "δέκα", "είκοσι", "τριάντα", "σαράντα", "πενήντα", "εξήντα", "εβδομήντα", "ογδόντα", "ενενήντα"]; - private readonly string[] TensNoDiacriticsMap = { "", "δεκα", "εικοσι", "τριαντα", "σαραντα", "πενηντα", "εξηντα", "εβδομηντα", "ογδοντα", "ενενηντα" }; + private readonly string[] TensNoDiacriticsMap = ["", "δεκα", "εικοσι", "τριαντα", "σαραντα", "πενηντα", "εξηντα", "εβδομηντα", "ογδοντα", "ενενηντα"]; - private readonly string[] HundredMap = { "", "εκατό", "διακόσια", "τριακόσια", "τετρακόσια", "πεντακόσια", "εξακόσια", "επτακόσια", "οκτακόσια", "εννιακόσια" }; + private readonly string[] HundredMap = ["", "εκατό", "διακόσια", "τριακόσια", "τετρακόσια", "πεντακόσια", "εξακόσια", "επτακόσια", "οκτακόσια", "εννιακόσια"]; - private readonly string[] HundredsMap = { "", "εκατόν", "διακόσιες", "τριακόσιες", "τετρακόσιες", "πεντακόσιες", "εξακόσιες", "επτακόσιες", "οκτακόσιες", "εννιακόσιες" }; + private readonly string[] HundredsMap = ["", "εκατόν", "διακόσιες", "τριακόσιες", "τετρακόσιες", "πεντακόσιες", "εξακόσιες", "επτακόσιες", "οκτακόσιες", "εννιακόσιες"]; private static readonly Dictionary ΟrdinalMap = new() { diff --git a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs index 2dea99f03..4fe92999a 100644 --- a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs @@ -1,19 +1,16 @@ namespace Humanizer { - internal class HebrewNumberToWordsConverter : GenderedNumberToWordsConverter + internal class HebrewNumberToWordsConverter(CultureInfo culture) : + GenderedNumberToWordsConverter(GrammaticalGender.Feminine) { - private static readonly string[] UnitsFeminine = { "אפס", "אחת", "שתיים", "שלוש", "ארבע", "חמש", "שש", "שבע", "שמונה", "תשע", "עשר" }; - private static readonly string[] UnitsMasculine = { "אפס", "אחד", "שניים", "שלושה", "ארבעה", "חמישה", "שישה", "שבעה", "שמונה", "תשעה", "עשרה" }; - private static readonly string[] TensUnit = { "עשר", "עשרים", "שלושים", "ארבעים", "חמישים", "שישים", "שבעים", "שמונים", "תשעים" }; + private static readonly string[] UnitsFeminine = ["אפס", "אחת", "שתיים", "שלוש", "ארבע", "חמש", "שש", "שבע", "שמונה", "תשע", "עשר"]; + private static readonly string[] UnitsMasculine = ["אפס", "אחד", "שניים", "שלושה", "ארבעה", "חמישה", "שישה", "שבעה", "שמונה", "תשעה", "עשרה"]; + private static readonly string[] TensUnit = ["עשר", "עשרים", "שלושים", "ארבעים", "חמישים", "שישים", "שבעים", "שמונים", "תשעים"]; - private readonly CultureInfo _culture; - - private class DescriptionAttribute : Attribute + private class DescriptionAttribute(string description) : + Attribute { - public string Description { get; set; } - - public DescriptionAttribute(string description) => - Description = description; + public string Description { get; set; } = description; } private enum Group @@ -26,10 +23,6 @@ private enum Group Billions = 1000000000 } - public HebrewNumberToWordsConverter(CultureInfo culture) - : base(GrammaticalGender.Feminine) => - _culture = culture; - public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { if (input is > int.MaxValue or < int.MinValue) @@ -118,7 +111,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd } public override string ConvertToOrdinal(int number, GrammaticalGender gender) => - number.ToString(_culture); + number.ToString(culture); private void ToBigNumber(int number, Group group, List parts) { diff --git a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs index c5a7c2498..8637d774e 100644 --- a/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/IcelandicNumberToWordsConverter.cs @@ -2,13 +2,13 @@ { internal class IcelandicNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] UnitsMap = { "núll", string.Empty, string.Empty, string.Empty, string.Empty, "fimm", "sex", "sjö", "átta", "níu", "tíu", "ellefu", "tólf", "þrettán", "fjórtán", "fimmtán", "sextán", "sautján", "átján", "nítján" }; - private static readonly string[] FeminineUnitsMap = { string.Empty, "ein", "tvær", "þrjár", "fjórar" }; - private static readonly string[] MasculineUnitsMap = { string.Empty, "einn", "tveir", "þrír", "fjórir" }; - private static readonly string[] NeuterUnitsMap = { string.Empty, "eitt", "tvö", "þrjú", "fjögur" }; - private static readonly string[] TensMap = { string.Empty, "tíu", "tuttugu", "þrjátíu", "fjörutíu", "fimmtíu", "sextíu", "sjötíu", "áttatíu", "níutíu" }; - private static readonly string[] UnitsOrdinalPrefixes = { "núllt", "fyrst", string.Empty, "þriðj", "fjórð", "fimmt", "sjött", "sjöund", "áttund", "níund", "tíund", "elleft", "tólft", "þrettánd", "fjórtánd", "fimmtánd", "sextánd", "sautjánd", "átjánd", "nítjánd" }; - private static readonly string[] TensOrdinalPrefixes = { string.Empty, "tíund", "tuttugast", "þrítugast", "fertugast", "fimmtugast", "sextugast", "sjötugast", "áttugast", "nítugast" }; + private static readonly string[] UnitsMap = ["núll", string.Empty, string.Empty, string.Empty, string.Empty, "fimm", "sex", "sjö", "átta", "níu", "tíu", "ellefu", "tólf", "þrettán", "fjórtán", "fimmtán", "sextán", "sautján", "átján", "nítján"]; + private static readonly string[] FeminineUnitsMap = [string.Empty, "ein", "tvær", "þrjár", "fjórar"]; + private static readonly string[] MasculineUnitsMap = [string.Empty, "einn", "tveir", "þrír", "fjórir"]; + private static readonly string[] NeuterUnitsMap = [string.Empty, "eitt", "tvö", "þrjú", "fjögur"]; + private static readonly string[] TensMap = [string.Empty, "tíu", "tuttugu", "þrjátíu", "fjörutíu", "fimmtíu", "sextíu", "sjötíu", "áttatíu", "níutíu"]; + private static readonly string[] UnitsOrdinalPrefixes = ["núllt", "fyrst", string.Empty, "þriðj", "fjórð", "fimmt", "sjött", "sjöund", "áttund", "níund", "tíund", "elleft", "tólft", "þrettánd", "fjórtánd", "fimmtánd", "sextánd", "sautjánd", "átjánd", "nítjánd"]; + private static readonly string[] TensOrdinalPrefixes = [string.Empty, "tíund", "tuttugast", "þrítugast", "fertugast", "fimmtugast", "sextugast", "sjötugast", "áttugast", "nítugast"]; private const string AndSplit = "og"; private class Fact { @@ -20,14 +20,14 @@ private class Fact } private static readonly Dictionary PowerOfTenMap = new() { - {0, new Fact{Power = 0 , Single = string.Empty, Plural = string.Empty, OrdinalPrefix = string.Empty, Gender = GrammaticalGender.Neuter }}, - {2, new Fact{Power = 2 , Single = "hundrað", Plural = "hundruð", OrdinalPrefix = "hundruðast", Gender = GrammaticalGender.Neuter }}, - {3, new Fact{Power = 1000 , Single = "eitt þúsund", Plural = "þúsund", OrdinalPrefix = "þúsundast", Gender = GrammaticalGender.Neuter }}, - {6, new Fact{Power = 1000000 , Single = "ein milljón", Plural = "milljónir", OrdinalPrefix = "milljónast", Gender = GrammaticalGender.Feminine }}, - {9, new Fact{Power = 1000000000 , Single = "einn milljarður", Plural = "milljarðar", OrdinalPrefix = "milljarðast", Gender = GrammaticalGender.Masculine }}, - {12, new Fact{Power = 1000000000000 , Single = "ein billjón", Plural = "billjónir", OrdinalPrefix = "billjónast", Gender = GrammaticalGender.Feminine }}, - {15, new Fact{Power = 1000000000000000 , Single = "einn billjarður", Plural = "billjarðar", OrdinalPrefix = "billjarðast", Gender = GrammaticalGender.Masculine }}, - {18, new Fact{Power = 1000000000000000000 , Single = "ein trilljón", Plural = "trilljónir", OrdinalPrefix = "trilljónast", Gender = GrammaticalGender.Feminine }} + {0, new(){Power = 0 , Single = string.Empty, Plural = string.Empty, OrdinalPrefix = string.Empty, Gender = GrammaticalGender.Neuter }}, + {2, new(){Power = 2 , Single = "hundrað", Plural = "hundruð", OrdinalPrefix = "hundruðast", Gender = GrammaticalGender.Neuter }}, + {3, new(){Power = 1000 , Single = "eitt þúsund", Plural = "þúsund", OrdinalPrefix = "þúsundast", Gender = GrammaticalGender.Neuter }}, + {6, new(){Power = 1000000 , Single = "ein milljón", Plural = "milljónir", OrdinalPrefix = "milljónast", Gender = GrammaticalGender.Feminine }}, + {9, new(){Power = 1000000000 , Single = "einn milljarður", Plural = "milljarðar", OrdinalPrefix = "milljarðast", Gender = GrammaticalGender.Masculine }}, + {12, new(){Power = 1000000000000 , Single = "ein billjón", Plural = "billjónir", OrdinalPrefix = "billjónast", Gender = GrammaticalGender.Feminine }}, + {15, new(){Power = 1000000000000000 , Single = "einn billjarður", Plural = "billjarðar", OrdinalPrefix = "billjarðast", Gender = GrammaticalGender.Masculine }}, + {18, new(){Power = 1000000000000000000 , Single = "ein trilljón", Plural = "trilljónir", OrdinalPrefix = "trilljónast", Gender = GrammaticalGender.Feminine }} }; private static bool IsAndSplitNeeded(int number) => (((number <= 20) || (number % 10 == 0) && (number < 100)) || (number % 100 == 0)); diff --git a/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs index f70940f0b..f15a1854a 100644 --- a/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/IndianNumberToWordsConverter.cs @@ -2,7 +2,7 @@ { internal class IndianNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {1, "first"}, {2, "second"}, @@ -13,12 +13,18 @@ internal class IndianNumberToWordsConverter : GenderlessNumberToWordsConverter {9, "ninth"}, {12, "twelfth"}, }; - private static readonly string[] Tillnineteen = {"one", "two", "three", "four", "five", "six", "seven", "eight", + private static readonly string[] Tillnineteen = + [ + "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", - "seventeen", "eighteen", "nineteen" }; + "seventeen", "eighteen", "nineteen" + ]; - private static readonly string[] Tens = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", - "eighty", "ninety" }; + private static readonly string[] Tens = + [ + "twenty", "thirty", "forty", "fifty", "sixty", "seventy", + "eighty", "ninety" + ]; public override string Convert(long number) => NumberToText(number).Trim(); diff --git a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs index a0098d997..796f345e2 100644 --- a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs +++ b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianCardinalNumberCruncher.cs @@ -227,8 +227,8 @@ protected static string BillionsConverter(int number) /// /// Lookup table converting units number to text. Index 1 for 1, index 2 for 2, up to index 9. /// - protected static string[] _unitsNumberToText = new string[] - { + protected static string[] _unitsNumberToText = + [ string.Empty, "uno", "due", @@ -239,13 +239,13 @@ protected static string BillionsConverter(int number) "sette", "otto", "nove" - }; + ]; /// /// Lookup table converting tens number to text. Index 2 for 20, index 3 for 30, up to index 9 for 90. /// - protected static string[] _tensOver20NumberToText = new string[] - { + protected static string[] _tensOver20NumberToText = + [ string.Empty, string.Empty, "venti", @@ -256,13 +256,13 @@ protected static string BillionsConverter(int number) "settanta", "ottanta", "novanta" - }; + ]; /// /// Lookup table converting teens number to text. Index 0 for 10, index 1 for 11, up to index 9 for 19. /// - protected static string[] _teensUnder20NumberToText = new string[] - { + protected static string[] _teensUnder20NumberToText = + [ "dieci", "undici", "dodici", @@ -273,13 +273,13 @@ protected static string BillionsConverter(int number) "diciassette", "diciotto", "diciannove" - }; + ]; /// /// Lookup table converting hundreds number to text. Index 0 for no hundreds, index 1 for 100, up to index 9. /// - protected static string[] _hundredNumberToText = new string[] - { + protected static string[] _hundredNumberToText = + [ string.Empty, "cento", "duecento", @@ -290,7 +290,7 @@ protected static string BillionsConverter(int number) "settecento", "ottocento", "novecento" - }; + ]; /// /// Enumerates sets of three-digits having distinct conversion to text. diff --git a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianOrdinalNumberCruncher.cs b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianOrdinalNumberCruncher.cs index 35ad7e5b1..cb3d1dbfe 100644 --- a/src/Humanizer/Localisation/NumberToWords/Italian/ItalianOrdinalNumberCruncher.cs +++ b/src/Humanizer/Localisation/NumberToWords/Italian/ItalianOrdinalNumberCruncher.cs @@ -90,8 +90,8 @@ public string Convert() /// /// Lookup table converting units number to text. Index 1 for 1, index 2 for 2, up to index 9. /// - protected static string[] _unitsUnder10NumberToText = new string[] - { + protected static string[] _unitsUnder10NumberToText = + [ string.Empty, "prim", "second", @@ -102,7 +102,7 @@ public string Convert() "settim", "ottav", "non" - }; + ]; protected static int _lengthOf10AsCardinal = "dieci".Length; } diff --git a/src/Humanizer/Localisation/NumberToWords/JapaneseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/JapaneseNumberToWordsConverter.cs index 1f5f91f5d..47c4731bf 100644 --- a/src/Humanizer/Localisation/NumberToWords/JapaneseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/JapaneseNumberToWordsConverter.cs @@ -2,10 +2,13 @@ { internal class JapaneseNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap1 = { "", "", "二", "三", "四", "五", "六", "七", "八", "九" }; - private static readonly string[] UnitsMap2 = { "", "十", "百", "千" }; - private static readonly string[] UnitsMap3 = { "", "万", "億", "兆", "京", "垓", "𥝱", "穣", "溝", "澗", "正", "載", "極", - "恒河沙", "阿僧祇", "那由他", "不可思議", "無量大数"}; + private static readonly string[] UnitsMap1 = ["", "", "二", "三", "四", "五", "六", "七", "八", "九"]; + private static readonly string[] UnitsMap2 = ["", "十", "百", "千"]; + private static readonly string[] UnitsMap3 = + [ + "", "万", "億", "兆", "京", "垓", "𥝱", "穣", "溝", "澗", "正", "載", "極", + "恒河沙", "阿僧祇", "那由他", "不可思議", "無量大数" + ]; public override string Convert(long number) => ConvertImpl(number, false); diff --git a/src/Humanizer/Localisation/NumberToWords/KoreanNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/KoreanNumberToWordsConverter.cs index 60ed278e4..211a42b63 100644 --- a/src/Humanizer/Localisation/NumberToWords/KoreanNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/KoreanNumberToWordsConverter.cs @@ -2,11 +2,11 @@ { internal class KoreanNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap1 = { "", "", "이", "삼", "사", "오", "육", "칠", "팔", "구" }; - private static readonly string[] UnitsMap2 = { "", "십", "백", "천" }; - private static readonly string[] UnitsMap3 = { "", "만", "억", "조", "경", "해", "자", "양", "구", "간", "정", "재", "극", "항하사", "아승기", "나유타", "불가사의", "무량대수"}; + private static readonly string[] UnitsMap1 = ["", "", "이", "삼", "사", "오", "육", "칠", "팔", "구"]; + private static readonly string[] UnitsMap2 = ["", "십", "백", "천"]; + private static readonly string[] UnitsMap3 = ["", "만", "억", "조", "경", "해", "자", "양", "구", "간", "정", "재", "극", "항하사", "아승기", "나유타", "불가사의", "무량대수"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {0, "영번째"}, {1, "첫번째"}, diff --git a/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs index 4f1f30f66..c9ad9f42e 100644 --- a/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs @@ -2,10 +2,10 @@ { internal class LatvianNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nulle", "vien", "div", "trīs", "četr", "piec", "seš", "septiņ", "astoņ", "deviņ", "desmit", "vienpadsmit", "divpadsmit", "trīspadsmit", "četrpadsmit", "piecpadsmit", "sešpadsmit", "septiņpadsmit", "astoņpadsmit", "deviņpadsmit" }; - private static readonly string[] TensMap = { "nulle", "desmit", "divdesmit", "trīsdesmit", "četrdesmit", "piecdesmit", "sešdesmit", "septiņdesmit", "astoņdesmit", "deviņdesmit" }; - private static readonly string[] HundredsMap = { "nulle", "simt", "divsimt", "trīssimt", "četrsimt", "piecsimt", "sešsimt", "septiņsimt", "astoņsimt", "deviņsimt" }; - private static readonly string[] UnitsOrdinal = { string.Empty, "pirm", "otr", "treš", "ceturt", "piekt", "sest", "septīt", "astot", "devīt", "desmit", "vienpadsmit", "divpadsmit", "trīspadsmit", "četrpadsmit", "piecpadsmit", "sešpadsmit", "septiņpadsmit", "astoņpadsmit", "deviņpadsmit", "divdesmit" }; + private static readonly string[] UnitsMap = ["nulle", "vien", "div", "trīs", "četr", "piec", "seš", "septiņ", "astoņ", "deviņ", "desmit", "vienpadsmit", "divpadsmit", "trīspadsmit", "četrpadsmit", "piecpadsmit", "sešpadsmit", "septiņpadsmit", "astoņpadsmit", "deviņpadsmit"]; + private static readonly string[] TensMap = ["nulle", "desmit", "divdesmit", "trīsdesmit", "četrdesmit", "piecdesmit", "sešdesmit", "septiņdesmit", "astoņdesmit", "deviņdesmit"]; + private static readonly string[] HundredsMap = ["nulle", "simt", "divsimt", "trīssimt", "četrsimt", "piecsimt", "sešsimt", "septiņsimt", "astoņsimt", "deviņsimt"]; + private static readonly string[] UnitsOrdinal = [string.Empty, "pirm", "otr", "treš", "ceturt", "piekt", "sest", "septīt", "astot", "devīt", "desmit", "vienpadsmit", "divpadsmit", "trīspadsmit", "četrpadsmit", "piecpadsmit", "sešpadsmit", "septiņpadsmit", "astoņpadsmit", "deviņpadsmit", "divdesmit"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs index e40ec996f..f86b75134 100644 --- a/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LithuanianNumberToWordsConverter.cs @@ -2,13 +2,13 @@ { internal class LithuanianNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nulis", "vienas", "du", "trys", "keturi", "penki", "šeši", "septyni", "aštuoni", "devyni", "dešimt", "vienuolika", "dvylika", "trylika", "keturiolika", "penkiolika", "šešiolika", "septyniolika", "aštuoniolika", "devyniolika" }; - private static readonly string[] TensMap = { string.Empty, "dešimt", "dvidešimt", "trisdešimt", "keturiasdešimt", "penkiasdešimt", "šešiasdešimt", "septyniasdešimt", "aštuoniasdešimt", "devyniasdešimt" }; - private static readonly string[] HundredsMap = { string.Empty, "šimtas", "du šimtai", "trys šimtai", "keturi šimtai", "penki šimtai", "šeši šimtai", "septyni šimtai", "aštuoni šimtai", "devyni šimtai" }; + private static readonly string[] UnitsMap = ["nulis", "vienas", "du", "trys", "keturi", "penki", "šeši", "septyni", "aštuoni", "devyni", "dešimt", "vienuolika", "dvylika", "trylika", "keturiolika", "penkiolika", "šešiolika", "septyniolika", "aštuoniolika", "devyniolika"]; + private static readonly string[] TensMap = [string.Empty, "dešimt", "dvidešimt", "trisdešimt", "keturiasdešimt", "penkiasdešimt", "šešiasdešimt", "septyniasdešimt", "aštuoniasdešimt", "devyniasdešimt"]; + private static readonly string[] HundredsMap = [string.Empty, "šimtas", "du šimtai", "trys šimtai", "keturi šimtai", "penki šimtai", "šeši šimtai", "septyni šimtai", "aštuoni šimtai", "devyni šimtai"]; - private static readonly string[] OrdinalUnitsMap = { string.Empty, "pirm", "antr", "treči", "ketvirt", "penkt", "šešt", "septint", "aštunt", "devint", "dešimt", "vienuolikt", "dvylikt", "trylikt", "keturiolikt", "penkiolikt", "šešiolikt", "septyniolikt", "aštuoniolikt", "devyniolikt", "dvidešimt" }; - private static readonly string[] OrdinalTensMap = { string.Empty, "dešimt", "dvidešimt", "trisdešimt", "keturiasdešimt", "penkiasdešimt", "šešiasdešimt", "septyniasdešimt", "aštuoniasdešimt", "devyniasdešimt" }; - private static readonly string[] OrdinalHundredsMap = { string.Empty, "šimt", "du šimt", "trys šimt", "keturi šimt", "penki šimt", "šeši šimt", "septyni šimt", "aštuoni šimt", "devyni šimt" }; + private static readonly string[] OrdinalUnitsMap = [string.Empty, "pirm", "antr", "treči", "ketvirt", "penkt", "šešt", "septint", "aštunt", "devint", "dešimt", "vienuolikt", "dvylikt", "trylikt", "keturiolikt", "penkiolikt", "šešiolikt", "septyniolikt", "aštuoniolikt", "devyniolikt", "dvidešimt"]; + private static readonly string[] OrdinalTensMap = [string.Empty, "dešimt", "dvidešimt", "trisdešimt", "keturiasdešimt", "penkiasdešimt", "šešiasdešimt", "septyniasdešimt", "aštuoniasdešimt", "devyniasdešimt"]; + private static readonly string[] OrdinalHundredsMap = [string.Empty, "šimt", "du šimt", "trys šimt", "keturi šimt", "penki šimt", "šeši šimt", "septyni šimt", "aštuoni šimt", "devyni šimt"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs index 81f146b03..dd59fca99 100644 --- a/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LuxembourgishNumberToWordsConverter.cs @@ -2,17 +2,17 @@ internal class LuxembourgishNumberToWordsConverter : GenderedNumberToWordsConverter { - private readonly string[] UnitsMap = { "null", "een", "zwee", "dräi", "véier", "fënnef", "sechs", "siwen", "aacht", "néng", "zéng", "eelef", "zwielef", "dräizéng", "véierzéng", "fofzéng", "siechzéng", "siwwenzéng", "uechtzéng", "nonzéng" }; - private readonly string[] TensMap = { "null", "zéng", "zwanzeg", "drësseg", "véierzeg", "fofzeg", "sechzeg", "siwwenzeg", "achtzeg", "nonzeg" }; - private readonly string[] UnitsOrdinal = { string.Empty, "éisch", "zwee", "drët", "véier", "fënnef", "sechs", "siwen", "aach", "néng", "zéng", "eelef", "zwielef", "dräizéng", "véierzéng", "fofzéng", "siechzéng", "siwwenzéng", "uechtzéng", "nonzéng" }; - private readonly string[] HundredOrdinalSingular = { "eenhonnert" }; - private readonly string[] HundredOrdinalPlural = { "{0}honnert" }; - private readonly string[] ThousandOrdinalSingular = { "eendausend" }; - private readonly string[] ThousandOrdinalPlural = { "{0}dausend" }; - private readonly string[] MillionOrdinalSingular = { "eemillioun", "engmillioun" }; - private readonly string[] MillionOrdinalPlural = { "{0}millioun", "{0}milliounen" }; - private readonly string[] BillionOrdinalSingular = { "eemilliard", "engmilliard" }; - private readonly string[] BillionOrdinalPlural = { "{0}milliard", "{0}milliarden" }; + private readonly string[] UnitsMap = ["null", "een", "zwee", "dräi", "véier", "fënnef", "sechs", "siwen", "aacht", "néng", "zéng", "eelef", "zwielef", "dräizéng", "véierzéng", "fofzéng", "siechzéng", "siwwenzéng", "uechtzéng", "nonzéng"]; + private readonly string[] TensMap = ["null", "zéng", "zwanzeg", "drësseg", "véierzeg", "fofzeg", "sechzeg", "siwwenzeg", "achtzeg", "nonzeg"]; + private readonly string[] UnitsOrdinal = [string.Empty, "éisch", "zwee", "drët", "véier", "fënnef", "sechs", "siwen", "aach", "néng", "zéng", "eelef", "zwielef", "dräizéng", "véierzéng", "fofzéng", "siechzéng", "siwwenzéng", "uechtzéng", "nonzéng"]; + private readonly string[] HundredOrdinalSingular = ["eenhonnert"]; + private readonly string[] HundredOrdinalPlural = ["{0}honnert"]; + private readonly string[] ThousandOrdinalSingular = ["eendausend"]; + private readonly string[] ThousandOrdinalPlural = ["{0}dausend"]; + private readonly string[] MillionOrdinalSingular = ["eemillioun", "engmillioun"]; + private readonly string[] MillionOrdinalPlural = ["{0}millioun", "{0}milliounen"]; + private readonly string[] BillionOrdinalSingular = ["eemilliard", "engmilliard"]; + private readonly string[] BillionOrdinalPlural = ["{0}milliard", "{0}milliarden"]; public override string Convert(long number, GrammaticalGender gender, bool addAnd = true) => Convert(number, WordForm.Normal, gender, addAnd); diff --git a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs index 04252e747..64435b30d 100644 --- a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs +++ b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs @@ -3,33 +3,33 @@ internal class MalteseNumberToWordsConvertor : GenderedNumberToWordsConverter { private static readonly string[] OrdinalOverrideMap = - { + [ "0", "l-ewwel", "it-tieni", "it-tielet", "ir-raba'", "il-ħames", "is-sitt", "is-seba'", "it-tmien", "id-disa'", "l-għaxar", "il-ħdax", "it-tnax", "it-tlettax", "l-erbatax", "il-ħmistax", "is-sittax", "is-sbatax", "it-tmintax", "id-dsatax", "l-għoxrin" - }; + ]; private static readonly string[] UnitsMap = - { + [ "żero", "wieħed", "tnejn", "tlieta", "erbgħa", "ħamsa", "sitta", "sebgħa", "tmienja", "disgħa", "għaxra", "ħdax", "tnax", "tlettax", "erbatax", "ħmistax", "sittax", "sbatax", "tmintax", "dsatax" - }; + ]; private static readonly string[] TensMap = - {"zero", "għaxra", "għoxrin", "tletin", "erbgħin", "ħamsin", "sittin", "sebgħin", "tmenin", "disgħin"}; + ["zero", "għaxra", "għoxrin", "tletin", "erbgħin", "ħamsin", "sittin", "sebgħin", "tmenin", "disgħin"]; private static readonly string[] HundredsMap = - { + [ string.Empty, string.Empty, string.Empty, "tlett", "erbgħa", "ħames", "sitt", "sebgħa", "tminn", "disgħa", "għaxar" - }; + ]; private static readonly string[] PrefixMap = - { + [ string.Empty, string.Empty, string.Empty, "tlett", "erbat", "ħamest", "sitt", "sebat", "tmint", "disat", "għaxart", "ħdax-il", "tnax-il", "tletax-il", "erbatax-il", "ħmistax-il", "sittax-il", "sbatax-il", "tmintax-il", "dsatax-il" - }; + ]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs index 8342fce2b..345e3e162 100644 --- a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs @@ -2,10 +2,10 @@ namespace Humanizer { internal class NorwegianBokmalNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] UnitsMap = { "null", "en", "to", "tre", "fire", "fem", "seks", "sju", "åtte", "ni", "ti", "elleve", "tolv", "tretten", "fjorten", "femten", "seksten", "sytten", "atten", "nitten" }; - private static readonly string[] TensMap = { "null", "ti", "tjue", "tretti", "førti", "femti", "seksti", "sytti", "åtti", "nitti" }; + private static readonly string[] UnitsMap = ["null", "en", "to", "tre", "fire", "fem", "seks", "sju", "åtte", "ni", "ti", "elleve", "tolv", "tretten", "fjorten", "femten", "seksten", "sytten", "atten", "nitten"]; + private static readonly string[] TensMap = ["null", "ti", "tjue", "tretti", "førti", "femti", "seksti", "sytti", "åtti", "nitti"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {0, "nullte"}, {1, "første"}, diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs index 9de8b9aa1..8b0d43433 100644 --- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs @@ -1,42 +1,38 @@ namespace Humanizer { - internal class PolishNumberToWordsConverter : GenderedNumberToWordsConverter + internal class PolishNumberToWordsConverter(CultureInfo culture) : + GenderedNumberToWordsConverter { private static readonly string[] HundredsMap = - { + [ "zero", "sto", "dwieście", "trzysta", "czterysta", "pięćset", "sześćset", "siedemset", "osiemset", "dziewięćset" - }; + ]; private static readonly string[] TensMap = - { + [ "zero", "dziesięć", "dwadzieścia", "trzydzieści", "czterdzieści", "pięćdziesiąt", "sześćdziesiąt", "siedemdziesiąt", "osiemdziesiąt", "dziewięćdziesiąt" - }; + ]; private static readonly string[] UnitsMap = - { + [ "zero", "jeden", "dwa", "trzy", "cztery", "pięć", "sześć", "siedem", "osiem", "dziewięć", "dziesięć", "jedenaście", "dwanaście", "trzynaście", "czternaście", "piętnaście", "szesnaście", "siedemnaście", "osiemnaście", "dziewiętnaście" - }; + ]; private static readonly string[][] PowersOfThousandMap = - { - new []{"tysiąc", "tysiące", "tysięcy"}, - new []{"milion", "miliony", "milionów"}, - new []{"miliard", "miliardy", "miliardów"}, - new []{"bilion", "biliony", "bilionów"}, - new []{"biliard", "biliardy", "biliardów"}, - new []{"trylion", "tryliony", "trylionów"} - }; + [ + ["tysiąc", "tysiące", "tysięcy"], + ["milion", "miliony", "milionów"], + ["miliard", "miliardy", "miliardów"], + ["bilion", "biliony", "bilionów"], + ["biliard", "biliardy", "biliardów"], + ["trylion", "tryliony", "trylionów"] + ]; private const long MaxPossibleDivisor = 1_000_000_000_000_000_000; - private readonly CultureInfo _culture; - - public PolishNumberToWordsConverter(CultureInfo culture) => - _culture = culture; - public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { if (input == 0) @@ -51,7 +47,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd } public override string ConvertToOrdinal(int number, GrammaticalGender gender) => - number.ToString(_culture); + number.ToString(culture); private static void CollectParts(ICollection parts, long input, GrammaticalGender gender) { diff --git a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs index 6df88f94a..ec14d173b 100644 --- a/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PortugueseNumberToWordsConverter.cs @@ -2,13 +2,13 @@ { internal class PortugueseNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] PortugueseUnitsMap = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove" }; - private static readonly string[] PortugueseTensMap = { "zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa" }; - private static readonly string[] PortugueseHundredsMap = { "zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos" }; + private static readonly string[] PortugueseUnitsMap = ["zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove"]; + private static readonly string[] PortugueseTensMap = ["zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa"]; + private static readonly string[] PortugueseHundredsMap = ["zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos"]; - private static readonly string[] PortugueseOrdinalUnitsMap = { "zero", "primeiro", "segundo", "terceiro", "quarto", "quinto", "sexto", "sétimo", "oitavo", "nono" }; - private static readonly string[] PortugueseOrdinalTensMap = { "zero", "décimo", "vigésimo", "trigésimo", "quadragésimo", "quinquagésimo", "sexagésimo", "septuagésimo", "octogésimo", "nonagésimo" }; - private static readonly string[] PortugueseOrdinalHundredsMap = { "zero", "centésimo", "ducentésimo", "trecentésimo", "quadringentésimo", "quingentésimo", "sexcentésimo", "septingentésimo", "octingentésimo", "noningentésimo" }; + private static readonly string[] PortugueseOrdinalUnitsMap = ["zero", "primeiro", "segundo", "terceiro", "quarto", "quinto", "sexto", "sétimo", "oitavo", "nono"]; + private static readonly string[] PortugueseOrdinalTensMap = ["zero", "décimo", "vigésimo", "trigésimo", "quadragésimo", "quinquagésimo", "sexagésimo", "septuagésimo", "octogésimo", "nonagésimo"]; + private static readonly string[] PortugueseOrdinalHundredsMap = ["zero", "centésimo", "ducentésimo", "trecentésimo", "quadringentésimo", "quingentésimo", "sexcentésimo", "septingentésimo", "octingentésimo", "noningentésimo"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs index b1cc186d5..14cb3c604 100644 --- a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianCardinalNumberConverter.cs @@ -6,25 +6,25 @@ internal class RomanianCardinalNumberConverter /// Lookup table converting units number to text. Index 1 for 1, index 2 for 2, up to index 9 for 9. /// private readonly string[] _units = - { - string.Empty, - "unu|una|unu", - "doi|două|două", - "trei", - "patru", - "cinci", - "șase", - "șapte", - "opt", - "nouă" - }; + [ + string.Empty, + "unu|una|unu", + "doi|două|două", + "trei", + "patru", + "cinci", + "șase", + "șapte", + "opt", + "nouă" + ]; /// /// Lookup table converting teens number to text. Index 0 for 10, index 1 for 11, up to index 9 for 19. /// private readonly string[] _teensUnder20NumberToText = - { - "zece", + [ + "zece", "unsprezece", "doisprezece|douăsprezece|douăsprezece", "treisprezece", @@ -34,14 +34,14 @@ internal class RomanianCardinalNumberConverter "șaptesprezece", "optsprezece", "nouăsprezece" - }; + ]; /// /// Lookup table converting tens number to text. Index 2 for 20, index 3 for 30, up to index 9 for 90. /// private readonly string[] _tensOver20NumberToText = - { - string.Empty, + [ + string.Empty, string.Empty, "douăzeci", "treizeci", @@ -51,7 +51,7 @@ internal class RomanianCardinalNumberConverter "șaptezeci", "optzeci", "nouăzeci" - }; + ]; private readonly string _feminineSingular = "o"; private readonly string _masculineSingular = "un"; diff --git a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianOrdinalNumberConverter.cs b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianOrdinalNumberConverter.cs index c0aa71ee1..30e87e763 100644 --- a/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianOrdinalNumberConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/Romanian/RomanianOrdinalNumberConverter.cs @@ -5,18 +5,18 @@ internal class RomanianOrdinalNumberConverter /// /// Lookup table converting units number to text. Index 1 for 1, index 2 for 2, up to index 9. /// - private readonly Dictionary _ordinalsUnder10 = new Dictionary - { - {1, "primul|prima"}, - {2, "doilea|doua"}, - {3, "treilea|treia"}, - {4, "patrulea|patra"}, - {5, "cincilea|cincea"}, - {6, "șaselea|șasea"}, - {7, "șaptelea|șaptea"}, - {8, "optulea|opta"}, - {9, "nouălea|noua"}, - }; + private readonly Dictionary _ordinalsUnder10 = new() + { + {1, "primul|prima"}, + {2, "doilea|doua"}, + {3, "treilea|treia"}, + {4, "patrulea|patra"}, + {5, "cincilea|cincea"}, + {6, "șaselea|șasea"}, + {7, "șaptelea|șaptea"}, + {8, "optulea|opta"}, + {9, "nouălea|noua"}, + }; private readonly string _femininePrefix = "a"; private readonly string _masculinePrefix = "al"; diff --git a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs index 336d7af1f..0cc48354c 100644 --- a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs @@ -2,13 +2,13 @@ { internal class RussianNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] HundredsMap = { "ноль", "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; - private static readonly string[] TensMap = { "ноль", "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; - private static readonly string[] UnitsMap = { "ноль", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; - private static readonly string[] UnitsOrdinalPrefixes = { string.Empty, string.Empty, "двух", "трёх", "четырёх", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати" }; - private static readonly string[] TensOrdinalPrefixes = { string.Empty, "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "восьмидесяти", "девяносто" }; - private static readonly string[] TensOrdinal = { string.Empty, "десят", "двадцат", "тридцат", "сороков", "пятидесят", "шестидесят", "семидесят", "восьмидесят", "девяност" }; - private static readonly string[] UnitsOrdinal = { string.Empty, "перв", "втор", "трет", "четверт", "пят", "шест", "седьм", "восьм", "девят", "десят", "одиннадцат", "двенадцат", "тринадцат", "четырнадцат", "пятнадцат", "шестнадцат", "семнадцат", "восемнадцат", "девятнадцат" }; + private static readonly string[] HundredsMap = ["ноль", "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот"]; + private static readonly string[] TensMap = ["ноль", "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто"]; + private static readonly string[] UnitsMap = ["ноль", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать"]; + private static readonly string[] UnitsOrdinalPrefixes = [string.Empty, string.Empty, "двух", "трёх", "четырёх", "пяти", "шести", "семи", "восьми", "девяти", "десяти", "одиннадцати", "двенадцати", "тринадцати", "четырнадцати", "пятнадцати", "шестнадцати", "семнадцати", "восемнадцати", "девятнадцати"]; + private static readonly string[] TensOrdinalPrefixes = [string.Empty, "десяти", "двадцати", "тридцати", "сорока", "пятидесяти", "шестидесяти", "семидесяти", "восьмидесяти", "девяносто"]; + private static readonly string[] TensOrdinal = [string.Empty, "десят", "двадцат", "тридцат", "сороков", "пятидесят", "шестидесят", "семидесят", "восьмидесят", "девяност"]; + private static readonly string[] UnitsOrdinal = [string.Empty, "перв", "втор", "трет", "четверт", "пят", "шест", "седьм", "восьм", "девят", "десят", "одиннадцат", "двенадцат", "тринадцат", "четырнадцат", "пятнадцат", "шестнадцат", "семнадцат", "восемнадцат", "девятнадцат"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs index 552e7b332..d2dd95d4e 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs @@ -1,14 +1,10 @@ namespace Humanizer { - internal class SerbianCyrlNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class SerbianCyrlNumberToWordsConverter(CultureInfo culture) : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "нула", "један", "два", "три", "четири", "пет", "шест", "седам", "осам", "девет", "десет", "једанест", "дванаест", "тринаест", "четрнаест", "петнаест", "шеснаест", "седамнаест", "осамнаест", "деветнаест" }; - private static readonly string[] TensMap = { "нула", "десет", "двадесет", "тридесет", "четрдесет", "петдесет", "шестдесет", "седамдесет", "осамдесет", "деветдесет" }; - - private readonly CultureInfo _culture; - - public SerbianCyrlNumberToWordsConverter(CultureInfo culture) => - _culture = culture; + private static readonly string[] UnitsMap = ["нула", "један", "два", "три", "четири", "пет", "шест", "седам", "осам", "девет", "десет", "једанест", "дванаест", "тринаест", "четрнаест", "петнаест", "шеснаест", "седамнаест", "осамнаест", "деветнаест"]; + private static readonly string[] TensMap = ["нула", "десет", "двадесет", "тридесет", "четрдесет", "петдесет", "шестдесет", "седамдесет", "осамдесет", "деветдесет"]; public override string Convert(long input) { @@ -105,7 +101,7 @@ public override string Convert(long input) public override string ConvertToOrdinal(int number) => //TODO: In progress - number.ToString(_culture); + number.ToString(culture); private string Part(string singular, string dual, string trialQuadral, string plural, int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs index 2d27dd121..6d43f03df 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs @@ -1,14 +1,10 @@ namespace Humanizer { - internal class SerbianNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class SerbianNumberToWordsConverter(CultureInfo culture) : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nula", "jedan", "dva", "tri", "četiri", "pet", "šest", "sedam", "osam", "devet", "deset", "jedanaest", "dvanaest", "trinaest", "četrnaest", "petnaest", "šestnaest", "sedemnaest", "osemnaest", "devetnaest" }; - private static readonly string[] TensMap = { "nula", "deset", "dvadeset", "trideset", "četrdeset", "petdeset", "šestdeset", "sedamdeset", "osamdeset", "devetdeset" }; - - private readonly CultureInfo _culture; - - public SerbianNumberToWordsConverter(CultureInfo culture) => - _culture = culture; + private static readonly string[] UnitsMap = ["nula", "jedan", "dva", "tri", "četiri", "pet", "šest", "sedam", "osam", "devet", "deset", "jedanaest", "dvanaest", "trinaest", "četrnaest", "petnaest", "šestnaest", "sedemnaest", "osemnaest", "devetnaest"]; + private static readonly string[] TensMap = ["nula", "deset", "dvadeset", "trideset", "četrdeset", "petdeset", "šestdeset", "sedamdeset", "osamdeset", "devetdeset"]; public override string Convert(long input) { @@ -103,7 +99,7 @@ public override string Convert(long input) public override string ConvertToOrdinal(int number) => //TODO: In progress - number.ToString(_culture); + number.ToString(culture); private string Part(string singular, string dual, string trialQuadral, string plural, int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs index 727430c94..988e6a0a0 100644 --- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs @@ -1,14 +1,10 @@ namespace Humanizer { - internal class SlovenianNumberToWordsConverter : GenderlessNumberToWordsConverter + internal class SlovenianNumberToWordsConverter(CultureInfo culture) : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nič", "ena", "dva", "tri", "štiri", "pet", "šest", "sedem", "osem", "devet", "deset", "enajst", "dvanajst", "trinajst", "štirinajst", "petnajst", "šestnajst", "sedemnajst", "osemnajst", "devetnajst" }; - private static readonly string[] TensMap = { "nič", "deset", "dvajset", "trideset", "štirideset", "petdeset", "šestdeset", "sedemdeset", "osemdeset", "devetdeset" }; - - private readonly CultureInfo _culture; - - public SlovenianNumberToWordsConverter(CultureInfo culture) => - _culture = culture; + private static readonly string[] UnitsMap = ["nič", "ena", "dva", "tri", "štiri", "pet", "šest", "sedem", "osem", "devet", "deset", "enajst", "dvanajst", "trinajst", "štirinajst", "petnajst", "šestnajst", "sedemnajst", "osemnajst", "devetnajst"]; + private static readonly string[] TensMap = ["nič", "deset", "dvajset", "trideset", "štirideset", "petdeset", "šestdeset", "sedemdeset", "osemdeset", "devetdeset"]; public override string Convert(long input) { @@ -102,7 +98,7 @@ public override string Convert(long input) } public override string ConvertToOrdinal(int number) => - number.ToString(_culture); + number.ToString(culture); private string Part(string singular, string dual, string trialQuadral, string plural, int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs index 61bc0ac3e..c5cc408dc 100644 --- a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs @@ -2,43 +2,60 @@ { internal class SpanishNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] HundredsRootMap = { + private static readonly string[] HundredsRootMap = + [ "cero", "ciento", "doscient", "trescient", "cuatrocient", "quinient", "seiscient", "setecient", - "ochocient", "novecient" }; + "ochocient", "novecient" + ]; - private static readonly string[] HundredthsRootMap = { + private static readonly string[] HundredthsRootMap = + [ "", "centésim", "ducentésim", "tricentésim", "cuadringentésim", "quingentésim", "sexcentésim", - "septingentésim", "octingentésim", "noningentésim" }; - - private static readonly string[] OrdinalsRootMap = { "" , "primer", "segund", "tercer", "cuart", "quint", "sext", - "séptim", "octav", "noven"}; - - private static readonly string[] TensMap = { - "cero", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" }; - - private static readonly string[] TenthsRootMap = { + "septingentésim", "octingentésim", "noningentésim" + ]; + + private static readonly string[] OrdinalsRootMap = + [ + "" , "primer", "segund", "tercer", "cuart", "quint", "sext", + "séptim", "octav", "noven" + ]; + + private static readonly string[] TensMap = + [ + "cero", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" + ]; + + private static readonly string[] TenthsRootMap = + [ "", "décim", "vigésim", "trigésim", "cuadragésim", "quincuagésim", "sexagésim", "septuagésim", - "octogésim", "nonagésim" }; + "octogésim", "nonagésim" + ]; - private static readonly string[] ThousandthsRootMap = { + private static readonly string[] ThousandthsRootMap = + [ "", "milésim", "dosmilésim", "tresmilésim", "cuatromilésim", "cincomilésim", "seismilésim", - "sietemilésim", "ochomilésim", "nuevemilésim" }; + "sietemilésim", "ochomilésim", "nuevemilésim" + ]; - private static readonly string[] TupleMap = { + private static readonly string[] TupleMap = + [ "cero veces", "una vez", "doble", "triple", "cuádruple", "quíntuple", "séxtuple", "séptuple", "óctuple", - "nonuplo", "décuplo", "undécuplo", "duodécuplo", "terciodécuplo" }; + "nonuplo", "décuplo", "undécuplo", "duodécuplo", "terciodécuplo" + ]; - private static readonly string[] UnitsMap = { + private static readonly string[] UnitsMap = + [ "cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiuno", - "veintidós", "veintitrés", "veinticuatro", "veinticinco", "veintiséis", "veintisiete", "veintiocho", "veintinueve"}; + "veintidós", "veintitrés", "veinticuatro", "veinticinco", "veintiséis", "veintisiete", "veintiocho", "veintinueve" + ]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) => Convert(input, WordForm.Normal, gender, addAnd); public override string Convert(long number, WordForm wordForm, GrammaticalGender gender, bool addAnd = true) { - List wordBuilder = new(); + List wordBuilder = []; if (number == 0) { @@ -70,7 +87,7 @@ public override string ConvertToOrdinal(int number, GrammaticalGender gender) => public override string ConvertToOrdinal(int number, GrammaticalGender gender, WordForm wordForm) { - List wordBuilder = new(); + List wordBuilder = []; if (number is 0 or int.MinValue) { @@ -268,7 +285,7 @@ private static string PluralizeGreaterThanMillion(string singularWord) => private string ConvertGreaterThanMillion(in long inputNumber, out long remainder) { - List wordBuilder = new(); + List wordBuilder = []; const long oneTrillion = 1_000_000_000_000_000_000; const long oneBillion = 1_000_000_000_000; diff --git a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs index d728dd903..c4fb8bd12 100644 --- a/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SwedishNumberToWordsConverter.cs @@ -2,8 +2,8 @@ { internal class SwedishNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "noll", "ett", "två", "tre", "fyra", "fem", "sex", "sju", "åtta", "nio", "tio", "elva", "tolv", "tretton", "fjorton", "femton", "sexton", "sjutton", "arton", "nitton" }; - private static readonly string[] TensMap = { "noll", "tio", "tjugo", "trettio", "fyrtio", "femtio", "sextio", "sjuttio", "åttio", "nittio", "hundra" }; + private static readonly string[] UnitsMap = ["noll", "ett", "två", "tre", "fyra", "fem", "sex", "sju", "åtta", "nio", "tio", "elva", "tolv", "tretton", "fjorton", "femton", "sexton", "sjutton", "arton", "nitton"]; + private static readonly string[] TensMap = ["noll", "tio", "tjugo", "trettio", "fyrtio", "femtio", "sextio", "sjuttio", "åttio", "nittio", "hundra"]; private class Fact { @@ -16,12 +16,12 @@ private class Fact } private static readonly Fact[] Hunderds = - { - new Fact {Value = 1000000000, Name = "miljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true, Gender = GrammaticalGender.Masculine}, - new Fact {Value = 1000000, Name = "miljon", Prefix = " ", Postfix = " ", DisplayOneUnit = true, Gender = GrammaticalGender.Masculine}, - new Fact {Value = 1000, Name = "tusen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, - new Fact {Value = 100, Name = "hundra", Prefix = "", Postfix = "", DisplayOneUnit = false} - }; + [ + new(){Value = 1000000000, Name = "miljard", Prefix = " ", Postfix = " ", DisplayOneUnit = true, Gender = GrammaticalGender.Masculine}, + new(){Value = 1000000, Name = "miljon", Prefix = " ", Postfix = " ", DisplayOneUnit = true, Gender = GrammaticalGender.Masculine}, + new(){Value = 1000, Name = "tusen", Prefix = " ", Postfix = " ", DisplayOneUnit = true}, + new(){Value = 100, Name = "hundra", Prefix = "", Postfix = "", DisplayOneUnit = false} + ]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { @@ -108,8 +108,8 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd public override string Convert(long input) => Convert(input, GrammaticalGender.Neuter); - private static string[] ordinalNumbers = new[] - { + private static string[] ordinalNumbers = + [ "nollte", "första", "andra", @@ -130,8 +130,8 @@ public override string Convert(long input) => "sjuttonde", "artonde", "nittonde", - "tjugonde", - }; + "tjugonde" + ]; public override string ConvertToOrdinal(int number) { diff --git a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs index bbe121ae7..94dedaef4 100644 --- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs @@ -2,14 +2,14 @@ { internal class TamilNumberToWordsConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "சுழியம்", "ஒன்று", "இரண்டு", "மூன்று", "நான்கு", "ஐந்து", "ஆறு", "ஏழு", "எட்டு", "ஒன்பது", "பத்து", "பதினொன்று", "பனிரெண்டு", "பதிமூன்று", "பதினான்கு", "பதினைந்து", "பதினாறு", "பதினேழு", "பதினெட்டு", "பத்தொன்பது" }; - private static readonly string[] TensMap = { "சுழியம்", "பத்து", "இருப", "முப்ப", "நாற்ப", "ஐம்ப", "அறுப", "எழுப", "எண்ப", "தொண்ணூ" }; - private static readonly string[] HundredsMap = { "நூ", "இருநூ", "முன்னூ", "நானூ", "ஐந்நூ", "அறுநூ", "எழுநூ", "எண்ணூ", "தொள்ளாயிர", }; - private static readonly string[] ThousandsMap = { "ஆ", "இரண்டா", "மூன்றா", "நான்கா", "ஐந்தா", "ஆறா", "ஏழா", "எட்டா", "ஒன்பதா", "பத்தா", "பதினொன்றா", "பனிரெண்டா", "பதிமூன்றா", "பதினான்கா", "பதினைந்தா", "பதினாறா", "பதினேழா", "பதினெட்டா", "பத்தொன்பதா" }; + private static readonly string[] UnitsMap = ["சுழியம்", "ஒன்று", "இரண்டு", "மூன்று", "நான்கு", "ஐந்து", "ஆறு", "ஏழு", "எட்டு", "ஒன்பது", "பத்து", "பதினொன்று", "பனிரெண்டு", "பதிமூன்று", "பதினான்கு", "பதினைந்து", "பதினாறு", "பதினேழு", "பதினெட்டு", "பத்தொன்பது"]; + private static readonly string[] TensMap = ["சுழியம்", "பத்து", "இருப", "முப்ப", "நாற்ப", "ஐம்ப", "அறுப", "எழுப", "எண்ப", "தொண்ணூ"]; + private static readonly string[] HundredsMap = ["நூ", "இருநூ", "முன்னூ", "நானூ", "ஐந்நூ", "அறுநூ", "எழுநூ", "எண்ணூ", "தொள்ளாயிர"]; + private static readonly string[] ThousandsMap = ["ஆ", "இரண்டா", "மூன்றா", "நான்கா", "ஐந்தா", "ஆறா", "ஏழா", "எட்டா", "ஒன்பதா", "பத்தா", "பதினொன்றா", "பனிரெண்டா", "பதிமூன்றா", "பதினான்கா", "பதினைந்தா", "பதினாறா", "பதினேழா", "பதினெட்டா", "பத்தொன்பதா"]; - private static readonly string[] LakhsMap = { "இலட்ச" }; + private static readonly string[] LakhsMap = ["இலட்ச"]; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new() { {1, "முதலாவது"}, {2, "இரண்டாவது"}, diff --git a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs index f9b6565e6..f5d9c463f 100644 --- a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs @@ -1,11 +1,12 @@ namespace Humanizer { - internal class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter + internal class TurkishNumberToWordConverter : + GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "sıfır", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz" }; - private static readonly string[] TensMap = { "sıfır", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan" }; + private static readonly string[] UnitsMap = ["sıfır", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"]; + private static readonly string[] TensMap = ["sıfır", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan"]; - private static readonly Dictionary OrdinalSuffix = new Dictionary + private static readonly Dictionary OrdinalSuffix = new() { {'ı', "ıncı"}, {'i', "inci"}, @@ -17,7 +18,7 @@ internal class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter {'a', "ıncı"}, }; - private static readonly Dictionary TupleSuffix = new Dictionary + private static readonly Dictionary TupleSuffix = new() { {'ı', "lı"}, {'i', "li"}, diff --git a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs index 4f1ad5e11..0511b43e4 100644 --- a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs @@ -2,13 +2,13 @@ { internal class UkrainianNumberToWordsConverter : GenderedNumberToWordsConverter { - private static readonly string[] HundredsMap = { "нуль", "сто", "двісті", "триста", "чотириста", "п'ятсот", "шістсот", "сімсот", "вісімсот", "дев'ятсот" }; - private static readonly string[] TensMap = { "нуль", "десять", "двадцять", "тридцять", "сорок", "п'ятдесят", "шістдесят", "сімдесят", "вісімдесят", "дев'яносто" }; - private static readonly string[] UnitsMap = { "нуль", "один", "два", "три", "чотири", "п'ять", "шість", "сім", "вісім", "дев'ять", "десять", "одинадцять", "дванадцять", "тринадцять", "чотирнадцять", "п'ятнадцять", "шістнадцять", "сімнадцять", "вісімнадцять", "дев'ятнадцять" }; - private static readonly string[] UnitsOrdinalPrefixes = { string.Empty, string.Empty, "двох", "трьох", "чотирьох", "п'яти", "шести", "семи", "восьми", "дев'яти", "десяти", "одинадцяти", "дванадцяти", "тринадцяти", "чотирнадцяти", "п'ятнадцяти", "шістнадцяти", "сімнадцяти", "вісімнадцяти", "дев'ятнадцяти", "двадцяти" }; - private static readonly string[] TensOrdinalPrefixes = { string.Empty, "десяти", "двадцяти", "тридцяти", "сорока", "п'ятдесяти", "шістдесяти", "сімдесяти", "вісімдесяти", "дев'яносто" }; - private static readonly string[] TensOrdinal = { string.Empty, "десят", "двадцят", "тридцят", "сороков", "п'ятдесят", "шістдесят", "сімдесят", "вісімдесят", "дев'яност" }; - private static readonly string[] UnitsOrdinal = { "нульов", "перш", "друг", "трет", "четверт", "п'ят", "шост", "сьом", "восьм", "дев'ят", "десят", "одинадцят", "дванадцят", "тринадцят", "чотирнадцят", "п'ятнадцят", "шістнадцят", "сімнадцят", "вісімнадцят", "дев'ятнадцят" }; + private static readonly string[] HundredsMap = ["нуль", "сто", "двісті", "триста", "чотириста", "п'ятсот", "шістсот", "сімсот", "вісімсот", "дев'ятсот"]; + private static readonly string[] TensMap = ["нуль", "десять", "двадцять", "тридцять", "сорок", "п'ятдесят", "шістдесят", "сімдесят", "вісімдесят", "дев'яносто"]; + private static readonly string[] UnitsMap = ["нуль", "один", "два", "три", "чотири", "п'ять", "шість", "сім", "вісім", "дев'ять", "десять", "одинадцять", "дванадцять", "тринадцять", "чотирнадцять", "п'ятнадцять", "шістнадцять", "сімнадцять", "вісімнадцять", "дев'ятнадцять"]; + private static readonly string[] UnitsOrdinalPrefixes = [string.Empty, string.Empty, "двох", "трьох", "чотирьох", "п'яти", "шести", "семи", "восьми", "дев'яти", "десяти", "одинадцяти", "дванадцяти", "тринадцяти", "чотирнадцяти", "п'ятнадцяти", "шістнадцяти", "сімнадцяти", "вісімнадцяти", "дев'ятнадцяти", "двадцяти"]; + private static readonly string[] TensOrdinalPrefixes = [string.Empty, "десяти", "двадцяти", "тридцяти", "сорока", "п'ятдесяти", "шістдесяти", "сімдесяти", "вісімдесяти", "дев'яносто"]; + private static readonly string[] TensOrdinal = [string.Empty, "десят", "двадцят", "тридцят", "сороков", "п'ятдесят", "шістдесят", "сімдесят", "вісімдесят", "дев'яност"]; + private static readonly string[] UnitsOrdinal = ["нульов", "перш", "друг", "трет", "четверт", "п'ят", "шост", "сьом", "восьм", "дев'ят", "десят", "одинадцят", "дванадцят", "тринадцят", "чотирнадцят", "п'ятнадцят", "шістнадцят", "сімнадцят", "вісімнадцят", "дев'ятнадцят"]; public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs index aca465891..87e560cbe 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs @@ -2,10 +2,10 @@ { internal class UzbekCyrlNumberToWordConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "нол", "бир", "икки", "уч", "тўрт", "беш", "олти", "етти", "саккиз", "тўққиз" }; - private static readonly string[] TensMap = { "нол", "ўн", "йигирма", "ўттиз", "қирқ", "эллик", "олтмиш", "етмиш", "саксон", "тўқсон" }; + private static readonly string[] UnitsMap = ["нол", "бир", "икки", "уч", "тўрт", "беш", "олти", "етти", "саккиз", "тўққиз"]; + private static readonly string[] TensMap = ["нол", "ўн", "йигирма", "ўттиз", "қирқ", "эллик", "олтмиш", "етмиш", "саксон", "тўқсон"]; - private static readonly string[] OrdinalSuffixes = new string[] { "инчи", "нчи" }; + private static readonly string[] OrdinalSuffixes = ["инчи", "нчи"]; public override string Convert(long input) { diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs index 1aeddd37c..e2d5f1fd7 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs @@ -2,10 +2,10 @@ { internal class UzbekLatnNumberToWordConverter : GenderlessNumberToWordsConverter { - private static readonly string[] UnitsMap = { "nol", "bir", "ikki", "uch", "to`rt", "besh", "olti", "yetti", "sakkiz", "to`qqiz" }; - private static readonly string[] TensMap = { "nol", "o`n", "yigirma", "o`ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to`qson" }; + private static readonly string[] UnitsMap = ["nol", "bir", "ikki", "uch", "to`rt", "besh", "olti", "yetti", "sakkiz", "to`qqiz"]; + private static readonly string[] TensMap = ["nol", "o`n", "yigirma", "o`ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to`qson"]; - private static readonly string[] OrdinalSuffixes = new string[] { "inchi", "nchi" }; + private static readonly string[] OrdinalSuffixes = ["inchi", "nchi"]; public override string Convert(long input) { diff --git a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs index 2efeebd9c..5eb987d28 100644 --- a/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/VietnameseNumberToWordsConverter.cs @@ -6,9 +6,9 @@ internal class VietnameseNumberToWordsConverter : GenderlessNumberToWordsConvert private const int OneMillion = 1000000; private static readonly string[] NumberVerbalPairs = - { + [ "", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" - }; + ]; public override string Convert(long number) => number == 0 diff --git a/src/Humanizer/Localisation/Resources.cs b/src/Humanizer/Localisation/Resources.cs index 44f60da37..091f0ccb2 100644 --- a/src/Humanizer/Localisation/Resources.cs +++ b/src/Humanizer/Localisation/Resources.cs @@ -7,7 +7,7 @@ namespace Humanizer /// public static class Resources { - private static readonly ResourceManager ResourceManager = new ResourceManager("Humanizer.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly); + private static readonly ResourceManager ResourceManager = new("Humanizer.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly); /// /// Returns the value of the specified string resource diff --git a/src/Humanizer/MetricNumeralExtensions.cs b/src/Humanizer/MetricNumeralExtensions.cs index 0bdf8b649..d7fa0950b 100644 --- a/src/Humanizer/MetricNumeralExtensions.cs +++ b/src/Humanizer/MetricNumeralExtensions.cs @@ -43,10 +43,10 @@ static MetricNumeralExtensions() /// Symbols is a list of every symbols for the Metric system. /// private static readonly List[] Symbols = - { - new List { 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' }, - new List { 'm', 'μ', 'n', 'p', 'f', 'a', 'z', 'y' } - }; + [ + ['k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'], + ['m', 'μ', 'n', 'p', 'f', 'a', 'z', 'y'] + ]; /// /// UnitPrefixes link a Metric symbol (as key) to its prefix (as value). @@ -58,7 +58,7 @@ static MetricNumeralExtensions() /// {'d', "deci" }, /// {'c', "centi"}, /// - private static readonly Dictionary UnitPrefixes = new Dictionary + private static readonly Dictionary UnitPrefixes = new() { {'Y', new UnitPrefix("yotta", "septillion", "quadrillion")}, {'Z', new UnitPrefix("zetta", "sextillion", "trilliard")}, @@ -372,20 +372,11 @@ private static bool IsInvalidMetricNumeral(this string input) return !double.TryParse(isSymbol ? input.Remove(index) : input, out var number); } - private struct UnitPrefix + private struct UnitPrefix(string name, string shortScaleWord, string longScaleWord = null) { - private readonly string _longScaleWord; - - public string Name { get; } - public string ShortScaleWord { get; } - public string LongScaleWord => _longScaleWord ?? ShortScaleWord; - - public UnitPrefix(string name, string shortScaleWord, string longScaleWord = null) - { - Name = name; - ShortScaleWord = shortScaleWord; - _longScaleWord = longScaleWord; - } + public string Name { get; } = name; + public string ShortScaleWord { get; } = shortScaleWord; + public string LongScaleWord => longScaleWord ?? ShortScaleWord; } } } diff --git a/src/Humanizer/RomanNumeralExtensions.cs b/src/Humanizer/RomanNumeralExtensions.cs index 265cc7809..5d176be74 100644 --- a/src/Humanizer/RomanNumeralExtensions.cs +++ b/src/Humanizer/RomanNumeralExtensions.cs @@ -28,7 +28,7 @@ public static class RomanNumeralExtensions }; private static readonly Regex ValidRomanNumeral = - new Regex( + new( "^(?i:(?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?XX{0,2})|L)?((I[VX])|(V?(II{0,2}))|V)?))$", RegexOptionsUtil.Compiled); diff --git a/src/Humanizer/StringHumanizeExtensions.cs b/src/Humanizer/StringHumanizeExtensions.cs index f95b20ebf..95d0f6eea 100644 --- a/src/Humanizer/StringHumanizeExtensions.cs +++ b/src/Humanizer/StringHumanizeExtensions.cs @@ -23,7 +23,7 @@ static StringHumanizeExtensions() } private static string FromUnderscoreDashSeparatedWords(string input) => - string.Join(" ", input.Split(new[] { '_', '-' })); + string.Join(" ", input.Split(['_', '-'])); private static string FromPascalCase(string input) { diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index 5558ee348..324551bc9 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -168,10 +168,10 @@ private static string BuildFormatTimePart(IFormatter cultureFormatter, TimeUnit : null; private static List CreateTimePartsWithNoTimeValue(string noTimeValue) => - new() { noTimeValue }; + [noTimeValue]; private static bool IsContainingOnlyNullValue(IEnumerable timeParts) => - (timeParts.Count(x => x != null) == 0); + timeParts.Count(x => x != null) == 0; private static IEnumerable SetPrecisionOfTimeSpan(IEnumerable timeParts, int precision, bool countEmptyUnits) {