From cb2feb3a6bd80e55a829cfbd166ca1dd337aef4d Mon Sep 17 00:00:00 2001 From: Diego <2248356998@qq.com> Date: Fri, 9 May 2025 15:49:29 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BB=8E=E7=88=B6=E7=B1=BB=E4=B8=AD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96json=E8=AF=AD=E8=A8=80=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Localization/Json/JsonStringLocalizer.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs index 2aa63f483d5..b5e37945a4e 100644 --- a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs +++ b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; + using System.Collections.Concurrent; using System.Globalization; using System.Reflection; @@ -119,7 +120,28 @@ public override LocalizedString this[string name] } else { - HandleMissingResourceItem(name); + // 如果没有找到资源信息则尝试从父类中查找 + var type = Assembly.GetType(typeName); + var propertyInfo = type?.GetPropertyByName(name); + if (propertyInfo != null) + { + var baseType = propertyInfo.DeclaringType!; + // 如果是父类属性则尝试从父类中查找 + if (baseType != type) + { + var baseAssembly = baseType.Assembly!; + var localizerStrings2 = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(baseAssembly, baseType.FullName!)); + + var l2 = localizerStrings2.Find(i => i.Name == name); + if (l2 is { ResourceNotFound: false }) + { + ret = l2.Value; + } + } + + } + if (ret is null) + HandleMissingResourceItem(name); } } return ret; From 376720bcb589a6764493b315d2e784ff2702d124 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 15:54:01 +0800 Subject: [PATCH 2/8] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/FullScreenServiceTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTest/Services/FullScreenServiceTest.cs b/test/UnitTest/Services/FullScreenServiceTest.cs index 121d04e1678..1d412d1c846 100644 --- a/test/UnitTest/Services/FullScreenServiceTest.cs +++ b/test/UnitTest/Services/FullScreenServiceTest.cs @@ -91,7 +91,7 @@ public void FullScreenOption_Ok() var option = new FullScreenOption() { Element = new("test01", null), Id = "test", Selector = "test-selector" }; Assert.NotNull(option.Id); Assert.Null(option.Element.Context); - Assert.Null(option.Selector); + Assert.NotNull(option.Selector); } private class MockFullScreen : ComponentBase From 6d6ef0b3943fbf6041b5992d1facf385211f82e1 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 16:11:37 +0800 Subject: [PATCH 3/8] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Localization/Json/JsonStringLocalizer.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs index b5e37945a4e..90b642d3ded 100644 --- a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs +++ b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; - using System.Collections.Concurrent; using System.Globalization; using System.Reflection; @@ -121,27 +120,35 @@ public override LocalizedString this[string name] else { // 如果没有找到资源信息则尝试从父类中查找 - var type = Assembly.GetType(typeName); - var propertyInfo = type?.GetPropertyByName(name); - if (propertyInfo != null) - { - var baseType = propertyInfo.DeclaringType!; - // 如果是父类属性则尝试从父类中查找 - if (baseType != type) - { - var baseAssembly = baseType.Assembly!; - var localizerStrings2 = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(baseAssembly, baseType.FullName!)); - - var l2 = localizerStrings2.Find(i => i.Name == name); - if (l2 is { ResourceNotFound: false }) - { - ret = l2.Value; - } - } + ret ??= GetStringFromBaseType(name); - } if (ret is null) + { + // 加入缺失资源信息缓存中 HandleMissingResourceItem(name); + } + } + } + return ret; + } + + private string? GetStringFromBaseType(string name) + { + string? ret = null; + var type = Assembly.GetType(typeName); + var propertyInfo = type?.GetPropertyByName(name); + if (propertyInfo is { DeclaringType: not null }) + { + var baseType = propertyInfo.DeclaringType; + if (baseType != type) + { + var baseAssembly = baseType.Assembly; + var localizerStrings = MegerResolveLocalizers(CacheManager.GetAllStringsByTypeName(baseAssembly, baseType.FullName!)); + var l = localizerStrings.Find(i => i.Name == name); + if (l is { ResourceNotFound: false }) + { + ret = l.Value; + } } } return ret; From 9193dedbd640cea125fa8d2293700bcd3eba6f2a Mon Sep 17 00:00:00 2001 From: Diego <2248356998@qq.com> Date: Fri, 9 May 2025 16:20:38 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Data/Foo.cs | 8 ++++++++ .../Localization/JsonStringLocalizerTest.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/BootstrapBlazor.Server/Data/Foo.cs b/src/BootstrapBlazor.Server/Data/Foo.cs index 92ecc5f1c06..8b1d50b93e7 100644 --- a/src/BootstrapBlazor.Server/Data/Foo.cs +++ b/src/BootstrapBlazor.Server/Data/Foo.cs @@ -183,6 +183,14 @@ public static List GetCompleteItems(IStringLocalizer localize #endregion } +/// +/// Demo示例数据 +/// Demo sample data +/// +public class Foo2:Foo +{ + +} /// /// /// diff --git a/test/UnitTest/Localization/JsonStringLocalizerTest.cs b/test/UnitTest/Localization/JsonStringLocalizerTest.cs index a485d761748..61faf8f2f4a 100644 --- a/test/UnitTest/Localization/JsonStringLocalizerTest.cs +++ b/test/UnitTest/Localization/JsonStringLocalizerTest.cs @@ -158,6 +158,7 @@ public void GetAllStrings_FromType() Assert.NotEmpty(items); } + [Fact] public void GetAllStrings_FromBase() { @@ -236,7 +237,21 @@ public void GetAllStrings_FromJson() var resolve = provider.GetRequiredService(); Assert.Empty(resolve.GetAllStringsByCulture(true)); } + [Fact] + public void GetString_FromBaseTypeJson() + { + var sc = new ServiceCollection(); + sc.AddConfiguration(); + sc.AddBootstrapBlazor(); + var provider = sc.BuildServiceProvider(); + var localizer = provider.GetRequiredService>(); + + Assert.Equal("姓名", localizer["Name"].Value); + + var resolve = provider.GetRequiredService(); + Assert.Empty(resolve.GetAllStringsByCulture(true)); + } [Fact] public void GetAllStrings_FromResolver() { From 7a5a8bb7bfcb9520eb0af107466088fa85702580 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 19:01:16 +0800 Subject: [PATCH 5/8] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Data/Foo.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/BootstrapBlazor.Server/Data/Foo.cs b/src/BootstrapBlazor.Server/Data/Foo.cs index 8b1d50b93e7..92ecc5f1c06 100644 --- a/src/BootstrapBlazor.Server/Data/Foo.cs +++ b/src/BootstrapBlazor.Server/Data/Foo.cs @@ -183,14 +183,6 @@ public static List GetCompleteItems(IStringLocalizer localize #endregion } -/// -/// Demo示例数据 -/// Demo sample data -/// -public class Foo2:Foo -{ - -} /// /// /// From c611978e4285b8f1680f82bb7b227e2424903608 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 19:02:01 +0800 Subject: [PATCH 6/8] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnitTest/Localization/JsonStringLocalizerTest.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/UnitTest/Localization/JsonStringLocalizerTest.cs b/test/UnitTest/Localization/JsonStringLocalizerTest.cs index 61faf8f2f4a..5affbb80faf 100644 --- a/test/UnitTest/Localization/JsonStringLocalizerTest.cs +++ b/test/UnitTest/Localization/JsonStringLocalizerTest.cs @@ -158,7 +158,6 @@ public void GetAllStrings_FromType() Assert.NotEmpty(items); } - [Fact] public void GetAllStrings_FromBase() { @@ -237,6 +236,7 @@ public void GetAllStrings_FromJson() var resolve = provider.GetRequiredService(); Assert.Empty(resolve.GetAllStringsByCulture(true)); } + [Fact] public void GetString_FromBaseTypeJson() { @@ -245,13 +245,15 @@ public void GetString_FromBaseTypeJson() sc.AddBootstrapBlazor(); var provider = sc.BuildServiceProvider(); - var localizer = provider.GetRequiredService>(); - + var localizer = provider.GetRequiredService>(); Assert.Equal("姓名", localizer["Name"].Value); + } + + class SubFoo : Foo + { - var resolve = provider.GetRequiredService(); - Assert.Empty(resolve.GetAllStringsByCulture(true)); } + [Fact] public void GetAllStrings_FromResolver() { From eb5f895e80b71496100f7533e01516fd60726e8f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 19:07:47 +0800 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DisplayTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/UnitTest/Components/DisplayTest.cs b/test/UnitTest/Components/DisplayTest.cs index 5f3ecd2b8f2..9cac91323d1 100644 --- a/test/UnitTest/Components/DisplayTest.cs +++ b/test/UnitTest/Components/DisplayTest.cs @@ -56,7 +56,7 @@ public async Task LookupService_Ok() { pb.Add(a => a.LookupService, new MockLookupService()); }); - await Task.Delay(20); + await Task.Delay(50); Assert.Contains("Test1,Test2", cut.Markup); cut.SetParametersAndRender(pb => @@ -64,7 +64,7 @@ public async Task LookupService_Ok() pb.Add(a => a.LookupServiceKey, null); pb.Add(a => a.Lookup, new List { new("v1", "Test3"), new("v2", "Test4") }); }); - await Task.Delay(20); + await Task.Delay(50); Assert.Contains("Test3,Test4", cut.Markup); } From b326ba2fe85c43796d67929d6f5dcc6dc60bf3c6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 9 May 2025 19:12:12 +0800 Subject: [PATCH 8/8] chore: bump version 9.6.2-beta02 Co-Authored-By: Diego2098 <82756760+kimdiego2098@users.noreply.github.com> --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index ee2fdce1f9c..fe343632130 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.6.2-beta01 + 9.6.2-beta02