-
-
Notifications
You must be signed in to change notification settings - Fork 366
feat(JsonLocalizationOptions): add DisableGetLocalizerFromService parameter #5164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d244659
chore: 增加配置项
ArgoZhang fe6413a
feat: 增加 DisableGetLocalizerFromService 配置项
ArgoZhang 4b1671c
feat: 增加本地化获取逻辑
ArgoZhang 5b6d93a
test: 更新单元测试
ArgoZhang 0807907
test: 更新单元测试
ArgoZhang 60afbb4
chore: bump version 9.2.9-beta01
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using Microsoft.Extensions.Localization; | ||
| using System.Globalization; | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
@@ -58,6 +59,16 @@ public class BootstrapBlazorOptions : IOptions<BootstrapBlazorOptions> | |
| /// <remarks>使用 <see cref="JsonLocalizationOptions.IgnoreLocalizerMissing"/> 默认值</remarks> | ||
| public bool? IgnoreLocalizerMissing { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 是否禁用从服务中获取本地化资源 默认 false 未禁用 | ||
| /// </summary> | ||
| public bool? DisableGetLocalizerFromService { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 是否禁用获取 <see cref="ResourceManagerStringLocalizer"/> 类型本地化资源 默认 false 未禁用 | ||
| /// </summary> | ||
| public bool? DisableGetLocalizerFromResourceManager { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 默认文化信息 | ||
| /// </summary> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Localization; | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
@@ -175,6 +176,27 @@ public void GetAllStrings_FromBase() | |
| Assert.Empty(items); | ||
ArgoZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void DisableGetLocalizerFromResourceManager_Ok() | ||
| { | ||
| var sc = new ServiceCollection(); | ||
| var builder = new ConfigurationBuilder(); | ||
| builder.AddJsonFile("appsettings.json"); | ||
| builder.AddInMemoryCollection(new Dictionary<string, string?>() | ||
| { | ||
| ["BootstrapBlazorOptions:DisableGetLocalizerFromService"] = "true", | ||
| ["BootstrapBlazorOptions:DisableGetLocalizerFromResourceManager"] = "true" | ||
| }); | ||
| var config = builder.Build(); | ||
| sc.AddSingleton<IConfiguration>(config); | ||
| sc.AddBootstrapBlazor(); | ||
|
|
||
| var provider = sc.BuildServiceProvider(); | ||
| var localizer = provider.GetRequiredService<IStringLocalizer<Dummy>>(); | ||
| var items = localizer.GetAllStrings(false); | ||
| Assert.Empty(items); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetAllStrings_FromResource() | ||
| { | ||
|
|
@@ -243,6 +265,7 @@ public void HandleMissingItem() | |
| var provider = sc.BuildServiceProvider(); | ||
| var localizer = provider.GetRequiredService<IStringLocalizer<Foo>>(); | ||
| var val = localizer["missing-item"]; | ||
| Assert.True(val.ResourceNotFound); | ||
|
|
||
| var handler = provider.GetRequiredService<ILocalizationMissingItemHandler>(); | ||
| MockLocalizationMissingItemHandler? mockHandler = null; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.