-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from DentallApp/feat/select-language-culture
feat: Implement a strategy to select the language/culture for each request in a localized ASP.NET Core app
- Loading branch information
Showing
10 changed files
with
80 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace DentallApp.HostApplication.Extensions; | ||
|
||
public static class LanguageExtensions | ||
{ | ||
public static IServiceCollection ConfigureLanguages( | ||
this IServiceCollection services, | ||
IConfiguration configuration) | ||
{ | ||
services.Configure<RequestLocalizationOptions>(options => | ||
{ | ||
List<CultureInfo> supportedCultures = []; | ||
var languages = configuration.GetLanguages(); | ||
foreach (var language in languages) | ||
supportedCultures.Add(new CultureInfo(language)); | ||
|
||
var defaultLanguage = configuration.GetDefaultLanguage(); | ||
options.DefaultRequestCulture = new RequestCulture(defaultLanguage); | ||
options.SupportedCultures = supportedCultures; | ||
options.SupportedUICultures = supportedCultures; | ||
}); | ||
return services; | ||
} | ||
|
||
public static string[] GetLanguages(this IConfiguration configuration) | ||
=> configuration | ||
.GetRequiredSection("Languages") | ||
.Get<string[]>() ?? []; | ||
|
||
public static string GetDefaultLanguage(this IConfiguration configuration) | ||
=> configuration.GetValue<string>("DefaultLanguage") ?? "es"; | ||
} |
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 was deleted.
Oops, something went wrong.
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,6 +1,11 @@ | ||
{ | ||
"MicrosoftAppType": "", | ||
"MicrosoftAppId": "", | ||
"MicrosoftAppPassword": "", | ||
"MicrosoftAppTenantId": "" | ||
"MicrosoftAppType": "", | ||
"MicrosoftAppId": "", | ||
"MicrosoftAppPassword": "", | ||
"MicrosoftAppTenantId": "", | ||
"DefaultLanguage": "es", | ||
"Languages": [ | ||
"es", | ||
"en" | ||
] | ||
} |
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