mirror of https://github.com/abpframework/abp.git
Browse Source
Replace the `culture` and `ui-culture` in the `url` while switching language.pull/9556/head
committed by
GitHub
4 changed files with 78 additions and 4 deletions
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class AbpAspNetCoreMvcQueryStringCultureReplacement : IQueryStringCultureReplacement, ITransientDependency |
|||
{ |
|||
public virtual Task ReplaceAsync(QueryStringCultureReplacementContext context) |
|||
{ |
|||
if (!string.IsNullOrWhiteSpace(context.ReturnUrl)) |
|||
{ |
|||
if (context.ReturnUrl.Contains("culture=", StringComparison.OrdinalIgnoreCase) && |
|||
context.ReturnUrl.Contains("ui-Culture=", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
context.ReturnUrl = Regex.Replace( |
|||
context.ReturnUrl, |
|||
"culture=[A-Za-z-]+?&", |
|||
$"culture={context.RequestCulture.Culture}&", |
|||
RegexOptions.Compiled | RegexOptions.IgnoreCase); |
|||
|
|||
context.ReturnUrl = Regex.Replace( |
|||
context.ReturnUrl, "ui-culture=[A-Za-z-]+?$", |
|||
$"ui-culture={context.RequestCulture.UICulture}", |
|||
RegexOptions.Compiled | RegexOptions.IgnoreCase); |
|||
} |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public interface IQueryStringCultureReplacement |
|||
{ |
|||
Task ReplaceAsync(QueryStringCultureReplacementContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Localization; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class QueryStringCultureReplacementContext |
|||
{ |
|||
public HttpContext HttpContext { get; } |
|||
|
|||
public RequestCulture RequestCulture { get; } |
|||
|
|||
public string ReturnUrl { get; set; } |
|||
|
|||
public QueryStringCultureReplacementContext(HttpContext httpContext, RequestCulture requestCulture, string returnUrl) |
|||
{ |
|||
HttpContext = httpContext; |
|||
RequestCulture = requestCulture; |
|||
ReturnUrl = returnUrl; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue