Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to translate achievements #578

Open
wants to merge 9 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions Werewolf for Telegram/Database/AchievementsReworked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,40 @@ public enum AchievementsReworked

public static partial class Extensions
{
public static string GetDescription(this AchievementsReworked value)
public static string GetDescription(this AchievementsReworked value, bool text = true)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
if (text)
{
FieldInfo fi = value.GetType().GetField(value.ToString());

DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute),
false);
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute),
false);

if (attributes != null &&
attributes.Length > 0)
return attributes[0].Description;
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Description;
else
return value.ToString();
}
else
return value.ToString();
return $"Achievement{value.ToString()}Descr";
}
public static string GetName(this AchievementsReworked value)
public static string GetName(this AchievementsReworked value, bool text = true)
{
var fieldInfo = value.GetType().GetField(value.ToString());
if (text)
{
var fieldInfo = value.GetType().GetField(value.ToString());

var descriptionAttributes = fieldInfo.GetCustomAttributes(
typeof(DisplayAttribute), false) as DisplayAttribute[];
var descriptionAttributes = fieldInfo.GetCustomAttributes(
typeof(DisplayAttribute), false) as DisplayAttribute[];

if (descriptionAttributes == null) return string.Empty;
return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString();
if (descriptionAttributes == null) return string.Empty;
return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString();
}
else
return $"Achievement{value.ToString()}Name";
}

public static byte[] ToByteArray(this BitArray bits)
Expand Down
Loading