Skip to content

Commit

Permalink
Use RequestLocalizationOptions.CultureInfoUseUserOverride (OrchardCMS…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored and urbanit committed Mar 18, 2024
1 parent 1d9b428 commit 225036d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 87 deletions.
16 changes: 8 additions & 8 deletions src/OrchardCore.Modules/OrchardCore.Localization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public override async ValueTask ConfigureAsync(IApplicationBuilder app, IEndpoin
var defaultCulture = await localizationService.GetDefaultCultureAsync();
var supportedCultures = await localizationService.GetSupportedCulturesAsync();

var localizationOptions = serviceProvider.GetService<IOptions<RequestLocalizationOptions>>().Value;
var ignoreSystemSettings = serviceProvider.GetService<IOptions<CultureOptions>>().Value.IgnoreSystemSettings;
var cultureOptions = serviceProvider.GetService<IOptions<CultureOptions>>().Value;

new LocalizationOptionsUpdater(localizationOptions, ignoreSystemSettings)
.SetDefaultCulture(defaultCulture)
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);

app.UseRequestLocalization(localizationOptions);
app.UseRequestLocalization(options =>
{
options.CultureInfoUseUserOverride = !cultureOptions.IgnoreSystemSettings;
options.SetDefaultCulture(defaultCulture);
options.AddSupportedCultures(supportedCultures);
options.AddSupportedUICultures(supportedCultures);
});
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Setup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ public override void ConfigureServices(IServiceCollection services)
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
var localizationOptions = serviceProvider.GetService<IOptions<RequestLocalizationOptions>>().Value;
var ignoreSystemSettings = serviceProvider.GetService<IOptions<CultureOptions>>().Value.IgnoreSystemSettings;
var cultureOptions = serviceProvider.GetService<IOptions<CultureOptions>>().Value;

localizationOptions.CultureInfoUseUserOverride = !cultureOptions.IgnoreSystemSettings;

var localizationOptionsUpdater = new LocalizationOptionsUpdater(localizationOptions, ignoreSystemSettings);
if (!string.IsNullOrEmpty(_defaultCulture))
{
localizationOptionsUpdater.SetDefaultCulture(_defaultCulture);
localizationOptions.SetDefaultCulture(_defaultCulture);

_supportedCultures = _supportedCultures.Union(new[] { _defaultCulture }).ToArray();
}

if (_supportedCultures?.Length > 0)
{
localizationOptionsUpdater
localizationOptions
.AddSupportedCultures(_supportedCultures)
.AddSupportedUICultures(_supportedCultures);
}
Expand Down

This file was deleted.

0 comments on commit 225036d

Please sign in to comment.