mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 17:19:00 +03:00
Macintxsh
d3053d87e8
295 PR/issues ~(not 300, however)~ or ~1.5 years ago, I made #2, the Russian language replacement aka mctaylors-ru. This was my first contribution to the Octobot project (formerly known as Boyfriend). This was to add some sort of unique, unusual feature to Octobot, which doesn't have any moderator bots. Everyone loved the language. But it just became difficult to maintain. I certainly don't want to get rid of it, but it leaves me no other choice. This isn't a joke or anything like that. I'm tired of maintaining it. And I'm sure the other contributors are too. This PR removes the mctaylors-ru language. --------- Signed-off-by: mctaylors <cantsendmails@mctaylors.ru> Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Globalization;
|
|
using System.Text.Json.Nodes;
|
|
using Remora.Discord.Extensions.Formatting;
|
|
using Remora.Results;
|
|
|
|
namespace Octobot.Data.Options;
|
|
|
|
/// <inheritdoc />
|
|
public sealed class LanguageOption : Option<CultureInfo>
|
|
{
|
|
private static readonly Dictionary<string, CultureInfo> CultureInfoCache = new()
|
|
{
|
|
{ "en", new CultureInfo("en-US") },
|
|
{ "ru", new CultureInfo("ru-RU") }
|
|
};
|
|
|
|
public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { }
|
|
|
|
public override string Display(JsonNode settings)
|
|
{
|
|
return Markdown.InlineCode(settings[Name]?.GetValue<string>() ?? "en");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override CultureInfo Get(JsonNode settings)
|
|
{
|
|
var property = settings[Name];
|
|
return property != null ? CultureInfoCache[property.GetValue<string>()] : DefaultValue;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override Result Set(JsonNode settings, string from)
|
|
{
|
|
return CultureInfoCache.ContainsKey(from.ToLowerInvariant())
|
|
? base.Set(settings, from.ToLowerInvariant())
|
|
: new ArgumentInvalidError(nameof(from), Messages.LanguageNotSupported);
|
|
}
|
|
}
|