From 1d0f3e7b06739a1357123d85b88de61b186f38ca Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Fri, 23 Nov 2018 21:21:45 +0100 Subject: [PATCH] Fixed minor issues with Maltese language support --- .../Localisation/mt/NumberToWordsTests.cs | 39 ++++++++++--------- .../MalteseNumberToWordsConvertor.cs | 23 ++++++----- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Localisation/mt/NumberToWordsTests.cs b/src/Humanizer.Tests.Shared/Localisation/mt/NumberToWordsTests.cs index 3038a0b82..aedcc9ee4 100644 --- a/src/Humanizer.Tests.Shared/Localisation/mt/NumberToWordsTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/mt/NumberToWordsTests.cs @@ -8,10 +8,12 @@ public class NumberToWordsTests [Theory] [InlineData(0, "żero")] [InlineData(1, "wieħed")] + [InlineData(-1, "wieħed inqas minn żero")] [InlineData(3, "tlieta")] [InlineData(10, "għaxra")] [InlineData(11, "ħdax")] [InlineData(20, "għoxrin")] + [InlineData(-20, "għoxrin inqas minn żero")] [InlineData(21, "wieħed u għoxrin")] [InlineData(38, "tmienja u tletin")] [InlineData(43, "tlieta u erbgħin")] @@ -66,31 +68,32 @@ public class NumberToWordsTests [InlineData(8100, "tmint elef u mija")] [InlineData(10000, "għaxart elef")] [InlineData(10001, "għaxart elef u wieħed")] - [InlineData(12345, "tnax il-elf u tlett mija u ħamsa u erbgħin")] - [InlineData(18000, "tmintax il-elf")] + [InlineData(12345, "tnax-il elf u tlett mija u ħamsa u erbgħin")] + [InlineData(18000, "tmintax-il elf")] [InlineData(100000, "mitt elf")] [InlineData(100001, "mitt elf u wieħed")] - [InlineData(111111, "mija u ħdax il-elf u mija u ħdax")] + [InlineData(111111, "mija u ħdax-il elf u mija u ħdax")] [InlineData(123456, "mija u tlieta u għoxrin elf u erbgħa mija u sitta u ħamsin")] [InlineData(1000000, "miljun")] [InlineData(1000001, "miljun u wieħed")] - [InlineData(1111101, "miljun u mija u ħdax il-elf u mija u wieħed")] - [InlineData(1111111, "miljun u mija u ħdax il-elf u mija u ħdax")] + [InlineData(1111101, "miljun u mija u ħdax-il elf u mija u wieħed")] + [InlineData(1111111, "miljun u mija u ħdax-il elf u mija u ħdax")] [InlineData(1234567, "miljun u mitejn u erbgħa u tletin elf u ħames mija u sebgħa u sittin")] [InlineData(5000000, "ħames miljuni")] [InlineData(10000000, "għaxar miljuni")] [InlineData(10000001, "għaxar miljuni u wieħed")] - [InlineData(11111111, "ħdax il-miljun u mija u ħdax il-elf u mija u ħdax")] - [InlineData(12345678, "tnax il-miljun u tlett mija u ħamsa u erbgħin elf u sitt mija u tmienja u sebgħin")] + [InlineData(11111111, "ħdax-il miljun u mija u ħdax-il elf u mija u ħdax")] + [InlineData(12345678, "tnax-il miljun u tlett mija u ħamsa u erbgħin elf u sitt mija u tmienja u sebgħin")] [InlineData(100000000, "mitt miljun")] [InlineData(100000001, "mitt miljun u wieħed")] - [InlineData(111111111, "mija u ħdax il-miljun u mija u ħdax il-elf u mija u ħdax")] + [InlineData(111111111, "mija u ħdax-il miljun u mija u ħdax-il elf u mija u ħdax")] [InlineData(123456789, "mija u tlieta u għoxrin miljun u erbgħa mija u sitta u ħamsin elf u sebgħa mija u disgħa u tmenin")] [InlineData(1000000000, "biljun")] [InlineData(1000000001, "biljun u wieħed")] - [InlineData(1101111101, "biljun u mija u miljun u mija u ħdax il-elf u mija u wieħed")] + [InlineData(1101111101, "biljun u mija u miljun u mija u ħdax-il elf u mija u wieħed")] [InlineData(2000000000, "żewġ biljuni")] [InlineData(2147483647, "żewġ biljuni u mija u sebgħa u erbgħin miljun u erbgħa mija u tlieta u tmenin elf u sitt mija u sebgħa u erbgħin")] + [InlineData(-2147483647, "żewġ biljuni u mija u sebgħa u erbgħin miljun u erbgħa mija u tlieta u tmenin elf u sitt mija u sebgħa u erbgħin inqas minn żero")] public void ToWords(int number, string expected) { Assert.Equal(expected, number.ToWords()); @@ -167,29 +170,29 @@ public void ToFeminineWords(int number, string expected) [InlineData(8100, "tmint elef u mija")] [InlineData(10000, "għaxart elef")] [InlineData(10001, "għaxart elef u wieħed")] - [InlineData(12345, "tnax il-elf u tlett mija u ħamsa u erbgħin")] - [InlineData(18000, "tmintax il-elf")] + [InlineData(12345, "tnax-il elf u tlett mija u ħamsa u erbgħin")] + [InlineData(18000, "tmintax-il elf")] [InlineData(100000, "mitt elf")] [InlineData(100001, "mitt elf u wieħed")] - [InlineData(111111, "mija u ħdax il-elf u mija u ħdax")] + [InlineData(111111, "mija u ħdax-il elf u mija u ħdax")] [InlineData(123456, "mija u tlieta u għoxrin elf u erbgħa mija u sitta u ħamsin")] [InlineData(1000000, "miljun")] [InlineData(1000001, "miljun u wieħed")] - [InlineData(1111101, "miljun u mija u ħdax il-elf u mija u wieħed")] - [InlineData(1111111, "miljun u mija u ħdax il-elf u mija u ħdax")] + [InlineData(1111101, "miljun u mija u ħdax-il elf u mija u wieħed")] + [InlineData(1111111, "miljun u mija u ħdax-il elf u mija u ħdax")] [InlineData(1234567, "miljun u mitejn u erbgħa u tletin elf u ħames mija u sebgħa u sittin")] [InlineData(5000000, "ħames miljuni")] [InlineData(10000000, "għaxar miljuni")] [InlineData(10000001, "għaxar miljuni u wieħed")] - [InlineData(11111111, "ħdax il-miljun u mija u ħdax il-elf u mija u ħdax")] - [InlineData(12345678, "tnax il-miljun u tlett mija u ħamsa u erbgħin elf u sitt mija u tmienja u sebgħin")] + [InlineData(11111111, "ħdax-il miljun u mija u ħdax-il elf u mija u ħdax")] + [InlineData(12345678, "tnax-il miljun u tlett mija u ħamsa u erbgħin elf u sitt mija u tmienja u sebgħin")] [InlineData(100000000, "mitt miljun")] [InlineData(100000001, "mitt miljun u wieħed")] - [InlineData(111111111, "mija u ħdax il-miljun u mija u ħdax il-elf u mija u ħdax")] + [InlineData(111111111, "mija u ħdax-il miljun u mija u ħdax-il elf u mija u ħdax")] [InlineData(123456789, "mija u tlieta u għoxrin miljun u erbgħa mija u sitta u ħamsin elf u sebgħa mija u disgħa u tmenin")] [InlineData(1000000000, "biljun")] [InlineData(1000000001, "biljun u wieħed")] - [InlineData(1101111101, "biljun u mija u miljun u mija u ħdax il-elf u mija u wieħed")] + [InlineData(1101111101, "biljun u mija u miljun u mija u ħdax-il elf u mija u wieħed")] [InlineData(2000000000, "żewġ biljuni")] [InlineData(2147483647, "żewġ biljuni u mija u sebgħa u erbgħin miljun u erbgħa mija u tlieta u tmenin elf u sitt mija u sebgħa u erbgħin")] public void ToMasculineWords(int number, string expected) diff --git a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs index d5ea09f69..9237e9ccf 100644 --- a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs +++ b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs @@ -30,15 +30,23 @@ internal class MalteseNumberToWordsConvertor : GenderedNumberToWordsConverter 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-" + "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 negativeNumber = false; + + if (input < 0) + { + negativeNumber = true; + input = input * -1; + } + if (input < 1000000000) { - return GetMillions(input, gender); + return GetMillions(input, gender) + (negativeNumber ? " inqas minn żero" : String.Empty); } var billions = input / 1000000000; @@ -53,7 +61,7 @@ public override string Convert(long input, GrammaticalGender gender) return billionsText; } - return $"{billionsText} u {millionsText}"; + return $"{billionsText} u {millionsText}" + (negativeNumber ? " inqas minn żero" : String.Empty); } public override string ConvertToOrdinal(int number, GrammaticalGender gender) @@ -211,12 +219,7 @@ private static string GetPrefixText(long thousands, long tensInThousands, string return dual; } - if (tensInThousands > 10 && tensInThousands < 20) - { - return $"{GetHundreds(thousands, true, usePrefixMapForLowerValueDigits, gender)}{singular}"; - } - - if (tensInThousands > 20) + if (tensInThousands > 10) { return $"{GetHundreds(thousands, true, usePrefixMapForLowerValueDigits, gender)} {singular}"; }