There are several times in our software the possibility to change the language in different ways. Mostly this is done via a dropdown. However, not all supported languages are always available as translations. So I’m trying to create a list of bools that can be used to activate and deactivate the respective language as a button everywhere. My current solution is unattractive to say the least. I have manually created all language as public bool and compare them in a loop. How to do it better?
// german
public bool de = true;
// english
public bool en = true;
public bool tr = true;
public bool ar = true;
public bool fa = true;
public bool ru = true;
public bool fr = true;
public bool pl = true;
public bool ro = true;
public bool sr = true;
public bool ur = true;
public bool bg = true;
public bool el = true;
public bool cs = true;
public bool es = true;
public bool it = true;
public bool sv = true;
public bool ti = true;
public bool sq = true;
public bool ku = true;
public bool so = true;
public bool uk = true;
public bool hu = true;
public bool sk = true;
public IEnumerator Initialize()
{
// activate/deactivate Languages
//var allLanguagesLists = GameObject.FindGameObjectsWithTag("LanguageDropDown");
// Find Objects with tag works only with active objects - static list is fast and save
foreach (GameObject gO in LanguageDropDowns)
{
foreach (Transform child in gO.transform)
{
if(child.GetComponent<LanguageEntryButton>().Language.ToString() == "de")
child.gameObject.SetActive(de);
if (child.GetComponent<LanguageEntryButton>().Language.ToString() == "en")
child.gameObject.SetActive(en);
}
}
}
I would probably make an enum of all of the values and then make a List of them. No need for Bools- if they are on the list then “yes”, if they’re not on the list than “no”.