using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Globalization; using System.Security.Principal; using System.Text; using System.Threading; using Umbraco.Core.BackOffice; namespace Umbraco.Core.Security { public static class AuthenticationExtensions { /// /// Ensures that the thread culture is set based on the back office user's culture /// /// public static void EnsureCulture(this IIdentity identity) { if (identity is UmbracoBackOfficeIdentity umbIdentity && umbIdentity.IsAuthenticated) { Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = UserCultures.GetOrAdd(umbIdentity.Culture, s => new CultureInfo(s)); } } /// /// Used so that we aren't creating a new CultureInfo object for every single request /// private static readonly ConcurrentDictionary UserCultures = new ConcurrentDictionary(); } }