|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
using Microsoft.AspNetCore.Localization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Localization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using Volo.Abp.Settings;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Mvc.Localization
|
|
|
|
|
{
|
|
|
|
@ -8,12 +11,40 @@ namespace Volo.Abp.AspNetCore.Mvc.Localization
|
|
|
|
|
public class AbpLanguagesController : AbpController
|
|
|
|
|
{
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Switch(string culture, string uiCulture = "") //TODO: Implement return URL
|
|
|
|
|
public IActionResult Switch(string culture, string uiCulture = "", string returnUrl = "")
|
|
|
|
|
{
|
|
|
|
|
//TODO: Check allowed languages and so on...
|
|
|
|
|
if (!GlobalizationHelper.IsValidCultureCode(culture))
|
|
|
|
|
{
|
|
|
|
|
throw new AbpException("Unknown language: " + culture + ". It must be a valid culture!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, $"c={culture}|uic={uiCulture ?? culture}");
|
|
|
|
|
string cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture, uiCulture));
|
|
|
|
|
|
|
|
|
|
Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions
|
|
|
|
|
{
|
|
|
|
|
Expires = Clock.Now.AddYears(2)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(returnUrl))
|
|
|
|
|
{
|
|
|
|
|
return Redirect(GetRedirectUrl(returnUrl));
|
|
|
|
|
}
|
|
|
|
|
return Redirect("/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetRedirectUrl(string returnUrl)
|
|
|
|
|
{
|
|
|
|
|
if (returnUrl.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
return "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Url.IsLocalUrl(returnUrl))
|
|
|
|
|
{
|
|
|
|
|
return returnUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "/";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|