What I’m looking for is to ‘code’ a simple translator.
Basically 2 text fields,a translate button, and a code that is more of less like this:
if varx = h
print "hello"
elseif varx = b
print "bye"
else varx = n
print "none"
Obviously this code isn’t going to work but I’m looking for guidance on how to do this(not the actual solution, just the “direction” on where to head.).
Interestingly, I just added support for localization to my own Unity Project
The general idea, instead of hard-coding if/elses, you’d want to set up a Dictionary/Map/Hashtable that basically has a list of string key/value pairs, and just pull the value based on the key. You can then load those pairs from an external file to allow to add/change translations without needing to recode anything, like this:
protected Dictionary<string, string> _TextTable = new Dictionary<string,string>();
public void Load()
{
//... load from file or something
}
public string GetValue( string key )
{
if( _TextTable.ContainsKey(key) )
{
return _TextTable[key];
}
Debug.LogError("Key " + key + " not found in text table!");
return "";
}
The problem you are looking at is well known in games and is commonly referred to as “Localization” so just google “unity + localization” and you should find more info.