From e802723a4c91828fb400429416c789dee34f4cf5 Mon Sep 17 00:00:00 2001 From: Nicholas Mayne Date: Wed, 17 Sep 2014 22:01:13 +0100 Subject: [PATCH] Change to culture of incoming request if culture is in the route data or in params --- .../DefaultFrontEndCultureSelector.cs | 19 ++++++++++++++++--- .../Views/Parts/Search.SearchForm.cshtml | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Providers/DefaultFrontEndCultureSelector.cs b/src/Orchard.Web/Modules/Orchard.Localization/Providers/DefaultFrontEndCultureSelector.cs index f0396d9db..c629869b7 100644 --- a/src/Orchard.Web/Modules/Orchard.Localization/Providers/DefaultFrontEndCultureSelector.cs +++ b/src/Orchard.Web/Modules/Orchard.Localization/Providers/DefaultFrontEndCultureSelector.cs @@ -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) { diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/Parts/Search.SearchForm.cshtml b/src/Orchard.Web/Modules/Orchard.Search/Views/Parts/Search.SearchForm.cshtml index 8675100e2..b6fe2594a 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Views/Parts/Search.SearchForm.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/Parts/Search.SearchForm.cshtml @@ -8,6 +8,7 @@ @using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search-form" })) {
@Html.TextBox("q", (SearchViewModel)Model.ViewModel.Query) + @Html.Hidden("culture", WorkContext.CurrentCulture)
} \ No newline at end of file