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 -.-)
This commit is contained in:
Sebastian Göls
2021-10-25 20:24:56 +02:00
committed by GitHub
parent ed0cb38147
commit d894f3a830
3 changed files with 22 additions and 2 deletions

View File

@@ -35,6 +35,7 @@
<PackageReference Include="Microsoft.AspNetCore.Cors" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" />
<PackageReference Include="Microsoft.AspNetCore.Localization" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" />

View File

@@ -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<RequestLocalizationOptions>(
#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<IRequestCultureProvider> { new AcceptLanguageHeaderRequestCultureProvider() };
}
);
// Add support for proxies
services.Configure<ForwardedHeadersOptions>(
options => {

View File

@@ -32,6 +32,7 @@
<PackageVersion Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Localization" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.AspNetCore.ResponseCaching" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />