diff --git a/src/Orchard/Localization/Services/CurrentCultureWorkContext.cs b/src/Orchard/Localization/Services/CurrentCultureWorkContext.cs index 16208ccbf..7efe5c68e 100644 --- a/src/Orchard/Localization/Services/CurrentCultureWorkContext.cs +++ b/src/Orchard/Localization/Services/CurrentCultureWorkContext.cs @@ -7,11 +7,14 @@ namespace Orchard.Localization.Services { public class CurrentCultureWorkContext : IWorkContextStateProvider { private readonly IEnumerable _cultureSelectors; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ICultureManager _cultureManager; public CurrentCultureWorkContext(IEnumerable cultureSelectors, - IHttpContextAccessor httpContextAccessor) { + IHttpContextAccessor httpContextAccessor, + ICultureManager cultureManager) { _cultureSelectors = cultureSelectors; _httpContextAccessor = httpContextAccessor; + _cultureManager = cultureManager; } public Func Get(string name) { @@ -25,11 +28,13 @@ namespace Orchard.Localization.Services { private string GetCurrentCulture() { var httpContext = _httpContextAccessor.Current(); + var supportedCultures = _cultureManager.ListCultures().ToList(); + var culture = _cultureSelectors .Select(c => c.GetCulture(httpContext)) .Where(c => c != null) .OrderByDescending(c => c.Priority) - .FirstOrDefault(c => !String.IsNullOrEmpty(c.CultureName)); + .FirstOrDefault(c => !String.IsNullOrEmpty(c.CultureName) && supportedCultures.Any(s => s.Equals(c.CultureName, StringComparison.OrdinalIgnoreCase))); return culture == null ? String.Empty : culture.CultureName; }