Add functionality for awardtype localized names

This commit is contained in:
Basique Evangelist 2019-02-07 17:14:36 +03:00
parent 7552303a6e
commit a7493e4911
5 changed files with 49 additions and 7 deletions

View File

@ -54,7 +54,7 @@ namespace JetKarmaBot.Commands
var text = args.Message.Text;
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.Find((sbyte)1);
@ -70,8 +70,8 @@ namespace JetKarmaBot.Commands
db.SaveChanges();
string message = awarding
? string.Format(currentLocale["jetkarmabot.award.awardmessage"], awardType.Name, "@" + recipient.Username)
: string.Format(currentLocale["jetkarmabot.award.revokemessage"], awardType.Name, "@" + recipient.Username);
? string.Format(currentLocale["jetkarmabot.award.awardmessage"], getLocalizedName(awardType, currentLocale), "@" + recipient.Username)
: string.Format(currentLocale["jetkarmabot.award.revokemessage"], getLocalizedName(awardType, currentLocale), "@" + recipient.Username);
var currentCount = db.Awards
.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] TelegramBotClient Client { get; set; }
[Inject] Localization Locale { get; set; }

View File

@ -100,7 +100,7 @@ namespace JetKarmaBot
}
public class Locale
public class Locale : IReadOnlyDictionary<string, string>
{
private Dictionary<string, string> locale;
private string localeName;
@ -119,6 +119,33 @@ namespace JetKarmaBot
public bool HasNote => note != null;
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 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();
}
}
}

View File

@ -20,6 +20,7 @@
"jetkarmabot.changelocale.getlocale": "Я зараз кажу па-беларускай.",
"jetkarmabot.changelocale.listalltext": "Я ведаю:",
"jetkarmabot.changelocale.errorall": "Мне б хацелася гаварыць на ўсіх мовах у той жа самы час, але з-за абмежаванняў сусвету, мне гэта не дазваляецца.",
"jetkarmabot.changelocale.beforenote": "Увага: "
"jetkarmabot.changelocale.beforenote": "Увага: ",
"jetkarmabot.awardtypes.star": "Зорачка"
}
}

View File

@ -19,6 +19,7 @@
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English.",
"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.beforenote": "Warning: "
"jetkarmabot.changelocale.beforenote": "Warning: ",
"jetkarmabot.awardtypes.star": "Star"
}
}

View File

@ -19,6 +19,7 @@
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.",
"jetkarmabot.changelocale.listalltext": "Я знаю:",
"jetkarmabot.changelocale.errorall": "Мне бы хотелось говорить на всех языках в то же самое время, но из-за ограничений вселенной, мне это не позволяется.",
"jetkarmabot.changelocale.beforenote": "Внимание: "
"jetkarmabot.changelocale.beforenote": "Внимание: ",
"jetkarmabot.awardtypes.star": "Звездочка"
}
}