You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

154 lines
4.5 KiB

  1. using System;
  2. namespace CIG.Translation
  3. {
  4. public class RawTimeSpanString : ILocalizedString
  5. {
  6. public RawTimeSpanString(TimeSpan dateTime, bool hidePartWhenZero, int showParts)
  7. {
  8. this._dateTime = dateTime;
  9. this._hidePartWhenZero = hidePartWhenZero;
  10. this._showParts = showParts;
  11. }
  12. public override string ToString()
  13. {
  14. return string.Concat(new object[]
  15. {
  16. "[TimeSpan=",
  17. this._dateTime.ToString(),
  18. ",HideZero=",
  19. this._hidePartWhenZero,
  20. ",#Parts=",
  21. this._showParts,
  22. "]"
  23. });
  24. }
  25. public string Translate()
  26. {
  27. ILocalizedString localizedString = null;
  28. ILocalizedString localizedString2 = null;
  29. ILocalizedString localizedString3 = null;
  30. ILocalizedString localizedString4;
  31. if ((double)this._dateTime.Days > 0.0)
  32. {
  33. localizedString4 = Localization.Format(Localization.Key("day_symbol"), new ILocalizedString[]
  34. {
  35. Localization.Literal(string.Format("{0:D}", this._dateTime.Days))
  36. });
  37. if (this._showParts >= 2 && (this._dateTime.Hours > 0 || !this._hidePartWhenZero))
  38. {
  39. localizedString = Localization.Format(Localization.Key("hour_symbol"), new ILocalizedString[]
  40. {
  41. Localization.Literal(string.Format("{0:D}", this._dateTime.Hours))
  42. });
  43. }
  44. if (this._showParts >= 3 && (this._dateTime.Minutes > 0 || !this._hidePartWhenZero))
  45. {
  46. localizedString2 = Localization.Format(Localization.Key("minute_symbol"), new ILocalizedString[]
  47. {
  48. Localization.Literal(string.Format("{0:D}", this._dateTime.Minutes))
  49. });
  50. }
  51. if (this._showParts >= 4 && (this._dateTime.Seconds > 0 || !this._hidePartWhenZero))
  52. {
  53. localizedString3 = Localization.Format(Localization.Key("second_symbol"), new ILocalizedString[]
  54. {
  55. Localization.Literal(string.Format("{0:D}", this._dateTime.Seconds))
  56. });
  57. }
  58. }
  59. else if (this._dateTime.Hours > 0)
  60. {
  61. localizedString4 = Localization.Format(Localization.Key("hour_symbol"), new ILocalizedString[]
  62. {
  63. Localization.Literal(string.Format("{0:D}", this._dateTime.Hours))
  64. });
  65. if (this._showParts >= 2 && (this._dateTime.Minutes > 0 || !this._hidePartWhenZero))
  66. {
  67. localizedString = Localization.Format(Localization.Key("minute_symbol"), new ILocalizedString[]
  68. {
  69. Localization.Literal(string.Format("{0:D}", this._dateTime.Minutes))
  70. });
  71. }
  72. if (this._showParts >= 3 && (this._dateTime.Seconds > 0 || !this._hidePartWhenZero))
  73. {
  74. localizedString2 = Localization.Format(Localization.Key("second_symbol"), new ILocalizedString[]
  75. {
  76. Localization.Literal(string.Format("{0:D}", this._dateTime.Seconds))
  77. });
  78. }
  79. }
  80. else
  81. {
  82. if (this._dateTime.Minutes > 0)
  83. {
  84. localizedString4 = Localization.Format(Localization.Key("minute_symbol"), new ILocalizedString[]
  85. {
  86. Localization.Literal(string.Format("{0:D}", this._dateTime.Minutes))
  87. });
  88. }
  89. else if (this._showParts >= 2)
  90. {
  91. localizedString4 = Localization.Literal(string.Empty);
  92. }
  93. else
  94. {
  95. localizedString4 = Localization.Format(Localization.Key("second_symbol"), new ILocalizedString[]
  96. {
  97. Localization.Literal(string.Format("{0:D}", this._dateTime.Seconds))
  98. });
  99. }
  100. if (this._showParts >= 2 && (this._dateTime.Seconds > 0 || !this._hidePartWhenZero))
  101. {
  102. localizedString = Localization.Format(Localization.Key("second_symbol"), new ILocalizedString[]
  103. {
  104. Localization.Literal(string.Format("{0:D}", this._dateTime.Seconds))
  105. });
  106. }
  107. }
  108. if (localizedString == null)
  109. {
  110. return localizedString4.Translate();
  111. }
  112. if (localizedString2 == null)
  113. {
  114. return Localization.Concat(new ILocalizedString[]
  115. {
  116. localizedString4,
  117. Localization.Literal(" "),
  118. localizedString
  119. }).Translate();
  120. }
  121. if (localizedString3 == null)
  122. {
  123. return Localization.Concat(new ILocalizedString[]
  124. {
  125. localizedString4,
  126. Localization.Literal(" "),
  127. localizedString,
  128. Localization.Literal(" "),
  129. localizedString2
  130. }).Translate();
  131. }
  132. return Localization.Concat(new ILocalizedString[]
  133. {
  134. localizedString4,
  135. Localization.Literal(" "),
  136. localizedString,
  137. Localization.Literal(" "),
  138. localizedString2,
  139. Localization.Literal(" "),
  140. localizedString3
  141. }).Translate();
  142. }
  143. private TimeSpan _dateTime;
  144. private bool _hidePartWhenZero;
  145. private int _showParts;
  146. }
  147. }