资源文件
注入服务
private void AddOwnerProvider(IServiceCollection services)
{
//// mapper bridge实现类
//services.AddSingleton<MapperBridgeAbstract, RG3.BO.BI.Bridge.Providers.MapperBridgeAbstractProvider>();
#region 国际化
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddSingleton<IResourceProvider, ResourceProvider>();
#endregion
}
private void AddOwnerConfigure(IApplicationBuilder app, IWebHostEnvironment env)
{
#region 国际化
var supportLang = new[] { "zh-CN", "en-US" };
var lp = new RequestLocalizationOptions()
.SetDefaultCulture(supportLang[0])
.AddSupportedCultures(supportLang)
.AddSupportedUICultures(supportLang);
app.UseRequestLocalization(lp);
#endregion
}
使用
// 本地化 详见 https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/localization?view=aspnetcore-6.0
private readonly IResourceProvider _resourceProvider;
#endregion 本地化
/// <summary>
/// 注入服务
/// </summary>
/// <param name="logger"></param>
/// <param name="config"></param>
public DefaultController(IResourceProvider resourceProvider)
{
_resourceProvider = resourceProvider;
}
数据获取
_resourceProvider.GetMessage("startup")
访问
http://localhost:5901/bs/api/default?culture=en-US
http://localhost:5901/bs/api/default?culture=zh-CN
文档更新时间: 2023-05-22 11:19 作者:admin