using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Xml.Serialization; namespace ReZero.SuperAPI { internal class TextHandler { /// /// Get the common text based on the language. /// /// The Chinese text. /// The English text. /// The common text. public static string GetCommonText(string cn, string en) { var language = App.Language; switch (language) { case Language.CN: return cn; default: return en; } } /// /// Get the interface category text based on the value. /// /// The value. /// The interface category text. public static string? GetInterfaceCategoryText(object value) { return GetText(typeof(InterfaceCategoryInitializerProvider), value); } /// /// Get the interface list text based on the value. /// /// The value. /// The interface list text. public static string? GetInterfaceListText(object value) { return GetText(typeof(InterfaceListInitializerProvider), value); } /// /// Get the text based on the type and value. /// /// The type. /// The value. /// The text. public static string? GetText(Type type, object value) { var language = App.Language; var fieldInfo = type.GetFields() .Where(it => it.GetCustomAttribute() != null) .Where(it => it.GetValue(null)?.ToString() == value?.ToString()) .FirstOrDefault(); switch (language) { case Language.CN: return fieldInfo?.GetCustomAttribute()?.Text; default: return fieldInfo?.GetCustomAttribute()?.Text; } } } }