Fixes, everything localized?

This commit is contained in:
Kwoth 2017-02-13 13:44:21 +01:00
parent eb17f0b5b7
commit 5571f74c52
4 changed files with 73 additions and 61 deletions

View File

@ -14,12 +14,16 @@ namespace NadekoBot.Modules
protected readonly Logger _log; protected readonly Logger _log;
public readonly string _prefix; public readonly string _prefix;
public readonly CultureInfo cultureInfo; public readonly CultureInfo cultureInfo;
public readonly string ModuleTypeName;
public readonly string LowerModuleTypeName;
public NadekoModule(bool isTopLevelModule = true) public NadekoModule(bool isTopLevelModule = true)
{ {
//if it's top level module //if it's top level module
var typeName = isTopLevelModule ? this.GetType().Name : this.GetType().DeclaringType.Name; ModuleTypeName = isTopLevelModule ? this.GetType().Name : this.GetType().DeclaringType.Name;
if (!NadekoBot.ModulePrefixes.TryGetValue(typeName, out _prefix)) LowerModuleTypeName = ModuleTypeName.ToLowerInvariant();
if (!NadekoBot.ModulePrefixes.TryGetValue(ModuleTypeName, out _prefix))
_prefix = "?err?"; _prefix = "?err?";
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
@ -48,27 +52,37 @@ namespace NadekoBot.Modules
// return Context.Channel.SendErrorAsync(title, text, url, footer); // return Context.Channel.SendErrorAsync(title, text, url, footer);
//} //}
protected string GetText(string key)
{
return NadekoBot.ResponsesResourceManager.GetString(LowerModuleTypeName + "_" + key, cultureInfo);
}
protected string GetText(string key, params object[] replacements)
{
return string.Format(GetText(key), replacements);
}
public Task<IUserMessage> ErrorLocalized(string textKey, params object[] replacements) public Task<IUserMessage> ErrorLocalized(string textKey, params object[] replacements)
{ {
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); var text = GetText(textKey);
return Context.Channel.SendErrorAsync(string.Format(text, replacements)); return Context.Channel.SendErrorAsync(string.Format(text, replacements));
} }
public Task<IUserMessage> ReplyErrorLocalized(string textKey, params object[] replacements) public Task<IUserMessage> ReplyErrorLocalized(string textKey, params object[] replacements)
{ {
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); var text = GetText(textKey);
return Context.Channel.SendErrorAsync(Context.User.Mention + " " +string.Format(text, replacements)); return Context.Channel.SendErrorAsync(Context.User.Mention + " " +string.Format(text, replacements));
} }
public Task<IUserMessage> ConfirmLocalized(string textKey, params object[] replacements) public Task<IUserMessage> ConfirmLocalized(string textKey, params object[] replacements)
{ {
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); var text = GetText(textKey);
return Context.Channel.SendConfirmAsync(string.Format(text, replacements)); return Context.Channel.SendConfirmAsync(string.Format(text, replacements));
} }
public Task<IUserMessage> ReplyConfirmLocalized(string textKey, params object[] replacements) public Task<IUserMessage> ReplyConfirmLocalized(string textKey, params object[] replacements)
{ {
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); var text = GetText(textKey);
return Context.Channel.SendConfirmAsync(Context.User.Mention + " " + string.Format(text, replacements)); return Context.Channel.SendConfirmAsync(Context.User.Mention + " " + string.Format(text, replacements));
} }
} }

View File

@ -167,31 +167,31 @@ namespace NadekoBot.Modules.Pokemon
//apply damage to target //apply damage to target
targetStats.Hp -= damage; targetStats.Hp -= damage;
var response = $"{user.Mention} used **{move}**{userType.Icon} on {targetUser.Mention}{targetType.Icon} for **{damage}** damage"; var response = GetText("attack", move, userType.Icon, targetUser.Mention, targetType.Icon, damage);
//Damage type //Damage type
if (damage < 40) if (damage < 40)
{ {
response += "\nIt's not effective."; response += "\n" + GetText("not_effective");
} }
else if (damage > 60) else if (damage > 60)
{ {
response += "\nIt's super effective!"; response += "\n" + GetText("super_effective");
} }
else else
{ {
response += "\nIt's somewhat effective"; response += "\n" + GetText("somewhat_effective");
} }
//check fainted //check fainted
if (targetStats.Hp <= 0) if (targetStats.Hp <= 0)
{ {
response += $"\n**{targetUser.Mention}** has fainted!"; response += $"\n" + GetText("fainted", targetUser);
} }
else else
{ {
response += $"\n**{targetUser.Mention}** has {targetStats.Hp} HP remaining"; response += $"\n" + GetText("hp_remaining", targetUser, targetStats.Hp);
} }
//update other stats //update other stats
@ -208,7 +208,7 @@ namespace NadekoBot.Modules.Pokemon
Stats[user.Id] = userStats; Stats[user.Id] = userStats;
Stats[targetUser.Id] = targetStats; Stats[targetUser.Id] = targetStats;
await Context.Channel.SendMessageAsync(response).ConfigureAwait(false); await Context.Channel.SendConfirmAsync(Context.User.Mention + " " + response).ConfigureAwait(false);
} }
@ -220,12 +220,10 @@ namespace NadekoBot.Modules.Pokemon
var userType = GetPokeType(user.Id); var userType = GetPokeType(user.Id);
var movesList = userType.Moves; var movesList = userType.Moves;
var str = $"**Moves for `{userType.Name}` type.**"; var embed = new EmbedBuilder().WithOkColor()
foreach (string m in movesList) .WithTitle(GetText("moves", userType))
{ .WithDescription(string.Join("\n", movesList.Select(m => userType.Icon + " " + m)));
str += $"\n{userType.Icon}{m}"; await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
await Context.Channel.SendMessageAsync(str).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -268,13 +266,13 @@ namespace NadekoBot.Modules.Pokemon
Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2); Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2);
if (target == "yourself") if (target == "yourself")
{ {
await ReplyErrorLocalized("revive_yourself", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); await ReplyConfirmLocalized("revive_yourself", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
return; return;
} }
await ReplyErrorLocalized("revive_other", targetUser, NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); await ReplyConfirmLocalized("revive_other", targetUser, NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
} }
await ReplyErrorLocalized("healed", targetUser, NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false); await ReplyConfirmLocalized("healed", targetUser, NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
return; return;
} }
else else

