예제 #1
0
        public static KaspServiceBuilder AddLocalization(this KaspServiceBuilder builder, Action <KaspLocalizationOptionBuilder> optionsAction)
        {
            var options = new KaspLocalizationOptionBuilder(builder.Services)
            {
                LocalizationOptions = new KaspLocalizationOptions()
            };

            optionsAction?.Invoke(options);

            builder.Services.AddLocalization(localizationOptions => localizationOptions.ResourcesPath       = options.LocalizationOptions.ResourcesPath);
            builder.MvcBuilder.AddViewLocalization(localizationOptions => localizationOptions.ResourcesPath = options.LocalizationOptions.ResourcesPath);
//			builder.MvcBuilder.AddDataAnnotationsLocalization(options => options.)

            builder.Services.AddMemoryCache();

            if (options.LocalizationOptions.StringLocalizerFactory != null)
            {
                builder.Services.AddSingleton(typeof(IStringLocalizerFactory), options.LocalizationOptions.StringLocalizerFactory);
            }

            if (options.LocalizationOptions.StringLocalizerFactory != null)
            {
                builder.Services.AddSingleton(typeof(IStringLocalizer), options.LocalizationOptions.StringLocalizer);
            }


            builder.Services.Configure <RequestLocalizationOptions>(localizationOptions => {
                localizationOptions.AddSupportedCultures(options.SupportedCultures.ToArray());
                localizationOptions.AddSupportedUICultures(options.SupportedCultures.ToArray());
                localizationOptions.SetDefaultCulture(options.DefaultCulture);
            });

            return(builder);
        }
예제 #2
0
 public static void AddDbLocalization <TDbContext>(this KaspLocalizationOptionBuilder builder) where TDbContext : DbContext, ILocalizationDbContext
 {
     builder.ServiceCollection.AddScoped <ILangRepository, LangRepository <TDbContext> >();
     EntityHelperFactory.Add <ILocalizer, LocalizerEntityHelper>();
 }
예제 #3
0
 public static void UseJson(this KaspLocalizationOptionBuilder builder)
 {
     builder.LocalizationOptions = new JsonLocalizationOptions();
 }