11using System . Text . Json ;
2+ using System . Text . RegularExpressions ;
23using CounterStrikeSharp . API ;
34using CounterStrikeSharp . API . Core ;
45using CounterStrikeSharp . API . Modules . Cvars ;
56using CounterStrikeSharp . API . Modules . Entities ;
67using CounterStrikeSharp . API . Modules . Utils ;
78using CustomCommands . Interfaces ;
9+ using CounterStrikeSharp . API . Core . Translations ;
810using Microsoft . Extensions . Logging ;
11+ using CounterStrikeSharp . API . Core . Plugin ;
912
1013namespace CustomCommands . Services ;
1114public class ReplaceTagsFunctions : IReplaceTagsFunctions
1215{
1316 private readonly IPluginGlobals PluginGlobals ;
17+ private readonly PluginContext PluginContext ;
1418 private readonly ILogger < CustomCommands > Logger ;
1519
16- public ReplaceTagsFunctions ( IPluginGlobals PluginGlobals , ILogger < CustomCommands > Logger )
20+ public ReplaceTagsFunctions ( IPluginGlobals PluginGlobals , IPluginContext PluginContext , ILogger < CustomCommands > Logger )
1721 {
1822 this . PluginGlobals = PluginGlobals ;
23+ this . PluginContext = ( PluginContext as PluginContext ) ! ;
1924 this . Logger = Logger ;
2025 }
2126
@@ -25,13 +30,38 @@ public string[] ReplaceTags(string[] input, CCSPlayerController player)
2530
2631 for ( int i = 0 ; i < input . Length ; i ++ )
2732 {
28- output [ i ] = ReplaceMessageTags ( input [ i ] , player ) ;
33+ output [ i ] = ReplaceLanguageTags ( input [ i ] ) ;
34+ output [ i ] = ReplaceMessageTags ( output [ i ] , player ) ;
2935 output [ i ] = ReplaceColorTags ( output [ i ] ) ;
3036 }
3137
3238 return output ;
3339 }
3440
41+ public string ReplaceLanguageTags ( string input )
42+ {
43+ CustomCommands plugin = ( PluginContext . Plugin as CustomCommands ) ! ;
44+
45+ // Define the regex pattern to find "{LANG=...}"
46+ string pattern = @"\{LANG=(.*?)\}" ;
47+
48+ // Use Regex to find matches
49+ Match match = Regex . Match ( input , pattern ) ;
50+
51+ // Check if a match is found
52+ if ( match . Success )
53+ {
54+ // Return the group captured in the regex, which is the string after "="
55+ string lang = match . Groups [ 1 ] . Value ;
56+
57+ return input . Replace ( match . Value , plugin . Localizer [ lang ] ?? "<LANG in CustomCommands/lang/<language.json> not found>" ) ;
58+ }
59+ else
60+ {
61+ // Return the original string if no match is found
62+ return input ;
63+ }
64+ }
3565 public string ReplaceMessageTags ( string input , CCSPlayerController player )
3666 {
3767 SteamID steamId = new SteamID ( player . SteamID ) ;
0 commit comments