44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
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;
|
|
|
|
namespace IRaCIS.Core.API
|
|
{
|
|
public static class LocalizationConfig
|
|
{
|
|
|
|
public static void UseLocalization(this IApplicationBuilder app,IServiceProvider serviceProvider)
|
|
{
|
|
var supportedCultures = new List<CultureInfo>
|
|
{
|
|
|
|
new CultureInfo(StaticData.CultureInfo.en_US),
|
|
new CultureInfo(StaticData.CultureInfo.zh_CN)
|
|
};
|
|
|
|
var options = new RequestLocalizationOptions
|
|
{
|
|
//DefaultRequestCulture = new RequestCulture("en-US"),
|
|
SupportedCultures = supportedCultures,
|
|
SupportedUICultures = supportedCultures,
|
|
|
|
ApplyCurrentCultureToResponseHeaders = true
|
|
};
|
|
|
|
//options.RequestCultureProviders.RemoveAt(0);
|
|
//options.RequestCultureProviders.RemoveAt(1);
|
|
|
|
app.UseRequestLocalization(options);
|
|
|
|
//设置国际化I18n
|
|
var localizer = serviceProvider.GetRequiredService<IStringLocalizer>();
|
|
I18n.SetLocalizer(localizer);
|
|
}
|
|
}
|
|
}
|