mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 20:09:09 +08:00
check the culture is supported (#8646)
* check the culture is supported * changed == to equals
This commit is contained in:
parent
eed4a6a11b
commit
7bf78ef852
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user