diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs
index 30db9c80..f7c8966e 100644
--- a/TShockAPI/Commands.cs
+++ b/TShockAPI/Commands.cs
@@ -649,7 +649,7 @@ namespace TShockAPI
string cmdName;
if (index == 0) // Space after the command specifier should not be supported
{
- player.SendErrorMessage(I18n.C.GetString("Invalid command entered. Type {0}help for a list of valid commands.", Specifier));
+ player.SendErrorMessage(GetString("Invalid command entered. Type {0}help for a list of valid commands.", Specifier));
return true;
}
else if (index < 0)
@@ -677,28 +677,28 @@ namespace TShockAPI
call(new CommandArgs(cmdText, player, args));
return true;
}
- player.SendErrorMessage(I18n.C.GetString("Invalid command entered. Type {0}help for a list of valid commands.", Specifier));
+ player.SendErrorMessage(GetString($"Invalid command entered. Type {0}help for a list of valid commands.", Specifier));
return true;
}
foreach (Command cmd in cmds)
{
if (!cmd.CanRun(player))
{
- TShock.Utils.SendLogs(I18n.C.GetString("{0} tried to execute {1}{2}.", player.Name, Specifier, cmdText), Color.PaleVioletRed, player);
- player.SendErrorMessage(I18n.C.GetString("You do not have access to this command."));
+ TShock.Utils.SendLogs(GetString("{0} tried to execute {1}{2}.", player.Name, Specifier, cmdText), Color.PaleVioletRed, player);
+ player.SendErrorMessage(GetString("You do not have access to this command."));
if (player.HasPermission(Permissions.su))
{
- player.SendInfoMessage(I18n.C.GetString("You can use '{0}sudo {0}{1}' to override this check.", Specifier, cmdText));
+ player.SendInfoMessage(GetString("You can use '{0}sudo {0}{1}' to override this check.", Specifier, cmdText));
}
}
else if (!cmd.AllowServer && !player.RealPlayer)
{
- player.SendErrorMessage(I18n.C.GetString("You must use this command in-game."));
+ player.SendErrorMessage(GetString("You must use this command in-game."));
}
else
{
if (cmd.DoLog)
- TShock.Utils.SendLogs(I18n.C.GetString("{0} executed: {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdText), Color.PaleVioletRed, player);
+ TShock.Utils.SendLogs(GetString("{0} executed: {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdText), Color.PaleVioletRed, player);
cmd.Run(cmdText, silent, player, args);
}
}
@@ -769,7 +769,7 @@ namespace TShockAPI
{
TShock.Log.Warn(String.Format("{0} ({1}) had {2} or more invalid login attempts and was kicked automatically.",
args.Player.IP, args.Player.Name, TShock.Config.Settings.MaximumLoginAttempts));
- args.Player.Kick(I18n.C.GetString("Too many invalid login attempts."));
+ args.Player.Kick(GetString("Too many invalid login attempts."));
return;
}
@@ -798,7 +798,7 @@ namespace TShockAPI
{
if (String.IsNullOrEmpty(args.Parameters[0]))
{
- args.Player.SendErrorMessage(I18n.C.GetString("Bad login attempt."));
+ args.Player.SendErrorMessage(GetString("Bad login attempt."));
return;
}
diff --git a/TShockAPI/I18n.cs b/TShockAPI/I18n.cs
index 1ec38c42..59f812f4 100644
--- a/TShockAPI/I18n.cs
+++ b/TShockAPI/I18n.cs
@@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+global using static TShockAPI.I18n;
+
using System;
using System.Globalization;
using System.IO;
@@ -42,5 +44,161 @@ namespace TShockAPI
}
/// Instance of a GetText.Catalog loaded with TShockAPI translations for user's specified language
public static Catalog C = new Catalog("TShockAPI", TranslationsDirectory, TranslationCultureInfo);
+
+ #region ICatalog forwarding methods
+ ///
+ /// Returns translated into the selected language.
+ /// Similar to gettext function.
+ ///
+ /// Text to translate.
+ /// Translated text.
+ static string GetString(FormattableStringAdapter text)
+ {
+ return C.GetString(text);
+ }
+
+ ///
+ /// Returns translated into the selected language.
+ /// Similar to gettext function.
+ ///
+ /// Text to translate.
+ /// Translated text.
+ public static string GetString(FormattableString text)
+ {
+ return C.GetString(text);
+ }
+
+ ///
+ /// Returns translated into the selected language.
+ /// Similar to gettext function.
+ ///
+ /// Text to translate.
+ /// Optional arguments for method.
+ /// Translated text.
+ public static string GetString(FormattableStringAdapter text, params object[] args)
+ {
+ return C.GetString(text, args);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of .
+ /// Similar to gettext function.
+ ///
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Translated text.
+ public static string GetPluralString(FormattableStringAdapter text, FormattableStringAdapter pluralText, long n)
+ {
+ return C.GetString(text, pluralText, n);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of .
+ /// Similar to gettext function.
+ ///
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Translated text.
+ public static string GetPluralString(FormattableString text, FormattableString pluralText, long n)
+ {
+ return C.GetString(text, pluralText, n);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of .
+ /// Similar to gettext function.
+ ///
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Optional arguments for method.
+ /// Translated text.
+ public static string GetPluralString(FormattableStringAdapter text, FormattableStringAdapter pluralText, long n, params object[] args)
+ {
+ return C.GetString(text, pluralText, n, args);
+ }
+
+ ///
+ /// Returns translated into the selected language using given .
+ /// Similar to pgettext function.
+ ///
+ /// Context.
+ /// Text to translate.
+ /// Translated text.
+ public static string GetParticularString(string context, FormattableStringAdapter text)
+ {
+ return C.GetParticularString(context, text);
+ }
+
+ ///
+ /// Returns translated into the selected language using given .
+ /// Similar to pgettext function.
+ ///
+ /// Context.
+ /// Text to translate.
+ /// Translated text.
+ public static string GetParticularString(string context, FormattableString text)
+ {
+ return C.GetParticularString(context, text);
+ }
+
+ ///
+ /// Returns translated into the selected language using given .
+ /// Similar to pgettext function.
+ ///
+ /// Context.
+ /// Text to translate.
+ /// Optional arguments for method.
+ /// Translated text.
+ public static string GetParticularString(string context, FormattableStringAdapter text, params object[] args)
+ {
+ return C.GetParticularString(context, text, args);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of using given .
+ /// Similar to npgettext function.
+ ///
+ /// Context.
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Translated text.
+ public static string GetParticularPluralString(string context, FormattableStringAdapter text, FormattableStringAdapter pluralText, long n)
+ {
+ return C.GetParticularString(context, text, pluralText, n);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of using given .
+ /// Similar to npgettext function.
+ ///
+ /// Context.
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Translated text.
+ public static string GetParticularPluralString(string context, FormattableString text, FormattableString pluralText, long n)
+ {
+ return C.GetParticularString(context, text, pluralText, n);
+ }
+
+ ///
+ /// Returns the plural form for of the translation of using given .
+ /// Similar to npgettext function.
+ ///
+ /// Context.
+ /// Singular form of message to translate.
+ /// Plural form of message to translate.
+ /// Value that determines the plural form.
+ /// Optional arguments for method.
+ /// Translated text.
+ public static string GetParticularPluralString(string context, FormattableStringAdapter text, FormattableStringAdapter pluralText, long n, params object[] args)
+ {
+ return C.GetParticularString(context, text, pluralText, n, args);
+ }
+ #endregion
}
}
diff --git a/docs/i18n.md b/docs/i18n.md
index bc72eee1..aed47f72 100644
--- a/docs/i18n.md
+++ b/docs/i18n.md
@@ -2,7 +2,7 @@ TShock supports the concept of multiple languages using `GetText.NET`.
CI is automatically designed to build and push updated `.po` files (the source for lang files) based on usage in TShock.
-To use a localized string instead of a standard string, use `I18n.C.GetString()`. For example, `I18n.C.GetString("Invalid command!")` instead of `"Invalid command!"`.
+To use a localized string instead of a standard string, use `GetString()`. For example, `GetString("Invalid command!")` instead of `"Invalid command!"`.
A test language file has been added that converts a limited number of phrases to [Toki Pona](https://tokipona.org/), the language of good. To use this, you can set an environment variable called `TSHOCK_LANGUAGE` set to `tok`. For example, `TSHOCK_LANGUAGE=tok dotnet run --project TShockLauncher`. Then, run the `die` command.