check the culture is supported (#8646)

* check the culture is supported

* changed == to equals
This commit is contained in:
Alessandro Agostini 2023-01-20 12:12:24 +01:00 committed by GitHub
parent eed4a6a11b
commit 7bf78ef852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,11 +7,14 @@ namespace Orchard.Localization.Services {
public class CurrentCultureWorkContext : IWorkContextStateProvider {
private readonly IEnumerable<ICultureSelector> _cultureSelectors;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ICultureManager _cultureManager;
public CurrentCultureWorkContext(IEnumerable<ICultureSelector> cultureSelectors,
IHttpContextAccessor httpContextAccessor) {
IHttpContextAccessor httpContextAccessor,
ICultureManager cultureManager) {
_cultureSelectors = cultureSelectors;
_httpContextAccessor = httpContextAccessor;
_cultureManager = cultureManager;
}
public Func<WorkContext, T> Get<T>(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;
}