UI/Notices/Notices.Localization.cs

UI partial class for Notices that sends a localized notice to a single connection. The host calls SendLocalizedNotice which serializes token data, invokes an RPC targeted to the recipient, deserializes tokens on the client, resolves the localized phrase and displays the notice.

NetworkingHttp Calls
namespace Sandbox.UI;

public partial class Notices
{
	/// <summary>
	/// Sends a phrase and its parameters to a connection, resolving them in the recipient's language.
	/// Must be called from the host.
	/// </summary>
	public static void SendLocalizedNotice( Connection target, string icon, Color iconColor, string phrase, Dictionary<string, string> tokens = null, float seconds = 5 )
	{
		Assert.True( Networking.IsHost, "Must be the host" );

		using ( Rpc.FilterInclude( target ) )
		{
			RpcAddLocalizedNotice( icon, iconColor, phrase, Sandbox.Json.Serialize( tokens ), seconds );
		}
	}

	[Rpc.Broadcast( NetFlags.HostOnly )]
	private static void RpcAddLocalizedNotice( string icon, Color iconColor, string phrase, string tokensJson, float seconds )
	{
		var tokens = Sandbox.Json.Deserialize<Dictionary<string, string>>( tokensJson );
		AddNotice( icon, iconColor, LocalizedText.Resolve( phrase, tokens ), seconds );
	}
}