Skip to content

Commit 12208dc

Browse files
committed
refactor: 移动多语言服务
1 parent 8cfaa96 commit 12208dc

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using BootstrapBlazor.Service.Services;
77
using Microsoft.AspNetCore.SignalR;
8+
using Microsoft.Extensions.Options;
89
using System.Text.Encodings.Web;
910
using System.Text.Unicode;
1011

@@ -17,9 +18,27 @@ public static IServiceCollection AddBootstrapBlazorServerService(this IServiceCo
1718
// 增加中文编码支持网页源码显示汉字
1819
services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
1920

21+
// 增加错误日志
2022
services.AddLogging(logBuilder => logBuilder.AddFileLogger());
23+
24+
// 增加跨域服务
2125
services.AddCors();
2226

27+
// 增加多语言支持配置信息
28+
services.AddRequestLocalization<IOptionsMonitor<BootstrapBlazorOptions>>((localizerOption, blazorOption) =>
29+
{
30+
blazorOption.OnChange(Invoke);
31+
Invoke(blazorOption.CurrentValue);
32+
return;
33+
34+
void Invoke(BootstrapBlazorOptions option)
35+
{
36+
var supportedCultures = option.GetSupportedCultures();
37+
localizerOption.SupportedCultures = supportedCultures;
38+
localizerOption.SupportedUICultures = supportedCultures;
39+
}
40+
});
41+
2342
#if DEBUG
2443
#else
2544
services.AddResponseCompression(options =>

src/BootstrapBlazor.Shared/Extensions/ServicesCollectionExtensions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ public static IServiceCollection AddBootstrapBlazorServices(this IServiceCollect
3535
// 增加 Baidu ORC 服务
3636
services.AddBootstrapBlazorBaiduOcr();
3737

38-
// 增加多语言支持配置信息
39-
services.AddRequestLocalization<IOptionsMonitor<BootstrapBlazorOptions>>((localizerOption, blazorOption) =>
40-
{
41-
blazorOption.OnChange(Invoke);
42-
Invoke(blazorOption.CurrentValue);
43-
return;
44-
45-
void Invoke(BootstrapBlazorOptions option)
46-
{
47-
var supportedCultures = option.GetSupportedCultures();
48-
localizerOption.SupportedCultures = supportedCultures;
49-
localizerOption.SupportedUICultures = supportedCultures;
50-
}
51-
});
52-
5338
// 增加 AzureOpenAI 服务
5439
services.AddBootstrapBlazorAzureOpenAIService();
5540

0 commit comments

Comments
 (0)