Skip to content

Commit

Permalink
Fixed minor issues with Maltese language support
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenmamo committed Nov 23, 2018
1 parent 6c07041 commit 1d0f3e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
39 changes: 21 additions & 18 deletions src/Humanizer.Tests.Shared/Localisation/mt/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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}";
}
Expand Down

0 comments on commit 1d0f3e7

Please sign in to comment.