Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add russian translation for ToWords #147

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
provide the possiblity to use gender only if required by language
  • Loading branch information
mexx committed Apr 12, 2014
commit 70f671e4dd3d4047e7f7a9d2fb11f24db9877973
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class ArabicNumberToWordsConverter : DefaultNumberToWordsConverter
private static readonly string[] AppendedTwos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن" };
private static readonly string[] Twos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان" };

public override string Convert(int number, GrammaticalGender gender)
public override string Convert(int number)
{
if (number == 0)
return "صفر";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
internal class DefaultNumberToWordsConverter : INumberToWordsConverter
{
public virtual string Convert(int number, GrammaticalGender gender)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as mentioned above, this is unnecessary API change that would be good if we could avoid.

{
return Convert(number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much neater. Thanks.

}

public virtual string Convert(int number)
{
return number.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Humanizer.Localisation.NumberToWords
{
internal class EnglishNumberToWordsConverter : INumberToWordsConverter
internal class EnglishNumberToWordsConverter : DefaultNumberToWordsConverter
{
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" };
Expand All @@ -20,37 +20,37 @@ internal class EnglishNumberToWordsConverter : INumberToWordsConverter
{12, "twelfth"},
};

public string Convert(int number, GrammaticalGender gender)
public override string Convert(int number)
{
if (number == 0)
return "zero";

if (number < 0)
return string.Format("minus {0}", Convert(-number, gender));
return string.Format("minus {0}", Convert(-number));

var parts = new List<string>();

if ((number / 1000000000) > 0)
{
parts.Add(string.Format("{0} billion", Convert(number / 1000000000, gender)));
parts.Add(string.Format("{0} billion", Convert(number / 1000000000)));
number %= 1000000000;
}

if ((number / 1000000) > 0)
{
parts.Add(string.Format("{0} million", Convert(number / 1000000, gender)));
parts.Add(string.Format("{0} million", Convert(number / 1000000)));
number %= 1000000;
}

if ((number / 1000) > 0)
{
parts.Add(string.Format("{0} thousand", Convert(number / 1000, gender)));
parts.Add(string.Format("{0} thousand", Convert(number / 1000)));
number %= 1000;
}

if ((number / 100) > 0)
{
parts.Add(string.Format("{0} hundred", Convert(number / 100, gender)));
parts.Add(string.Format("{0} hundred", Convert(number / 100)));
number %= 100;
}

Expand All @@ -74,7 +74,7 @@ public string Convert(int number, GrammaticalGender gender)
return string.Join(" ", parts.ToArray());
}

public string ConvertToOrdinal(int number)
public override string ConvertToOrdinal(int number)
{
string towords;
// 9 => ninth
Expand All @@ -88,7 +88,7 @@ public string ConvertToOrdinal(int number)
if (ExceptionNumbersToWords(number%10, out exceptionPart))
{
var normalPart = number - number%10;
towords = RemoveOnePrefix(Convert(normalPart, GrammaticalGender.Masculine));
towords = RemoveOnePrefix(Convert(normalPart));
return towords + " " + exceptionPart;
}
}
Expand All @@ -98,7 +98,7 @@ public string ConvertToOrdinal(int number)

private string NormalNumberToWords(int number)
{
string towords = Convert(number, GrammaticalGender.Masculine).Replace('-', ' ');
string towords = Convert(number).Replace('-', ' ');

towords = RemoveOnePrefix(towords);
// twenty => twentieth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ internal class FarsiNumberToWordsConverter : DefaultNumberToWordsConverter
private static readonly string[] FarsiTensMap = { "صفر", "ده", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود" };
private static readonly string[] FarsiUnitsMap = { "صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه", "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده" };

public override string Convert(int number, GrammaticalGender gender)
public override string Convert(int number)
{
if (number < 0)
return string.Format("منفی {0}", Convert(-number, gender));
return string.Format("منفی {0}", Convert(-number));

if (number == 0)
return "صفر";

var farsiGroupsMap = new Dictionary<int, Func<int, string>>
{
{(int)Math.Pow(10, 9), n => string.Format("{0} میلیارد", Convert(n, gender)) },
{(int)Math.Pow(10, 6), n => string.Format("{0} میلیون", Convert(n, gender)) },
{(int)Math.Pow(10, 3), n => string.Format("{0} هزار", Convert(n, gender)) },
{(int)Math.Pow(10, 9), n => string.Format("{0} میلیارد", Convert(n)) },
{(int)Math.Pow(10, 6), n => string.Format("{0} میلیون", Convert(n)) },
{(int)Math.Pow(10, 3), n => string.Format("{0} هزار", Convert(n)) },
{(int)Math.Pow(10, 2), n => FarsiHundredsMap[n]}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static string GetSuffix(Numeral numeral, int num)
}
}

public override string Convert(int number, GrammaticalGender gender)
public override string Convert(int number)
{
if (number == 0)
return Zero;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

namespace Humanizer.Localisation.NumberToWords
{
internal class SpanishNumberToWordsConverter : INumberToWordsConverter
internal class SpanishNumberToWordsConverter : DefaultNumberToWordsConverter
{
private static readonly string[] HundredsMap = { "cero", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" };
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" };
private static readonly string[] TensMap = { "cero", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" };

public string Convert(int number, GrammaticalGender gender)
public override string Convert(int number)
{
if (number == 0)
return "cero";

if (number < 0)
return string.Format("menos {0}", Convert(Math.Abs(number), gender));
return string.Format("menos {0}", Convert(Math.Abs(number)));

var parts = new List<string>();

if ((number / 1000000000) > 0)
{
parts.Add(number/1000000000 == 1
? string.Format("mil millones")
: string.Format("{0} mil millones", Convert(number / 1000000000, gender)));
: string.Format("{0} mil millones", Convert(number/1000000000)));

number %= 1000000000;
}
Expand All @@ -32,7 +32,7 @@ public string Convert(int number, GrammaticalGender gender)
{
parts.Add(number/1000000 == 1
? string.Format("millón")
: string.Format("{0} millones", Convert(number / 1000000, gender)));
: string.Format("{0} millones", Convert(number/1000000)));

number %= 1000000;
}
Expand All @@ -41,7 +41,7 @@ public string Convert(int number, GrammaticalGender gender)
{
parts.Add(number/1000 == 1
? string.Format("mil")
: string.Format("{0} mil", Convert(number / 1000, gender)));
: string.Format("{0} mil", Convert(number/1000)));

number %= 1000;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public string Convert(int number, GrammaticalGender gender)
return string.Join(" ", parts.ToArray());
}

public string ConvertToOrdinal(int number)
public override string ConvertToOrdinal(int number)
{
throw new NotImplementedException();
}
Expand Down