mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Add functionality for awardtype localized names
This commit is contained in:
parent
fadd970c5d
commit
4be28f3c1b
@ -54,7 +54,7 @@ namespace JetKarmaBot.Commands
|
|||||||
|
|
||||||
var text = args.Message.Text;
|
var text = args.Message.Text;
|
||||||
var awardTypeText = cmd.Parameters.FirstOrDefault();
|
var awardTypeText = cmd.Parameters.FirstOrDefault();
|
||||||
var awardType = awardTypeText != null
|
global::JetKarmaBot.Models.AwardType awardType = awardTypeText != null
|
||||||
? db.AwardTypes.First(at => at.CommandName == awardTypeText)
|
? db.AwardTypes.First(at => at.CommandName == awardTypeText)
|
||||||
: db.AwardTypes.Find((sbyte)1);
|
: db.AwardTypes.Find((sbyte)1);
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ namespace JetKarmaBot.Commands
|
|||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
|
|
||||||
string message = awarding
|
string message = awarding
|
||||||
? string.Format(currentLocale["jetkarmabot.award.awardmessage"], awardType.Name, "@" + recipient.Username)
|
? string.Format(currentLocale["jetkarmabot.award.awardmessage"], getLocalizedName(awardType, currentLocale), "@" + recipient.Username)
|
||||||
: string.Format(currentLocale["jetkarmabot.award.revokemessage"], awardType.Name, "@" + recipient.Username);
|
: string.Format(currentLocale["jetkarmabot.award.revokemessage"], getLocalizedName(awardType, currentLocale), "@" + recipient.Username);
|
||||||
|
|
||||||
var currentCount = db.Awards
|
var currentCount = db.Awards
|
||||||
.Where(aw => aw.ToId == recipient.Id && aw.AwardTypeId == awardType.AwardTypeId)
|
.Where(aw => aw.ToId == recipient.Id && aw.AwardTypeId == awardType.AwardTypeId)
|
||||||
@ -87,6 +87,18 @@ namespace JetKarmaBot.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string getLocalizedName(global::JetKarmaBot.Models.AwardType awardType, Locale loc)
|
||||||
|
{
|
||||||
|
if (loc.ContainsKey($"jetkarmabot.awardtypes.{awardType.CommandName}"))
|
||||||
|
{
|
||||||
|
return loc[$"jetkarmabot.awardtypes.{awardType.CommandName}"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return awardType.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Inject] KarmaContextFactory Db { get; set; }
|
[Inject] KarmaContextFactory Db { get; set; }
|
||||||
[Inject] TelegramBotClient Client { get; set; }
|
[Inject] TelegramBotClient Client { get; set; }
|
||||||
[Inject] Localization Locale { get; set; }
|
[Inject] Localization Locale { get; set; }
|
||||||
|
|||||||
@ -100,7 +100,7 @@ namespace JetKarmaBot
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public class Locale
|
public class Locale : IReadOnlyDictionary<string, string>
|
||||||
{
|
{
|
||||||
private Dictionary<string, string> locale;
|
private Dictionary<string, string> locale;
|
||||||
private string localeName;
|
private string localeName;
|
||||||
@ -119,6 +119,33 @@ namespace JetKarmaBot
|
|||||||
public bool HasNote => note != null;
|
public bool HasNote => note != null;
|
||||||
|
|
||||||
public string Note => note;
|
public string Note => note;
|
||||||
|
|
||||||
|
public IEnumerable<string> Keys => ((IReadOnlyDictionary<string, string>)locale).Keys;
|
||||||
|
|
||||||
|
public IEnumerable<string> Values => ((IReadOnlyDictionary<string, string>)locale).Values;
|
||||||
|
|
||||||
|
public int Count => ((IReadOnlyDictionary<string, string>)locale).Count;
|
||||||
|
|
||||||
public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown";
|
public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown";
|
||||||
|
|
||||||
|
public bool ContainsKey(string key)
|
||||||
|
{
|
||||||
|
return ((IReadOnlyDictionary<string, string>)locale).ContainsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetValue(string key, out string value)
|
||||||
|
{
|
||||||
|
return ((IReadOnlyDictionary<string, string>)locale).TryGetValue(key, out value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||||
|
{
|
||||||
|
return ((IReadOnlyDictionary<string, string>)locale).GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return ((IReadOnlyDictionary<string, string>)locale).GetEnumerator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,6 +20,7 @@
|
|||||||
"jetkarmabot.changelocale.getlocale": "Я зараз кажу па-беларускай.",
|
"jetkarmabot.changelocale.getlocale": "Я зараз кажу па-беларускай.",
|
||||||
"jetkarmabot.changelocale.listalltext": "Я ведаю:",
|
"jetkarmabot.changelocale.listalltext": "Я ведаю:",
|
||||||
"jetkarmabot.changelocale.errorall": "Мне б хацелася гаварыць на ўсіх мовах у той жа самы час, але з-за абмежаванняў сусвету, мне гэта не дазваляецца.",
|
"jetkarmabot.changelocale.errorall": "Мне б хацелася гаварыць на ўсіх мовах у той жа самы час, але з-за абмежаванняў сусвету, мне гэта не дазваляецца.",
|
||||||
"jetkarmabot.changelocale.beforenote": "Увага: "
|
"jetkarmabot.changelocale.beforenote": "Увага: ",
|
||||||
|
"jetkarmabot.awardtypes.star": "Зорачка"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,6 +19,7 @@
|
|||||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English.",
|
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English.",
|
||||||
"jetkarmabot.changelocale.listalltext": "I know:",
|
"jetkarmabot.changelocale.listalltext": "I know:",
|
||||||
"jetkarmabot.changelocale.errorall": "I would like to speak all languages at once, but because of the rules of the universe, I am not allowed to do that.",
|
"jetkarmabot.changelocale.errorall": "I would like to speak all languages at once, but because of the rules of the universe, I am not allowed to do that.",
|
||||||
"jetkarmabot.changelocale.beforenote": "Warning: "
|
"jetkarmabot.changelocale.beforenote": "Warning: ",
|
||||||
|
"jetkarmabot.awardtypes.star": "Star"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,6 +19,7 @@
|
|||||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.",
|
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.",
|
||||||
"jetkarmabot.changelocale.listalltext": "Я знаю:",
|
"jetkarmabot.changelocale.listalltext": "Я знаю:",
|
||||||
"jetkarmabot.changelocale.errorall": "Мне бы хотелось говорить на всех языках в то же самое время, но из-за ограничений вселенной, мне это не позволяется.",
|
"jetkarmabot.changelocale.errorall": "Мне бы хотелось говорить на всех языках в то же самое время, но из-за ограничений вселенной, мне это не позволяется.",
|
||||||
"jetkarmabot.changelocale.beforenote": "Внимание: "
|
"jetkarmabot.changelocale.beforenote": "Внимание: ",
|
||||||
|
"jetkarmabot.awardtypes.star": "Звездочка"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user