Skip to content

Commit

Permalink
feature: allow to configure default culture of server
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Feb 3, 2024
1 parent 9e3bae8 commit 9620400
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/GZCTF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources")
.Configure<RequestLocalizationOptions>(options =>
{
options.ApplyCurrentCultureToResponseHeaders = true;
options.SupportedUICultures = options.SupportedCultures = [new CultureInfo("zh-CN"), new CultureInfo("en-US"), new CultureInfo("ja-JP")];
var defaultCulture = Environment.GetEnvironmentVariable("GZCTF_DEFAULT_CULTURE");
if (!string.IsNullOrWhiteSpace(defaultCulture))
{
var culture = new CultureInfo(defaultCulture);
options.DefaultRequestCulture = new(culture, culture);
}
});

#pragma warning disable ASP0000 // Do not call 'IServiceCollection.BuildServiceProvider' in 'ConfigureServices'
GZCTF.Program.StaticLocalizer =
Expand Down Expand Up @@ -267,12 +278,7 @@

WebApplication app = builder.Build();

app.UseRequestLocalization(options =>
{
options.ApplyCurrentCultureToResponseHeaders = true;
options.SupportedCultures = [new CultureInfo("zh-CN"), new CultureInfo("en-US"), new CultureInfo("ja-JP")];
options.SupportedUICultures = options.SupportedUICultures;
});
app.UseRequestLocalization();

Log.Logger = LogHelper.GetLogger(app.Configuration, app.Services);

Expand Down

0 comments on commit 9620400

Please sign in to comment.