From 0e43c7017a6a8985e2a4a2e8d0bdf9873bac131b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20La=C5=A1t=C5=AFvka?= Date: Thu, 30 May 2024 23:02:25 +0200 Subject: [PATCH 1/4] CQ: Add custom number format --- .../Extensions/MessageFormatExtensions.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Extensions/MessageFormatExtensions.cs b/src/Files.App/Extensions/MessageFormatExtensions.cs index 04c74a871678..67b2c6dd08f8 100644 --- a/src/Files.App/Extensions/MessageFormatExtensions.cs +++ b/src/Files.App/Extensions/MessageFormatExtensions.cs @@ -25,11 +25,32 @@ public static class MessageFormatExtensions /// private static readonly CultureInfo _locale = new(AppLanguageHelper.PreferredLanguage.Code); + /// + /// Custom value formatters for the message formatter. + /// This class is used to customize the formatting of specific value types. + /// + private static readonly CustomValueFormatters _customFormatter = new() + { + // Custom formatting for number values. + Number = (CultureInfo _, object? value, string? style, out string? formatted) => + { + if (style is not null && style == string.Empty) + { + // Format the number with commas as thousands separators + formatted = string.Format($"{{0:#,##0}}", value); + return true; + } + formatted = null; + return false; + } + }; + /// /// Message formatter with caching enabled, using the current UI culture's two-letter ISO language name. - /// It is initialized with the options to use cache and the two-letter ISO language name of the current UI culture. + /// It is initialized with the options to use cache and the two-letter ISO language name of the current UI culture, + /// and a custom value formatter for number values. /// - private static readonly MessageFormatter _formatter = new(useCache: true, locale: _locale.TwoLetterISOLanguageName); + private static readonly MessageFormatter _formatter = new(useCache: true, locale: _locale.TwoLetterISOLanguageName, customValueFormatter: _customFormatter); /// /// Creates a dictionary for format pairs with a string key. From 1796e172b8190aedec5e0d282e4cfded816eb60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20La=C5=A1t=C5=AFvka?= <84145589+XTorLukas@users.noreply.github.com> Date: Thu, 30 May 2024 23:25:02 +0200 Subject: [PATCH 2/4] Update MessageFormatExtensions.cs --- src/Files.App/Extensions/MessageFormatExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Extensions/MessageFormatExtensions.cs b/src/Files.App/Extensions/MessageFormatExtensions.cs index 67b2c6dd08f8..04fa1a3670f5 100644 --- a/src/Files.App/Extensions/MessageFormatExtensions.cs +++ b/src/Files.App/Extensions/MessageFormatExtensions.cs @@ -36,7 +36,7 @@ public static class MessageFormatExtensions { if (style is not null && style == string.Empty) { - // Format the number with commas as thousands separators + // Format the number '{0, number}' formatted = string.Format($"{{0:#,##0}}", value); return true; } From 71219f1946bc94c0d0c1d074ba59dcf823aaeb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20La=C5=A1t=C5=AFvka?= <84145589+XTorLukas@users.noreply.github.com> Date: Fri, 31 May 2024 00:24:06 +0200 Subject: [PATCH 3/4] Update src/Files.App/Extensions/MessageFormatExtensions.cs Co-authored-by: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> --- src/Files.App/Extensions/MessageFormatExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Extensions/MessageFormatExtensions.cs b/src/Files.App/Extensions/MessageFormatExtensions.cs index 04fa1a3670f5..fb7ac9eb7352 100644 --- a/src/Files.App/Extensions/MessageFormatExtensions.cs +++ b/src/Files.App/Extensions/MessageFormatExtensions.cs @@ -26,7 +26,7 @@ public static class MessageFormatExtensions private static readonly CultureInfo _locale = new(AppLanguageHelper.PreferredLanguage.Code); /// - /// Custom value formatters for the message formatter. + /// Gets custom value formatters for the message formatter. /// This class is used to customize the formatting of specific value types. /// private static readonly CustomValueFormatters _customFormatter = new() From 8d8b874f0982e3aebad6fca1f77ca9ba19df562a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20La=C5=A1t=C5=AFvka?= <84145589+XTorLukas@users.noreply.github.com> Date: Fri, 31 May 2024 00:24:15 +0200 Subject: [PATCH 4/4] Update src/Files.App/Extensions/MessageFormatExtensions.cs Co-authored-by: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> --- src/Files.App/Extensions/MessageFormatExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/Extensions/MessageFormatExtensions.cs b/src/Files.App/Extensions/MessageFormatExtensions.cs index fb7ac9eb7352..4698d0a26e85 100644 --- a/src/Files.App/Extensions/MessageFormatExtensions.cs +++ b/src/Files.App/Extensions/MessageFormatExtensions.cs @@ -40,6 +40,7 @@ public static class MessageFormatExtensions formatted = string.Format($"{{0:#,##0}}", value); return true; } + formatted = null; return false; }