Browse Source

docs module: changing language now effects the current culture

resolves https://github.com/abpframework/abp/issues/1217
pull/1236/head
Yunus Emre Kalkan 7 years ago
parent
commit
7a7887be7d
  1. 35
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

35
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

Loading…
Cancel
Save