This commit is contained in:
Archi
2021-10-27 13:31:48 +02:00
parent 785b43781a
commit 28d0068fdb
2 changed files with 24 additions and 20 deletions

View File

@@ -23,7 +23,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
@@ -34,7 +33,10 @@ using Microsoft.Net.Http.Headers;
namespace ArchiSteamFarm.IPC.Integration {
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
internal sealed class LocalizationMiddleware {
internal static readonly ImmutableDictionary<string, string> CultureConversions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { "lol-US", SharedInfo.LolcatCultureName }, { "sr-CS", "sr-Latn" } }.ToImmutableDictionary();
private static readonly ImmutableDictionary<string, string> CultureConversions = new Dictionary<string, string>(2, StringComparer.OrdinalIgnoreCase) {
{ "lol-US", SharedInfo.LolcatCultureName },
{ "sr-CS", "sr-Latn" }
}.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase);
private readonly RequestDelegate Next;

View File

@@ -141,7 +141,10 @@ namespace ArchiSteamFarm.IPC {
}
);
// Add support for additional localization mappings
app.UseMiddleware<LocalizationMiddleware>();
// Add support for localization
app.UseRequestLocalization();
// Use routing for our API controllers, this should be called once we're done with all the static files mess
@@ -215,24 +218,6 @@ 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
List<CultureInfo> supportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures).Append(CultureInfo.CreateSpecificCulture(SharedInfo.LolcatCultureName)).ToList();
options.SupportedUICultures = options.SupportedCultures = supportedCultures;
// 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 => {
@@ -254,6 +239,23 @@ namespace ArchiSteamFarm.IPC {
// Add support for response compression
services.AddResponseCompression();
// Add support for localization
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.SupportedCultures = options.SupportedUICultures = CultureInfo.GetCultures(CultureTypes.AllCultures).Append(CultureInfo.CreateSpecificCulture(SharedInfo.LolcatCultureName)).ToList();
// 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>(1) { new AcceptLanguageHeaderRequestCultureProvider() };
}
);
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
if (!string.IsNullOrEmpty(ipcPassword)) {