ux: format file size based on current culture

This commit is contained in:
leo
2025-07-10 11:43:28 +08:00
parent d3d1377334
commit a687de36da
2 changed files with 16 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Reflection;
@@ -194,6 +195,17 @@ namespace SourceGit
if (app._activeLocale != null)
app.Resources.MergedDictionaries.Remove(app._activeLocale);
try
{
var culture = CultureInfo.GetCultureInfo(localeKey.Replace("_", "-"));
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
}
catch
{
// Just ignore
}
app.Resources.MergedDictionaries.Add(targetLocale);
app._activeLocale = targetLocale;
}

View File

@@ -7,15 +7,15 @@ namespace SourceGit.Converters
public static readonly FuncValueConverter<long, string> ToFileSize = new(bytes =>
{
if (bytes < KB)
return $"{bytes} B";
return $"{bytes:N0} B";
if (bytes < MB)
return $"{(bytes / KB):F3} KB ({bytes} B)";
return $"{(bytes / KB):N3} KB ({bytes:N0})";
if (bytes < GB)
return $"{(bytes / MB):F3} MB ({bytes} B)";
return $"{(bytes / MB):N3} MB ({bytes:N0})";
return $"{(bytes / GB):F3} GB ({bytes} B)";
return $"{(bytes / GB):N3} GB ({bytes:N0})";
});
private const double KB = 1024;