mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-08 08:56:34 -08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28ce183cdc | ||
|
|
dddf24d0f3 |
@@ -1,4 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Globalization;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
@@ -32,6 +32,17 @@ public class WithTranslationsPlugin : BasePlugin
|
||||
|
||||
// This message has colour codes and formatted values
|
||||
Server.PrintToChatAll(Localizer["test.colors.withformat", 123.551]);
|
||||
|
||||
// This prints the message to all players in their respective language
|
||||
PrintToAllPlayersLocalized("test.format", 123.456);
|
||||
}
|
||||
|
||||
void PrintToAllPlayersLocalized(string key, params object[] args)
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers().Where(x => x.IsValid))
|
||||
{
|
||||
player.PrintToChat(Localizer.ForPlayer(player, key, args));
|
||||
}
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_replylanguage", "Test Translations")]
|
||||
|
||||
Submodule libraries/hl2sdk-cs2 updated: c57d5ab398...0b862d725a
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace CounterStrikeSharp.API.Core.Translations;
|
||||
|
||||
public static class LocalizerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a localized string using the locale of the specified player.
|
||||
/// <remarks>Defaults to the server language if the player is invalid.</remarks>
|
||||
/// </summary>
|
||||
public static string ForPlayer(this IStringLocalizer localizer, CCSPlayerController? player, string key)
|
||||
{
|
||||
using WithTemporaryCulture temporaryCulture = new WithTemporaryCulture(player.GetLanguage());
|
||||
return localizer[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="ForPlayer(Microsoft.Extensions.Localization.IStringLocalizer,CounterStrikeSharp.API.Core.CCSPlayerController?,string)"/>
|
||||
/// </summary>
|
||||
public static string ForPlayer(this IStringLocalizer localizer, CCSPlayerController? player, string key, params object[] args)
|
||||
{
|
||||
using WithTemporaryCulture temporaryCulture = new WithTemporaryCulture(player.GetLanguage());
|
||||
return localizer[key, args];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user