mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
#nullable disable
|
|
namespace NadekoBot.Services;
|
|
|
|
public class LocalBotStringsProvider : IBotStringsProvider
|
|
{
|
|
private readonly IStringsSource _source;
|
|
private IReadOnlyDictionary<string, Dictionary<string, string>> responseStrings;
|
|
private IReadOnlyDictionary<string, Dictionary<string, CommandStrings>> commandStrings;
|
|
|
|
public LocalBotStringsProvider(IStringsSource source)
|
|
{
|
|
_source = source;
|
|
Reload();
|
|
}
|
|
|
|
public string GetText(string localeName, string key)
|
|
{
|
|
if (responseStrings.TryGetValue(localeName, out var langStrings) && langStrings.TryGetValue(key, out var text))
|
|
return text;
|
|
|
|
return null;
|
|
}
|
|
|
|
public void Reload()
|
|
{
|
|
responseStrings = _source.GetResponseStrings();
|
|
commandStrings = _source.GetCommandStrings();
|
|
}
|
|
|
|
public CommandStrings GetCommandStrings(string localeName, string commandName)
|
|
{
|
|
if (commandStrings.TryGetValue(localeName, out var langStrings)
|
|
&& langStrings.TryGetValue(commandName, out var strings))
|
|
return strings;
|
|
|
|
return null;
|
|
}
|
|
} |