Humanize TimeSpans, get rid of dirty manual TimeSpan translations

This commit is contained in:
JustArchi
2017-04-08 05:05:09 +02:00
parent 8c0a100ae8
commit 92bb7d0927
128 changed files with 5616 additions and 136 deletions

View File

@@ -79,6 +79,9 @@
<HintPath>..\packages\HtmlAgilityPack.1.4.9.5\lib\Net45\HtmlAgilityPack.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Humanizer, Version=2.1.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e, processorArchitecture=MSIL">
<HintPath>..\packages\Humanizer.Core.2.1.0\lib\netstandard1.0\Humanizer.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

View File

@@ -1224,78 +1224,6 @@ namespace ArchiSteamFarm.Localization {
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu 1 day.
/// </summary>
internal static string TimeSpanDay {
get {
return ResourceManager.GetString("TimeSpanDay", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu {0} days.
/// </summary>
internal static string TimeSpanDays {
get {
return ResourceManager.GetString("TimeSpanDays", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu 1 hour.
/// </summary>
internal static string TimeSpanHour {
get {
return ResourceManager.GetString("TimeSpanHour", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu {0} hours.
/// </summary>
internal static string TimeSpanHours {
get {
return ResourceManager.GetString("TimeSpanHours", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu 1 minute.
/// </summary>
internal static string TimeSpanMinute {
get {
return ResourceManager.GetString("TimeSpanMinute", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu {0} minutes.
/// </summary>
internal static string TimeSpanMinutes {
get {
return ResourceManager.GetString("TimeSpanMinutes", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu 1 second.
/// </summary>
internal static string TimeSpanSecond {
get {
return ResourceManager.GetString("TimeSpanSecond", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu {0} seconds.
/// </summary>
internal static string TimeSpanSeconds {
get {
return ResourceManager.GetString("TimeSpanSeconds", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu ASF will attempt to use your preferred {0} culture, but translation in that language was completed only in {1}. Perhaps you could help us improve ASF translation for your language?.
/// </summary>

View File

@@ -255,34 +255,6 @@ StackTrace:
<data name="Success" xml:space="preserve">
<value>Success!</value>
</data>
<data name="TimeSpanDay" xml:space="preserve">
<value>1 day</value>
</data>
<data name="TimeSpanDays" xml:space="preserve">
<value>{0} days</value>
<comment>{0} will be replaced by number of days</comment>
</data>
<data name="TimeSpanHour" xml:space="preserve">
<value>1 hour</value>
</data>
<data name="TimeSpanHours" xml:space="preserve">
<value>{0} hours</value>
<comment>{0} will be replaced by number of hours</comment>
</data>
<data name="TimeSpanMinute" xml:space="preserve">
<value>1 minute</value>
</data>
<data name="TimeSpanMinutes" xml:space="preserve">
<value>{0} minutes</value>
<comment>{0} will be replaced by number of minutes</comment>
</data>
<data name="TimeSpanSecond" xml:space="preserve">
<value>1 second</value>
</data>
<data name="TimeSpanSeconds" xml:space="preserve">
<value>{0} seconds</value>
<comment>{0} will be replaced by number of seconds</comment>
</data>
<data name="UnlockingParentalAccount" xml:space="preserve">
<value>Unlocking parental account...</value>
</data>

View File

@@ -29,8 +29,7 @@ using System.Globalization;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using ArchiSteamFarm.Localization;
using Humanizer;
namespace ArchiSteamFarm {
internal static class Utilities {
@@ -109,38 +108,7 @@ namespace ArchiSteamFarm {
yield return item;
}
internal static string ToHumanReadable(this TimeSpan timeSpan) {
// It's really dirty, I'd appreciate a lot if C# offered nice TimeSpan formatting by default
// Normally I'd use third-party library like Humanizer, but using it only for this bit is not worth it
// Besides, ILRepack has problem merging it's library due to referencing System.Runtime
StringBuilder result = new StringBuilder();
if (timeSpan.Days > 0) {
result.Append((timeSpan.Days > 1 ? string.Format(Strings.TimeSpanDays, timeSpan.Days) : Strings.TimeSpanDay) + ", ");
}
if (timeSpan.Hours > 0) {
result.Append((timeSpan.Hours > 1 ? string.Format(Strings.TimeSpanHours, timeSpan.Hours) : Strings.TimeSpanHour) + ", ");
}
if (timeSpan.Minutes > 0) {
result.Append((timeSpan.Minutes > 1 ? string.Format(Strings.TimeSpanMinutes, timeSpan.Minutes) : Strings.TimeSpanMinute) + ", ");
}
if (timeSpan.Seconds > 0) {
result.Append((timeSpan.Seconds > 1 ? string.Format(Strings.TimeSpanSeconds, timeSpan.Seconds) : Strings.TimeSpanSecond) + ", ");
}
if (result.Length == 0) {
return string.Format(Strings.TimeSpanSeconds, 0);
}
// Get rid of last comma + space
result.Length -= 2;
return result.ToString();
}
internal static string ToHumanReadable(this TimeSpan timeSpan) => timeSpan.Humanize(4);
private static string[] GetArgs(this string[] args, byte argsToSkip = 1) {
if (args.Length < argsToSkip) {

View File

@@ -1,9 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" />
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" />
<package id="Humanizer" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.af" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.ar" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.bg" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.bn-BD" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.cs" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.da" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.de" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.el" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.es" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.fa" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.fi-FI" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.fr" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.fr-BE" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.he" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.hr" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.hu" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.id" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.it" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.ja" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.nb" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.nb-NO" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.nl" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.pl" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.pt" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.ro" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.ru" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.sk" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.sl" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.sr" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.sr-Latn" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.sv" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.tr" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.uk" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.uz-Cyrl-UZ" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.uz-Latn-UZ" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.vi" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.zh-CN" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.zh-Hans" version="2.1.0" targetFramework="net461" />
<package id="Humanizer.Core.zh-Hant" version="2.1.0" targetFramework="net461" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net461" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" />