mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Localization;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Yi.Framework.Common.Models;
|
|
using Yi.Framework.Language;
|
|
|
|
namespace Yi.Framework.WebCore.MiddlewareExtend
|
|
{
|
|
public static class LocalizerExtend
|
|
{
|
|
public static IServiceCollection AddLocalizerService(this IServiceCollection services)
|
|
{
|
|
|
|
services.AddLocalization();
|
|
return services;
|
|
}
|
|
|
|
public static void UseLocalizerService(this IApplicationBuilder app)
|
|
{
|
|
Result._local = app.ApplicationServices.GetService<IStringLocalizer<LocalLanguage>>();
|
|
|
|
var support = new[] { "zh", "en" };
|
|
var local = new RequestLocalizationOptions().SetDefaultCulture(support[0])
|
|
.AddSupportedCultures(support)
|
|
.AddSupportedUICultures(support);
|
|
app.UseRequestLocalization(local);
|
|
|
|
}
|
|
}
|
|
}
|