-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
628e435
commit 3c9f1f3
Showing
6 changed files
with
44 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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"test.translation": "This is the english translation", | ||
"test.format": "This number has 2 decimal places {0:n2}" | ||
"test.format": "This number has 2 decimal places {0:n2}", | ||
"test.colors": "{orange}This{default} text has {green}green{default} text", | ||
"test.colors.withformat": "{orange}{0:n2}{default}" | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"test.translation": "This is the english translation", | ||
"test.format": "This number has 2 decimal places {0:n2}" | ||
} | ||
"test.format": "This number has 2 decimal places {0:n2}", | ||
"test.colors": "{orange}This{default} text has {green}green{default} text", | ||
"test.colors.withformat": "{orange}{0:n2}{default}" | ||
} |
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
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
22 changes: 22 additions & 0 deletions
22
managed/CounterStrikeSharp.API/Core/Translations/StringExtensions.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,22 @@ | ||
using System.Reflection; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
|
||
namespace CounterStrikeSharp.API.Core.Translations; | ||
|
||
public static class StringExtensions | ||
{ | ||
public static string ReplaceColorTags(this string message) | ||
{ | ||
var modifiedValue = message; | ||
foreach (var field in typeof(ChatColors).GetFields()) | ||
{ | ||
string pattern = $"{{{field.Name}}}"; | ||
if (modifiedValue.Contains(pattern, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)?.ToString() ?? string.Empty, StringComparison.OrdinalIgnoreCase); | ||
} | ||
} | ||
|
||
return modifiedValue.Equals(message) ? message : $"\x01\x0B\x01{modifiedValue}"; | ||
} | ||
} |