From 22b8bdd576c0810ad3b22addaa32b98c6d79df0a Mon Sep 17 00:00:00 2001 From: nilsk Date: Tue, 31 Mar 2026 14:41:50 +0200 Subject: [PATCH] added common function to derive CultureInfo for formatting from the active plugins IETF Tag --- app/MindWork AI Studio/Tools/CommonTools.cs | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/MindWork AI Studio/Tools/CommonTools.cs b/app/MindWork AI Studio/Tools/CommonTools.cs index 26150880..fd3542b5 100644 --- a/app/MindWork AI Studio/Tools/CommonTools.cs +++ b/app/MindWork AI Studio/Tools/CommonTools.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Text; namespace AIStudio.Tools; @@ -19,4 +20,32 @@ public static class CommonTools return sb.ToString(); } -} \ No newline at end of file + + /// + /// Resolves a from the active language plugin's IETF tag. + /// + /// The IETF language tag provided by the active language plugin. + /// The matching culture when the tag is valid; otherwise . + public static CultureInfo DeriveActiveCultureOrInvariant(string? ietfTag) + { + if (string.IsNullOrWhiteSpace(ietfTag)) + return CultureInfo.InvariantCulture; + + try + { + return CultureInfo.GetCultureInfo(ietfTag); + } + catch (CultureNotFoundException) + { + return CultureInfo.InvariantCulture; + } + } + + /// + /// Formats a timestamp using the short date and time pattern of the specified culture. + /// + /// The timestamp to format. + /// The culture whose short date and time pattern should be used. + /// The localized timestamp string. + public static string FormatTimestampToGeneral(DateTime timestamp, CultureInfo culture) => timestamp.ToString("g", culture); +}