Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/LocalizerExtend.cs

(完整代码) 1KB

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);

        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。