function based on return value

I’ve got a project set up the translates text to multiple languages by selecting a language in the first scene.

I want to expand on this by also adding voice overs in the correct language.

I need something along the lines of: get current language. if language = English, Play(“EnglishVoiceOver.mp3”);

Below is the piece of code that selects the language by referencing a CSV file:

public static bool SelectLanguage(string alanguage)
	{
		currentLanguageIndex = -1;
		for(int i = 0; i < AvailableLanguages.Length; ++i)
			if (AvailableLanguages *== alanguage)*
  •  	{*
    
  •  		currentLanguageIndex = i;*
    
  •  		break;*
    
  •  	}*
    
  •  if (Application.isPlaying)*
    
  •  {*
    
  •  	if(LocalizationChanged != null)*
    
  •  		LocalizationChanged();*
    
  •  }*
    
  •  return currentLanguageIndex >= 0;*
    
  • }*

  • public static string Get(string key)*

  • {*

  •  string[] vals;*
    
  •  if (currentLanguageIndex != -1 && dictionary.TryGetValue(key, out vals))*
    
  •  {*
    
  •  	if (currentLanguageIndex < vals.Length)*
    
  •  		return vals[currentLanguageIndex];*
    
  •  }*
    

Can anyone give me any ideas please?

Ideas about what, it’s not really clear…
I think you’re question is about how to save the language and apply it every time you need it:

Just set a int variable (static if you want) as the language (you did it, it’s currentLanguageIndex)

then every time you need to play a sound or write a text :

public class Example
{
   private String[] welcome_texts = 
    {
        "Welcome",
        "Bienvenue",
         "Bienvenido"
    };

   void print_welcome()
   {
      print(welcome[Language.currentLanguageIndex]);
   }
}

How about you saving the file name of the vo along with text Id( key ) and depend on the key load the Audio files from Resources folder on run time and play. You put VO files on different folders according to language.

simple class structure from top of my head,

public enum LocaliseLanguage { English,Italian }

class LocalizeSentence
{
 string TextId;
 string LocalizedText;
 string VOFileName;
}

public class LocalizeSentenses
{
   public LocaliseLanguage MyLanguage;
   List<LocalizeSentence>    LocalizeSentence;

  public string GetText( string Id )
  {
  // search given id and return LocalizedText
  }

  public string GetVOFileName()
  {
   // search given id and return VOFileName
  }
}