mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Allow adding of common names of locales to locale files
This commit is contained in:
parent
d20cc89f28
commit
51dce7f588
@ -23,7 +23,12 @@ namespace JetKarmaBot.Commands
|
||||
replyToMessageId: args.Message.MessageId);
|
||||
return true;
|
||||
}
|
||||
db.Chats.Find(args.Message.Chat.Id).Locale = cmd.Parameters[0];
|
||||
string localeId;
|
||||
if (Locale.ContainsLocale(cmd.Parameters[0]))
|
||||
localeId = cmd.Parameters[0];
|
||||
else
|
||||
localeId = Locale.FindByCommonName(cmd.Parameters[0]).Name;
|
||||
db.Chats.Find(args.Message.Chat.Id).Locale = localeId;
|
||||
db.SaveChanges();
|
||||
|
||||
currentLocale = Locale[db.Chats.Find(args.Message.Chat.Id).Locale];
|
||||
|
||||
@ -9,7 +9,7 @@ namespace JetKarmaBot
|
||||
{
|
||||
public class Localization
|
||||
{
|
||||
private Dictionary<string, Dictionary<string, string>> locales = new Dictionary<string, Dictionary<string, string>>();
|
||||
private Dictionary<string, Locale> locales = new Dictionary<string, Locale>();
|
||||
|
||||
[Inject]
|
||||
public Localization(Config cfg)
|
||||
@ -25,7 +25,7 @@ namespace JetKarmaBot
|
||||
{
|
||||
string langName = Path.GetFileNameWithoutExtension(langFilePath);
|
||||
string langKey = langName.ToLowerInvariant();
|
||||
locales[langKey] = JObject.Parse(File.ReadAllText(langFilePath)).ToObject<Dictionary<string, string>>();
|
||||
locales[langKey] = new Locale(JObject.Parse(File.ReadAllText(langFilePath)), langKey);
|
||||
Log("Found " + langName);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -46,9 +46,20 @@ namespace JetKarmaBot
|
||||
get
|
||||
{
|
||||
locale = locale.ToLowerInvariant();
|
||||
return new Locale(locales[locale], locale);
|
||||
return locales[locale];
|
||||
}
|
||||
}
|
||||
public Locale FindByCommonName(string name)
|
||||
{
|
||||
foreach (Locale l in locales.Values)
|
||||
{
|
||||
if (l.CommonNames.Contains(name))
|
||||
{
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public bool ContainsLocale(string locale)
|
||||
{
|
||||
locale = locale.ToLowerInvariant();
|
||||
@ -64,11 +75,16 @@ namespace JetKarmaBot
|
||||
{
|
||||
private Dictionary<string, string> locale;
|
||||
private string localeName;
|
||||
public Locale(Dictionary<string, string> locale, string localeName)
|
||||
private string[] commonNames;
|
||||
|
||||
public Locale(JObject locale, string localeName)
|
||||
{
|
||||
this.locale = locale;
|
||||
this.locale = locale.Property("strings").Value.ToObject<Dictionary<string, string>>();
|
||||
this.localeName = localeName;
|
||||
this.commonNames = locale.Property("names").Value.ToObject<string[]>();
|
||||
}
|
||||
public string[] CommonNames => commonNames;
|
||||
public string Name => localeName;
|
||||
public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
{
|
||||
"jetkarmabot.award.errawardnoreply": "Please use this command in reply to another user.",
|
||||
"jetkarmabot.award.errawardself": "Please stop playing with yourself.",
|
||||
"jetkarmabot.award.errawardbot": "I am a bot, and have no use for your foolish fake internet points.",
|
||||
"jetkarmabot.award.errrevokebot": "ಠ_ಠ",
|
||||
"jetkarmabot.award.awardmessage": "Awarded a {0} to {1}!",
|
||||
"jetkarmabot.award.revokemessage": "Revoked a {0} from {1}!",
|
||||
"jetkarmabot.award.statustext": "{0} is at {1}{2} now.",
|
||||
"jetkarmabot.status.listalltext": "Your badges report:",
|
||||
"jetkarmabot.status.listspecifictext": "You are at {0}{1} now.",
|
||||
"jetkarmabot.changelocale.justchanged": "Roger that.",
|
||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English."
|
||||
"names": [
|
||||
"english"
|
||||
],
|
||||
"strings": {
|
||||
"jetkarmabot.award.errawardnoreply": "Please use this command in reply to another user.",
|
||||
"jetkarmabot.award.errawardself": "Please stop playing with yourself.",
|
||||
"jetkarmabot.award.errawardbot": "I am a bot, and have no use for your foolish fake internet points.",
|
||||
"jetkarmabot.award.errrevokebot": "ಠ_ಠ",
|
||||
"jetkarmabot.award.awardmessage": "Awarded a {0} to {1}!",
|
||||
"jetkarmabot.award.revokemessage": "Revoked a {0} from {1}!",
|
||||
"jetkarmabot.award.statustext": "{0} is at {1}{2} now.",
|
||||
"jetkarmabot.status.listalltext": "Your badges report:",
|
||||
"jetkarmabot.status.listspecifictext": "You are at {0}{1} now.",
|
||||
"jetkarmabot.changelocale.justchanged": "Roger that.",
|
||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English."
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,19 @@
|
||||
{
|
||||
"jetkarmabot.award.errawardnoreply": "Пожалуйста используйте эту команду в ответе другому пользователю.",
|
||||
"jetkarmabot.award.errawardself": "Хватит с собой играться.",
|
||||
"jetkarmabot.award.errawardbot": "Я бот, и меня ваши жалкие пузомерки не прельщают.",
|
||||
"jetkarmabot.award.errrevokebot": "ಠ_ಠ",
|
||||
"jetkarmabot.award.awardmessage": "Вручил \"{0}\" {1}!",
|
||||
"jetkarmabot.award.revokemessage": "Отнял \"{0}\" у {1}!",
|
||||
"jetkarmabot.award.statustext": "У {0} теперь {1}{2}.",
|
||||
"jetkarmabot.status.listalltext": "У вас :",
|
||||
"jetkarmabot.status.listspecifictext": "У вас сейчас {0}{1}.",
|
||||
"jetkarmabot.changelocale.justchanged": "Так точно.",
|
||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски."
|
||||
"names": [
|
||||
"russian",
|
||||
"русский"
|
||||
],
|
||||
"strings": {
|
||||
"jetkarmabot.award.errawardnoreply": "Пожалуйста используйте эту команду в ответе другому пользователю.",
|
||||
"jetkarmabot.award.errawardself": "Хватит с собой играться.",
|
||||
"jetkarmabot.award.errawardbot": "Я бот, и меня ваши жалкие пузомерки не прельщают.",
|
||||
"jetkarmabot.award.errrevokebot": "ಠ_ಠ",
|
||||
"jetkarmabot.award.awardmessage": "Вручил \"{0}\" {1}!",
|
||||
"jetkarmabot.award.revokemessage": "Отнял \"{0}\" у {1}!",
|
||||
"jetkarmabot.award.statustext": "У {0} теперь {1}{2}.",
|
||||
"jetkarmabot.status.listalltext": "У вас :",
|
||||
"jetkarmabot.status.listspecifictext": "У вас сейчас {0}{1}.",
|
||||
"jetkarmabot.changelocale.justchanged": "Так точно.",
|
||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски."
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user