From d894f3a8306a52744f7a28e4f17522d5f2a846b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C3=B6ls?= <6608231+Abrynos@users.noreply.github.com> Date: Mon, 25 Oct 2021 20:24:56 +0200 Subject: [PATCH] Localize IPC (#2431) * Localize IPC * Keep logs in one language * Cleanup * Revert changes that keep strings in one locale * Order dependencies alphabetically * Fix formatting (Thanks, Rider -.-) --- ArchiSteamFarm/ArchiSteamFarm.csproj | 1 + ArchiSteamFarm/IPC/Startup.cs | 22 ++++++++++++++++++++-- Directory.Packages.props | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 261602b46..97467801f 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -35,6 +35,7 @@ + diff --git a/ArchiSteamFarm/IPC/Startup.cs b/ArchiSteamFarm/IPC/Startup.cs index d7402cae8..81c75bda4 100644 --- a/ArchiSteamFarm/IPC/Startup.cs +++ b/ArchiSteamFarm/IPC/Startup.cs @@ -40,6 +40,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Headers; using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -54,11 +55,10 @@ namespace ArchiSteamFarm.IPC { public Startup(IConfiguration configuration) => Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); -#if NETFRAMEWORK [UsedImplicitly] +#if NETFRAMEWORK public void Configure(IApplicationBuilder app, IHostingEnvironment env) { #else - [UsedImplicitly] public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { #endif if (app == null) { @@ -140,6 +140,8 @@ namespace ArchiSteamFarm.IPC { } ); + app.UseRequestLocalization(); + // Use routing for our API controllers, this should be called once we're done with all the static files mess #if !NETFRAMEWORK app.UseRouting(); @@ -211,6 +213,22 @@ namespace ArchiSteamFarm.IPC { } } + services.AddLocalization(); + +#if NETFRAMEWORK + services.Configure( +#else + services.AddRequestLocalization( +#endif + static options => { + // We do not set the DefaultRequestCulture here, because it will default to Thread.CurrentThread.CurrentCulture in this case, which is set when loading GlobalConfig + options.SupportedUICultures = options.SupportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures); + + // The default checks the URI and cookies and only then for headers; ASFs IPC does not use either of the higher priority mechanisms anywhere else and we don't want to start here. + options.RequestCultureProviders = new List { new AcceptLanguageHeaderRequestCultureProvider() }; + } + ); + // Add support for proxies services.Configure( options => { diff --git a/Directory.Packages.props b/Directory.Packages.props index 21494fced..21ec04762 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -32,6 +32,7 @@ +