From b34148a9173703e7de18e7708f9180406bd0642c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=8A=E7=A3=8A?= Date: Tue, 15 Nov 2022 10:13:59 +0800 Subject: [PATCH] feat(i18n): Fix ValidatorMiddleware error & Fix I18n errors (#333) * fix: Fix ValidatorMiddleware error * fix: Fix I18n errors --- .../Middleware/ValidatorMiddleware.cs | 2 +- .../ApplicationBuilderExtensions.cs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events.FluentValidation/Middleware/ValidatorMiddleware.cs b/src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events.FluentValidation/Middleware/ValidatorMiddleware.cs index 368ce74cc..4bed6f209 100644 --- a/src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events.FluentValidation/Middleware/ValidatorMiddleware.cs +++ b/src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events.FluentValidation/Middleware/ValidatorMiddleware.cs @@ -36,7 +36,7 @@ public override async Task HandleAsync(TEvent @event, EventHandlerDelegate next) @event, failures); - var validationException = new ValidationException("Validation exception", failures); + var validationException = new ValidationException(failures); throw new MasaValidatorException(validationException.Message); } diff --git a/src/Contrib/Globalization/Masa.Contrib.Globalization.I18n.AspNetCore/Extensions/ApplicationBuilderExtensions.cs b/src/Contrib/Globalization/Masa.Contrib.Globalization.I18n.AspNetCore/Extensions/ApplicationBuilderExtensions.cs index 677420d9b..6eaa1f82d 100644 --- a/src/Contrib/Globalization/Masa.Contrib.Globalization.I18n.AspNetCore/Extensions/ApplicationBuilderExtensions.cs +++ b/src/Contrib/Globalization/Masa.Contrib.Globalization.I18n.AspNetCore/Extensions/ApplicationBuilderExtensions.cs @@ -20,14 +20,17 @@ public static IApplicationBuilder UseI18n(this IApplicationBuilder app, string? var requestLocalization = new RequestLocalizationOptions(); - var cultures = settings.SupportedCultures.Select(x => x.Culture).ToArray(); - requestLocalization - .AddSupportedCultures(cultures) - .AddSupportedUICultures(cultures); - requestLocalization.SetDefaultCulture(!string.IsNullOrWhiteSpace(defaultCulture) ? defaultCulture : cultures.FirstOrDefault()!); - - requestLocalization.ApplyCurrentCultureToResponseHeaders = true; - app.UseRequestLocalization(requestLocalization); + if (settings.SupportedCultures.Any()) + { + var cultures = settings.SupportedCultures.Select(x => x.Culture).ToArray(); + requestLocalization + .AddSupportedCultures(cultures) + .AddSupportedUICultures(cultures); + requestLocalization.SetDefaultCulture(!string.IsNullOrWhiteSpace(defaultCulture) ? defaultCulture : cultures.FirstOrDefault()!); + + requestLocalization.ApplyCurrentCultureToResponseHeaders = true; + app.UseRequestLocalization(requestLocalization); + } return app; } }