From 20c1197793b6218c3dcf3db09e15d0456589bb08 Mon Sep 17 00:00:00 2001 From: James Yeung Date: Thu, 17 Sep 2020 16:42:23 +0800 Subject: [PATCH] docs: follow up the .net 5 docs and fix the culture issue (#615) --- components/menu/Menu.razor.cs | 10 +++++----- site/AntBlazor.Docs/Routing/ConventionRouter.cs | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/components/menu/Menu.razor.cs b/components/menu/Menu.razor.cs index 7b78009b..da5df0b1 100644 --- a/components/menu/Menu.razor.cs +++ b/components/menu/Menu.razor.cs @@ -124,14 +124,14 @@ namespace AntDesign return; } + foreach (MenuItem menuitem in MenuItems.Where(x => x != item)) + { + menuitem.Deselect(); + } + if (!item.IsSelected) { item.Select(); - - foreach (MenuItem menuitem in MenuItems.Where(x => x != item)) - { - menuitem.Deselect(); - } } StateHasChanged(); diff --git a/site/AntBlazor.Docs/Routing/ConventionRouter.cs b/site/AntBlazor.Docs/Routing/ConventionRouter.cs index ba49c9e4..2e3f9582 100644 --- a/site/AntBlazor.Docs/Routing/ConventionRouter.cs +++ b/site/AntBlazor.Docs/Routing/ConventionRouter.cs @@ -26,8 +26,6 @@ namespace AntDesign.Docs.Routing [Parameter] public string DefaultUrl { get; set; } - private static CultureInfo[] AllCultureInfos => CultureInfo.GetCultures(CultureTypes.AllCultures); - public void Attach(RenderHandle renderHandle) { _renderHandle = renderHandle; @@ -93,19 +91,23 @@ namespace AntDesign.Docs.Routing var currentCulture = LanguageService.CurrentCulture; - var segment = relativeUri.IndexOf('/') > 0 ? relativeUri.Substring(0, relativeUri.IndexOf('/')) : null; + var segment = relativeUri.IndexOf('/') > 0 ? relativeUri.Substring(0, relativeUri.IndexOf('/')) : relativeUri; - if (segment == null) + if (string.IsNullOrWhiteSpace(segment)) { NavigationManager.NavigateTo($"{currentCulture.Name}/{relativeUri}", true); return; } else { - if (AllCultureInfos.Any(x => x.Name == segment)) + if (segment.IsIn("zh-CN", "en-US")) { LanguageService.SetLanguage(CultureInfo.GetCultureInfo(segment)); } + else if (currentCulture.Name.IsIn("zh-CN", "en-US")) + { + NavigationManager.NavigateTo($"{currentCulture.Name}/{relativeUri}", true); + } else { NavigationManager.NavigateTo($"en-US/{relativeUri}", true);