starOfWords/Assets/Scripts/WordPair.cs

45 lines
978 B
C#
Raw Normal View History

using System;
using System.Reflection;
[Serializable]
public class WordPair
{
public string tr;
public string en;
public string es;
public string de;
public string fr;
public string pt;
private const string DefaultLang = "en";
public WordPair(string tr, string en, string es, string de, string fr, string pt)
{
this.tr = tr;
this.en = en;
this.es = es;
this.de = de;
this.fr = fr;
this.pt = pt;
}
public string GetByCode(string code)
{
if (string.IsNullOrWhiteSpace(code))
code = DefaultLang;
string safe = code.ToLower();
FieldInfo f = this.GetType().GetField(safe);
if (f != null)
{
string val = f.GetValue(this) as string;
if (!string.IsNullOrEmpty(val))
return val;
}
return GetByCode(DefaultLang);
}
public string Get(string code) => GetByCode(code);
}