Add Accept-Language header support for per-request localization

This commit is contained in:
Shadowghost
2026-05-04 20:26:39 +02:00
parent e9942c3857
commit 4be3f5f1f9
28 changed files with 571 additions and 149 deletions

View File

@@ -4,9 +4,11 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Threading.Tasks;
using Emby.Server.Implementations.Localization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Net;
using Microsoft.AspNetCore.Http;
@@ -48,13 +50,22 @@ namespace Emby.Server.Implementations.HttpServer
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);
// Capture the culture context set by AcceptLanguageMiddleware so it can be
// restored both when processing incoming messages and when periodic
// listeners produce server-initiated payloads on background tasks.
var connection = new WebSocketConnection(
_loggerFactory.CreateLogger<WebSocketConnection>(),
webSocket,
authorizationInfo,
context.GetNormalizedRemoteIP())
{
OnReceive = ProcessWebSocketMessageReceived
RequestCultureFallback = LocalizationManager.RequestCultureFallback,
RequestUICulture = CultureInfo.CurrentUICulture.Name
};
connection.OnReceive = result =>
{
connection.ApplyRequestCulture();
return ProcessWebSocketMessageReceived(result);
};
await using (connection.ConfigureAwait(false))
{