From 76f8b64cc83fa8a58d21a2e55dd0bdf8bfcf9adf Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 16 Jun 2022 15:37:37 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E6=96=87?= =?UTF-8?q?=E5=8C=96=E6=89=BE=E4=B8=8D=E5=88=B0=E6=97=A5=E5=BF=97=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E4=B8=BA=20Info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs index 42d8801ea..8a7d59c70 100644 --- a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs +++ b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs @@ -201,7 +201,7 @@ internal class JsonStringLocalizer : ResourceManagerStringLocalizer var cultureName = GetCultureName(culture); var resources = GetJsonStringByCulture(cultureName); var resource = resources.FirstOrDefault(s => s.Key == name); - Logger.LogDebug($"{nameof(JsonStringLocalizer)} searched for '{name}' in '{_searchedLocation}' with culture '{culture}'."); + Logger.LogInformation($"{nameof(JsonStringLocalizer)} searched for '{name}' in '{_searchedLocation}' with culture '{culture}'."); return resource.Value; } -- Gitee From 220172622f641d5f621233bbc0a81050051e19b1 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 16 Jun 2022 15:56:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20ILocalizationR?= =?UTF-8?q?esolve=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Localization/ILocalizationResolve.cs | 21 +++++++++++++++++++ .../Localization/NullLocalizationResolve.cs | 12 +++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/BootstrapBlazor/Localization/ILocalizationResolve.cs create mode 100644 src/BootstrapBlazor/Localization/NullLocalizationResolve.cs diff --git a/src/BootstrapBlazor/Localization/ILocalizationResolve.cs b/src/BootstrapBlazor/Localization/ILocalizationResolve.cs new file mode 100644 index 000000000..1fad23bef --- /dev/null +++ b/src/BootstrapBlazor/Localization/ILocalizationResolve.cs @@ -0,0 +1,21 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using System.Globalization; + +namespace BootstrapBlazor.Localization; + +/// +/// ILocalizationResolve 服务 +/// +public interface ILocalizationResolve +{ + /// + /// 通过文化信息与语言键值获取值方法 + /// + /// + /// + /// + string? GetJsonStringByCulture(CultureInfo culture, string name); +} diff --git a/src/BootstrapBlazor/Localization/NullLocalizationResolve.cs b/src/BootstrapBlazor/Localization/NullLocalizationResolve.cs new file mode 100644 index 000000000..40507a70f --- /dev/null +++ b/src/BootstrapBlazor/Localization/NullLocalizationResolve.cs @@ -0,0 +1,12 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using System.Globalization; + +namespace BootstrapBlazor.Localization; + +internal class NullLocalizationResolve : ILocalizationResolve +{ + public string? GetJsonStringByCulture(CultureInfo culture, string name) => null; +} -- Gitee From ca6f586cec21faee8d50c54f4cf951e77ab2d034 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 16 Jun 2022 15:57:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=89=BE=E4=B8=8D=E5=88=B0=E6=97=B6=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=20ILocalizationResolve=20=E6=9C=8D=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JsonLocalizationServiceCollectionExtensions.cs | 4 +++- .../Localization/Json/JsonStringLocalizer.cs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Localization/Json/JsonLocalizationServiceCollectionExtensions.cs b/src/BootstrapBlazor/Localization/Json/JsonLocalizationServiceCollectionExtensions.cs index 675362663..cfdb8f2b2 100644 --- a/src/BootstrapBlazor/Localization/Json/JsonLocalizationServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Localization/Json/JsonLocalizationServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ +using BootstrapBlazor.Localization; using BootstrapBlazor.Localization.Json; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Localization; @@ -24,7 +25,8 @@ internal static class JsonLocalizationServiceCollectionExtensions // 防止被 AddLocalization 覆盖掉 services.AddSingleton(); services.TryAddTransient(typeof(IStringLocalizer<>), typeof(StringLocalizer<>)); - services.TryAddTransient(typeof(IStringLocalizer), typeof(StringLocalizer)); + services.TryAddTransient(); + services.TryAddSingleton(); if (localizationConfigure != null) { services.Configure(localizationConfigure); diff --git a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs index 8a7d59c70..e56c897a9 100644 --- a/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs +++ b/src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs @@ -27,6 +27,7 @@ internal class JsonStringLocalizer : ResourceManagerStringLocalizer private IServiceProvider ServiceProvider { get; set; } + private ILocalizationResolve LocalizerResolver { get; set; } private readonly string _searchedLocation = ""; @@ -54,6 +55,7 @@ internal class JsonStringLocalizer : ResourceManagerStringLocalizer Logger = logger; Options = options; ServiceProvider = provider; + LocalizerResolver = provider.GetRequiredService(); } /// @@ -201,8 +203,14 @@ internal class JsonStringLocalizer : ResourceManagerStringLocalizer var cultureName = GetCultureName(culture); var resources = GetJsonStringByCulture(cultureName); var resource = resources.FirstOrDefault(s => s.Key == name); - Logger.LogInformation($"{nameof(JsonStringLocalizer)} searched for '{name}' in '{_searchedLocation}' with culture '{culture}'."); - return resource.Value; + + // localization resolve + var value = resource.Value ?? LocalizerResolver.GetJsonStringByCulture(culture, name); + if (value == null) + { + Logger.LogInformation($"{nameof(JsonStringLocalizer)} searched for '{name}' in '{_searchedLocation}' with culture '{culture}' not found."); + } + return value; } private IEnumerable GetAllStringsFromCultureHierarchy(CultureInfo culture) -- Gitee From 6cef88903d00a74bffb54969a026e1f49169bf6e Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 16 Jun 2022 16:04:37 +0800 Subject: [PATCH 4/4] chore: bump version 6.7.15 --- 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 f0c9a1ef9..5dff545e1 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -3,7 +3,7 @@ - 6.7.14 + 6.7.15 -- Gitee