Skip to content
This repository was archived by the owner on Jan 16, 2020. It is now read-only.

Commit df202b3

Browse files
committed
Improve extension methods
1 parent 0dbbf43 commit df202b3

1 file changed

Lines changed: 71 additions & 3 deletions

File tree

Rocket.Core/I18N/LocalizationExtensions.cs

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Drawing;
2+
using System.Collections.Generic;
23
using Rocket.API.I18N;
34
using Rocket.API.User;
45
using Rocket.Core.User;
@@ -8,7 +9,7 @@ namespace Rocket.Core.I18N
89
public static class LocalizationExtensions
910
{
1011
/// <summary>
11-
/// Sends a localized (translatable) message to the command user.
12+
/// Sends a localized (translatable) message to the user.
1213
/// </summary>
1314
/// <param name="User">The message receiver.</param>
1415
/// <param name="translations">The translations source.</param>
@@ -20,6 +21,33 @@ public static void SendLocalizedMessage(this IUser User, ITranslationCollection
2021
User.SendMessage(translations.Get(translationKey, arguments), color);
2122
}
2223

24+
/// <summary>
25+
/// Sends a localized (translatable) message to the user.
26+
/// </summary>
27+
/// <param name="User">The message receiver.</param>
28+
/// <param name="translations">The translations source.</param>
29+
/// <param name="translationKey">The translation key.</param>
30+
/// <param name="arguments">The arguments for the message. See <see cref="string.Format(string, object[])" /></param>
31+
public static void SendLocalizedMessage(this IUser User, ITranslationCollection translations,
32+
string translationKey, params object[] arguments)
33+
{
34+
User.SendMessage(translations.Get(translationKey, arguments));
35+
}
36+
37+
/// <summary>
38+
/// Sends a localized message to the given player
39+
/// </summary>
40+
/// <param name="userManager">The user manager.</param>
41+
/// <param name="translations">The translation source.</param>
42+
/// <param name="user">The message receiver.</param>
43+
/// <param name="translationKey">The translation key.</param>
44+
/// <param name="arguments">The arguments for the message.</param>
45+
public static void SendLocalizedMessage(this IUserManager userManager, ITranslationCollection translations,
46+
IUser user, string translationKey, Color? color = null, params object[] arguments)
47+
{
48+
userManager.SendMessage(user, translations.Get(translationKey, arguments), color);
49+
}
50+
2351
/// <summary>
2452
/// Sends a localized message to the given player
2553
/// </summary>
@@ -29,11 +57,25 @@ public static void SendLocalizedMessage(this IUser User, ITranslationCollection
2957
/// <param name="translationKey">The translation key.</param>
3058
/// <param name="arguments">The arguments for the message.</param>
3159
public static void SendLocalizedMessage(this IUserManager userManager, ITranslationCollection translations,
32-
IUser user, string translationKey, params object[] arguments)
60+
IUser user, string translationKey, params object[] arguments)
3361
{
3462
userManager.SendMessage(user, translations.Get(translationKey, arguments));
3563
}
3664

65+
66+
/// <summary>
67+
/// Broadcasts a localized message to all players
68+
/// </summary>
69+
/// <param name="userManager">The user manager.</param>
70+
/// <param name="translations">The translation soruce</param>
71+
/// <param name="translationKey">The key of the translated message to send</param>
72+
/// <param name="arguments">The arguments for the message</param>
73+
public static void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations,
74+
string translationKey, Color? color = null, params object[] arguments)
75+
{
76+
userManager.Broadcast(null, translations.Get(translationKey, arguments), color);
77+
}
78+
3779
/// <summary>
3880
/// Broadcasts a localized message to all players
3981
/// </summary>
@@ -42,9 +84,35 @@ public static void SendLocalizedMessage(this IUserManager userManager, ITranslat
4284
/// <param name="translationKey">The key of the translated message to send</param>
4385
/// <param name="arguments">The arguments for the message</param>
4486
public static void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations,
45-
string translationKey, params object[] arguments)
87+
string translationKey, params object[] arguments)
4688
{
4789
userManager.Broadcast(null, translations.Get(translationKey, arguments));
4890
}
91+
92+
/// <summary>
93+
/// Broadcasts a localized message to all players
94+
/// </summary>
95+
/// <param name="userManager">The user manager.</param>
96+
/// <param name="translations">The translation soruce</param>
97+
/// <param name="translationKey">The key of the translated message to send</param>
98+
/// <param name="arguments">The arguments for the message</param>
99+
public static void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations,
100+
IEnumerable<IUser> receivers, string translationKey, Color? color = null, params object[] arguments)
101+
{
102+
userManager.Broadcast(null, receivers, translations.Get(translationKey, arguments), color);
103+
}
104+
105+
/// <summary>
106+
/// Broadcasts a localized message to all players
107+
/// </summary>
108+
/// <param name="userManager">The user manager.</param>
109+
/// <param name="translations">The translation soruce</param>
110+
/// <param name="translationKey">The key of the translated message to send</param>
111+
/// <param name="arguments">The arguments for the message</param>
112+
public static void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations,
113+
IEnumerable<IUser> receivers, string translationKey, params object[] arguments)
114+
{
115+
userManager.Broadcast(null, receivers, translations.Get(translationKey, arguments));
116+
}
49117
}
50118
}

0 commit comments

Comments
 (0)