diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index 83a1f62f27..5de65507a9 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Localization; using Volo.Docs.Documents; using Volo.Docs.HtmlConverting; using Volo.Docs.Models; @@ -72,6 +75,11 @@ namespace Volo.Docs.Pages.Documents.Project { DocumentsUrlPrefix = _options.GetFormattedRoutePrefix(); + if (IsDocumentCultureDifferentThanCurrent()) + { + return ReloadPageWithCulture(); + } + await SetProjectAsync(); await SetProjectsAsync(); await SetVersionAsync(); @@ -94,6 +102,24 @@ namespace Volo.Docs.Pages.Documents.Project return Page(); } + private bool IsDocumentCultureDifferentThanCurrent() + { + var currentCulture = CultureInfo.CurrentCulture; + CultureInfo newCulture; + + try + { + newCulture = CultureInfo.GetCultureInfo(LanguageCode); + + return currentCulture.Name != newCulture.Name; + } + catch (CultureNotFoundException) + { + return false; + } + + } + private bool IsDefaultDocument() { return DocumentName == Project.DefaultDocumentName; @@ -120,6 +146,15 @@ namespace Volo.Docs.Pages.Documents.Project return LanguageConfig.Languages.Any(l => l.Code == LanguageCode); } + private IActionResult ReloadPageWithCulture() + { + var languageCodeWithSlashAtTheEnd = string.IsNullOrWhiteSpace(LanguageCode) ? "" : LanguageCode + "/"; + var returnUrl = "/" + DocumentsUrlPrefix + languageCodeWithSlashAtTheEnd + ProjectName + "/" + Version + "/" + + DocumentName; + + return Redirect("/Abp/Languages/Switch?culture=" + LanguageCode + "&uiCulture=" + LanguageCode + "&returnUrl=" + returnUrl); + } + private IActionResult RedirectToDefaultLanguage() { return RedirectToPage(new