mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-22 00:27:09 +01:00
Add Accept-Language header support for per-request localization
This commit is contained in:
@@ -209,6 +209,11 @@ namespace MediaBrowser.Controller.Net
|
||||
var (connection, cts, state) = tuple;
|
||||
var cancellationToken = cts.Token;
|
||||
|
||||
// Restore the culture context captured when the connection was established
|
||||
// so that GetDataToSendForConnection produces a localized payload matching
|
||||
// the client's Accept-Language preference rather than the server default.
|
||||
connection.ApplyRequestCulture();
|
||||
|
||||
var data = await GetDataToSendForConnection(connection).ConfigureAwait(false);
|
||||
if (data is null)
|
||||
{
|
||||
|
||||
@@ -77,5 +77,14 @@ namespace MediaBrowser.Controller.Net
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task ReceiveAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Applies the culture context captured when the connection was established
|
||||
/// (from the upgrade request's <c>Accept-Language</c> header) to the current
|
||||
/// async flow. Server-initiated message senders should call this before
|
||||
/// localising any payload so that the response uses the client's preferred
|
||||
/// language rather than the server default.
|
||||
/// </summary>
|
||||
void ApplyRequestCulture();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user