View File

@ -141,34 +141,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to It&apos;s not effective.. /// Looks up a localized string similar to Movelist for &quot;{0}&quot; type.
/// </summary>
public static string pokemon_its_not_effective {
get {
return ResourceManager.GetString("pokemon_its_not_effective", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to It&apos;s somewhat effective..
/// </summary>
public static string pokemon_its_somewhat_effective {
get {
return ResourceManager.GetString("pokemon_its_somewhat_effective", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to It&apos;s super effective!.
/// </summary>
public static string pokemon_its_super_effective {
get {
return ResourceManager.GetString("pokemon_its_super_effective", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Moves for {0} type.
/// </summary> /// </summary>
public static string pokemon_moves { public static string pokemon_moves {
get { get {
@ -185,6 +158,15 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to It&apos;s not effective..
/// </summary>
public static string pokemon_not_effective {
get {
return ResourceManager.GetString("pokemon_not_effective", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to revived {0} with one {1}. /// Looks up a localized string similar to revived {0} with one {1}.
/// </summary> /// </summary>
@ -212,6 +194,24 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to It&apos;s somewhat effective..
/// </summary>
public static string pokemon_somewhat_effective {
get {
return ResourceManager.GetString("pokemon_somewhat_effective", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to It&apos;s super effective!.
/// </summary>
public static string pokemon_super_effective {
get {
return ResourceManager.GetString("pokemon_super_effective", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to You used too many moves in a row, so you can&apos;t move!. /// Looks up a localized string similar to You used too many moves in a row, so you can&apos;t move!.
/// </summary> /// </summary>

View File

@ -145,17 +145,11 @@
<data name="pokemon_invalid_move" xml:space="preserve"> <data name="pokemon_invalid_move" xml:space="preserve">
<value>You are not able to use **{0}**. Type {1}ml to see a list of moves you can use.</value> <value>You are not able to use **{0}**. Type {1}ml to see a list of moves you can use.</value>
</data> </data>
<data name="pokemon_its_not_effective" xml:space="preserve">
<value>It's not effective.</value>
</data>
<data name="pokemon_its_somewhat_effective" xml:space="preserve">
<value>It's somewhat effective.</value>
</data>
<data name="pokemon_its_super_effective" xml:space="preserve">
<value>It's super effective!</value>
</data>
<data name="pokemon_moves" xml:space="preserve"> <data name="pokemon_moves" xml:space="preserve">
<value>Moves for {0} type</value> <value>Movelist for "{0}" type</value>
</data>
<data name="pokemon_not_effective" xml:space="preserve">
<value>It's not effective.</value>
</data> </data>
<data name="pokemon_no_currency" xml:space="preserve"> <data name="pokemon_no_currency" xml:space="preserve">
<value>You don't have enough {0}</value> <value>You don't have enough {0}</value>
@ -169,6 +163,12 @@
<data name="pokemon_settype_success" xml:space="preserve"> <data name="pokemon_settype_success" xml:space="preserve">
<value>Your type has been changed to {0} for a {1}</value> <value>Your type has been changed to {0} for a {1}</value>
</data> </data>
<data name="pokemon_somewhat_effective" xml:space="preserve">
<value>It's somewhat effective.</value>
</data>
<data name="pokemon_super_effective" xml:space="preserve">
<value>It's super effective!</value>
</data>
<data name="pokemon_too_many_moves" xml:space="preserve"> <data name="pokemon_too_many_moves" xml:space="preserve">
<value>You used too many moves in a row, so you can't move!</value> <value>You used too many moves in a row, so you can't move!</value>
</data> </data>