mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Change to culture of incoming request if culture is in the route data or in params
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Alias;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -34,11 +35,23 @@ namespace Orchard.Localization.Providers {
|
||||
if (!IsActivable(context))
|
||||
return null;
|
||||
|
||||
var path = context.Request.Path;
|
||||
if (context.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)
|
||||
&& context.Request.UrlReferrer != null) {
|
||||
// Attempt to determine culture by route.
|
||||
// This normally happens when you are using non standard pages that are not content items
|
||||
// {culture}/foo
|
||||
var routeCulture = context.Request.RequestContext.RouteData.Values["culture"] ??
|
||||
context.Request.RequestContext.HttpContext.Request.Params["culture"];
|
||||
if (routeCulture != null && !string.IsNullOrWhiteSpace(routeCulture.ToString())) {
|
||||
return new CultureSelectorResult { Priority = -1, CultureName = routeCulture.ToString() };
|
||||
}
|
||||
|
||||
// Attempt to determine culture by previous route if by POST
|
||||
string path = string.Empty;
|
||||
if (context.Request.HttpMethod.Equals(HttpVerbs.Post.ToString(), StringComparison.OrdinalIgnoreCase)) {
|
||||
path = context.Request.UrlReferrer.AbsolutePath;
|
||||
}
|
||||
else {
|
||||
path = context.Request.Path;
|
||||
}
|
||||
|
||||
var content = GetByPath(path.TrimStart('/'));
|
||||
if (content != null) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
@using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search-form" })) {
|
||||
<fieldset>
|
||||
@Html.TextBox("q", (SearchViewModel)Model.ViewModel.Query)
|
||||
@Html.Hidden("culture", WorkContext.CurrentCulture)
|
||||
<button type="submit">@T("Search")</button>
|
||||
</fieldset>
|
||||
}
|
||||
Reference in New Issue
Block a user