GetListItemText_ru_RU.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace OpenXmlPowerTools
  8. {
  9. public class ListItemTextGetter_ru_RU
  10. {
  11. private static string[] OneThroughNineteen = {
  12. "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь",
  13. "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать",
  14. "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать"
  15. };
  16. private static string[] Tens = {
  17. "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят",
  18. "восемьдесят", "девяносто"
  19. };
  20. private static string[] OrdinalOneThroughNineteen = {
  21. "первый", "второй", "третий", "четвертый", "пятый", "шестой",
  22. "седьмой", "восьмой", "девятый", "десятый", "одиннадцатый", "двенадцатый",
  23. "тринадцатый", "четырнадцатый", "пятнадцатый", "шестнадцатый",
  24. "семнадцатый", "восемнадцатый", "девятнадцатый"
  25. };
  26. private static string[] OrdinalTenths = {
  27. "десятый", "двадцатый", "тридцатый", "сороковой", "пятидесятый",
  28. "шестидесятый", "семидесятый", "восьмидесятый", "девяностый"
  29. };
  30. // TODO this is not correct for values above 99
  31. public static string GetListItemText(string languageCultureName, int levelNumber, string numFmt)
  32. {
  33. if (numFmt == "cardinalText")
  34. {
  35. string result = "";
  36. int t1 = levelNumber / 1000;
  37. int t2 = levelNumber % 1000;
  38. if (t1 >= 1)
  39. result += OneThroughNineteen[t1 - 1] + " thousand";
  40. if (t1 >= 1 && t2 == 0)
  41. return result.Substring(0, 1).ToUpper() +
  42. result.Substring(1);
  43. if (t1 >= 1)
  44. result += " ";
  45. int h1 = (levelNumber % 1000) / 100;
  46. int h2 = levelNumber % 100;
  47. if (h1 >= 1)
  48. result += OneThroughNineteen[h1 - 1] + " hundred";
  49. if (h1 >= 1 && h2 == 0)
  50. return result.Substring(0, 1).ToUpper() +
  51. result.Substring(1);
  52. if (h1 >= 1)
  53. result += " ";
  54. int z = levelNumber % 100;
  55. if (z <= 19)
  56. result += OneThroughNineteen[z - 1];
  57. else
  58. {
  59. int x = z / 10;
  60. int r = z % 10;
  61. result += Tens[x - 1];
  62. if (r >= 1)
  63. result += "-" + OneThroughNineteen[r - 1];
  64. }
  65. return result.Substring(0, 1).ToUpper() +
  66. result.Substring(1);
  67. }
  68. if (numFmt == "ordinalText")
  69. {
  70. string result = "";
  71. int t1 = levelNumber / 1000;
  72. int t2 = levelNumber % 1000;
  73. if (t1 >= 1 && t2 != 0)
  74. result += OneThroughNineteen[t1 - 1] + " thousand";
  75. if (t1 >= 1 && t2 == 0)
  76. {
  77. result += OneThroughNineteen[t1 - 1] + " thousandth";
  78. return result.Substring(0, 1).ToUpper() +
  79. result.Substring(1);
  80. }
  81. if (t1 >= 1)
  82. result += " ";
  83. int h1 = (levelNumber % 1000) / 100;
  84. int h2 = levelNumber % 100;
  85. if (h1 >= 1 && h2 != 0)
  86. result += OneThroughNineteen[h1 - 1] + " hundred";
  87. if (h1 >= 1 && h2 == 0)
  88. {
  89. result += OneThroughNineteen[h1 - 1] + " hundredth";
  90. return result.Substring(0, 1).ToUpper() +
  91. result.Substring(1);
  92. }
  93. if (h1 >= 1)
  94. result += " ";
  95. int z = levelNumber % 100;
  96. if (z <= 19)
  97. result += OrdinalOneThroughNineteen[z - 1];
  98. else
  99. {
  100. int x = z / 10;
  101. int r = z % 10;
  102. if (r == 0)
  103. result += OrdinalTenths[x - 1];
  104. else
  105. result += Tens[x - 1];
  106. if (r >= 1)
  107. result += " " + OrdinalOneThroughNineteen[r - 1];
  108. }
  109. return result.Substring(0, 1).ToUpper() +
  110. result.Substring(1);
  111. }
  112. return null;
  113. }
  114. }
  115. }