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[i] == 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?
Answer by EpiFouloux · Jun 15, 2016 at 01:43 PM
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]);
}
}
Answer by YasanthaPrabath · Jun 15, 2016 at 02:08 PM
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
}
}
Hi, Thanks for the reply.
This looks like the right direction but I'm still a bit confused, I get the concept but unsure how to apply it correctly.
Any chance you could elaborate a little, please?
Your answer
Follow this Question
Related Questions
How to get the active/loaded Scene then turn the name of it into a string? [C#] 1 Answer
List of Structs variable values not changing 1 Answer
Do Something If Temperature Reading Changes 0 Answers
Accessing a non-static string variable in another script C# 1 Answer
How to make a main menu like that ? 1 Answer