修改国际化配置提前
parent
8a3eb61a34
commit
9e057ff815
|
@ -207,7 +207,7 @@ app.UseExceptionHandler(o => { });
|
|||
app.UseIRacisHostStaticFileStore(env);
|
||||
|
||||
//本地化
|
||||
app.UseLocalization();
|
||||
app.UseLocalization(app.Services);
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
|
@ -249,9 +249,7 @@ app.MapMasaMinimalAPIs();
|
|||
SerilogExtension.AddSerilogSetup(enviromentName, app.Services);
|
||||
|
||||
|
||||
//设置国际化I18n
|
||||
var localizer = app.Services.GetRequiredService<IStringLocalizer>();
|
||||
I18n.SetLocalizer(localizer);
|
||||
|
||||
|
||||
var hangfireJobService = app.Services.GetRequiredService<IIRaCISHangfireJob>();
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
|
@ -8,7 +12,7 @@ namespace IRaCIS.Core.API
|
|||
public static class LocalizationConfig
|
||||
{
|
||||
|
||||
public static void UseLocalization(this IApplicationBuilder app)
|
||||
public static void UseLocalization(this IApplicationBuilder app,IServiceProvider serviceProvider)
|
||||
{
|
||||
var supportedCultures = new List<CultureInfo>
|
||||
{
|
||||
|
@ -30,6 +34,10 @@ namespace IRaCIS.Core.API
|
|||
//options.RequestCultureProviders.RemoveAt(1);
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
|
||||
//设置国际化I18n
|
||||
var localizer = serviceProvider.GetRequiredService<IStringLocalizer>();
|
||||
I18n.SetLocalizer(localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,29 @@ public static class I18n
|
|||
|
||||
public static string T(string key)
|
||||
{
|
||||
return _localizer[key];
|
||||
if(_localizer is null)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _localizer[key];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static string T(string key, params object[] arguments)
|
||||
{
|
||||
return _localizer[key, arguments];
|
||||
if (_localizer is null)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _localizer[key, arguments];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue