Skip to content

Commit 0d598ec

Browse files
committed
ux: format file size based on current culture
1 parent d3d1377 commit 0d598ec

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/App.axaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Globalization;
45
using System.IO;
56
using System.Net.Http;
67
using System.Reflection;
@@ -194,6 +195,17 @@ app.Resources[localeKey] is not ResourceDictionary targetLocale ||
194195
if (app._activeLocale != null)
195196
app.Resources.MergedDictionaries.Remove(app._activeLocale);
196197

198+
try
199+
{
200+
var culture = CultureInfo.GetCultureInfo(localeKey.Replace("_", "-"));
201+
Thread.CurrentThread.CurrentUICulture = culture;
202+
Thread.CurrentThread.CurrentCulture = culture;
203+
}
204+
catch
205+
{
206+
// Just ignore
207+
}
208+
197209
app.Resources.MergedDictionaries.Add(targetLocale);
198210
app._activeLocale = targetLocale;
199211
}

src/Converters/LongConverters.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ public static class LongConverters
77
public static readonly FuncValueConverter<long, string> ToFileSize = new(bytes =>
88
{
99
if (bytes < KB)
10-
return $"{bytes} B";
10+
return $"{bytes:N0} B";
1111

1212
if (bytes < MB)
13-
return $"{(bytes / KB):F3} KB ({bytes} B)";
13+
return $"{(bytes / KB):N3} KB ({bytes:N0})";
1414

1515
if (bytes < GB)
16-
return $"{(bytes / MB):F3} MB ({bytes} B)";
16+
return $"{(bytes / MB):N3} MB ({bytes:N0})";
1717

18-
return $"{(bytes / GB):F3} GB ({bytes} B)";
18+
return $"{(bytes / GB):N3} GB ({bytes:N0})";
1919
});
2020

2121
private const double KB = 1024;

0 commit comments

Comments
 (0)