-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
src/Inc.TeamAssistant.WebUI/Services/ValidatorConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
using System.Globalization; | ||
using FluentValidation; | ||
using Inc.TeamAssistant.Primitives.Languages; | ||
using Inc.TeamAssistant.WebUI.Contracts; | ||
using Inc.TeamAssistant.WebUI.Services.ClientCore; | ||
|
||
namespace Inc.TeamAssistant.WebUI.Services; | ||
|
||
public static class ValidatorConfigurationExtensions | ||
{ | ||
public static ValidatorConfiguration Configure( | ||
public static async Task<CultureInfo> SetCulture( | ||
this ValidatorConfiguration validatorConfiguration, | ||
LanguageId languageId) | ||
IServiceProvider serviceProvider) | ||
{ | ||
ArgumentNullException.ThrowIfNull(validatorConfiguration); | ||
ArgumentNullException.ThrowIfNull(languageId); | ||
ArgumentNullException.ThrowIfNull(serviceProvider); | ||
|
||
validatorConfiguration.LanguageManager.Culture = new(languageId.Value); | ||
var renderContext = serviceProvider.GetRequiredService<IRenderContext>(); | ||
var resourcesManager = serviceProvider.GetRequiredService<ResourcesManager>(); | ||
|
||
var languageContext = renderContext.GetLanguageContext(); | ||
var culture = new CultureInfo(languageContext.CurrentLanguage.Value); | ||
|
||
validatorConfiguration.LanguageManager.Culture = culture; | ||
validatorConfiguration.DefaultClassLevelCascadeMode = CascadeMode.Continue; | ||
validatorConfiguration.DefaultRuleLevelCascadeMode = CascadeMode.Stop; | ||
|
||
return validatorConfiguration; | ||
|
||
await resourcesManager.Initialize(); | ||
|
||
return culture; | ||
} | ||
} |