Closed Dliix66 closed 5 days ago
Looks okay to me, might be worth adding a XML doc comment to the methods and updating the example plugin?
I can do that 👍
Since IStringLocalizer can be injected in other classes, would it not be better to create extension methods on IStringLocalizer?
public static class LocalizerExtensions
{
public static string ForPlayer(this IStringLocalizer localizer, CCSPlayerController player, string key)
{
if (player == null || player.IsValid == false)
return "";
using WithTemporaryCulture temporaryCulture = new WithTemporaryCulture(player.GetLanguage());
return localizer[key];
}
public static string ForPlayer(this IStringLocalizer localizer, CCSPlayerController player, string key, params object[] args)
{
if (player == null || player.IsValid == false)
return "";
using WithTemporaryCulture temporaryCulture = new WithTemporaryCulture(player.GetLanguage());
return localizer[key, args];
}
}
@roflmuffin I updated the example plugin and this should be available in the docs too.
I've added these as extension methods in build #258, which I think is cleaner/more extensible than amending the base class in this PR.
Added some more methods to simplify localization out of a command's context