-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add localizer extension methods for player language
- Loading branch information
1 parent
fce68cb
commit dddf24d
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
managed/CounterStrikeSharp.API/Core/Translations/LocalizerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
} | ||
} |