using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace MaksIT.Core; /// /// The main Cultures class. /// Contains all methods for performing basic Cultures management. /// public static class Culture { /// /// Sets the culture for the current thread. /// /// The culture to set. If null or empty, the invariant culture is used. /// The error message if the operation fails. /// True if the operation was successful; otherwise, false. public static bool TrySet(string? culture, [NotNullWhen(false)] out string? errorMessage) { try { var threadCulture = CultureInfo.InvariantCulture; if (!string.IsNullOrEmpty(culture)) { threadCulture = CultureInfo.CreateSpecificCulture(culture); } Thread.CurrentThread.CurrentUICulture = threadCulture; Thread.CurrentThread.CurrentCulture = threadCulture; errorMessage = null; return true; } catch (Exception ex) { errorMessage = ex.Message; return false; } } }