Set default language if the culture not supported
This commit is contained in:
parent
7057f93f13
commit
90ca6aafe9
|
@ -5,6 +5,7 @@ using Oqtane.Modules;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Themes;
|
using Oqtane.Themes;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Http.Extensions;
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
|
@ -45,18 +46,20 @@ namespace Oqtane.Pages
|
||||||
// if framework is installed
|
// if framework is installed
|
||||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
||||||
{
|
{
|
||||||
Uri uri = new Uri(Request.GetDisplayUrl());
|
var uri = new Uri(Request.GetDisplayUrl());
|
||||||
var alias = _aliases.GetAlias(uri.Authority + "/" + uri.LocalPath.Substring(1));
|
var alias = _aliases.GetAlias(uri.Authority + "/" + uri.LocalPath.Substring(1));
|
||||||
_state.Alias = alias;
|
_state.Alias = alias;
|
||||||
|
|
||||||
// set default language for site
|
// set default language for site if the culture is not supported
|
||||||
var language = _languages.GetLanguages(alias.SiteId).Where(item => item.IsDefault).FirstOrDefault();
|
var languages = _languages.GetLanguages(alias.SiteId);
|
||||||
if (language != null)
|
if (languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name))
|
||||||
{
|
{
|
||||||
|
var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First();
|
||||||
|
|
||||||
HttpContext.Response.Cookies.Append(
|
HttpContext.Response.Cookies.Append(
|
||||||
CookieRequestCultureProvider.DefaultCookieName,
|
CookieRequestCultureProvider.DefaultCookieName,
|
||||||
CookieRequestCultureProvider.MakeCookieValue(
|
CookieRequestCultureProvider.MakeCookieValue(
|
||||||
new RequestCulture(language.Code)));
|
new RequestCulture(defaultLanguage.Code)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user