Last active
July 27, 2020 07:27
-
-
Save hk1ll3r/d93e4228edc78ab9bea87070dd5719bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class TextLocalizer : MonoBehaviour | |
{ | |
public static string CurrentLanguage = "english"; | |
static Dictionary<string, Dictionary<string, string>> Translations = new Dictionary<string, Dictionary<string, string>>() { | |
["english"] = new Dictionary<string, string>() { | |
["menu_resume"] = "Resume", | |
["menu_settings"] = "Settings", | |
["menu_exit"] = "Exit", | |
}, | |
["spanish"] = new Dictionary<string, string>() { | |
["menu_resume"] = "Reanudar", | |
["menu_settings"] = "Configuraciones", | |
["menu_exit"] = "Salida", | |
} | |
}; | |
[SerializeField] string id; | |
public string ResolveStringValue(string id) { | |
return Translations[CurrentLanguage][id]; | |
} | |
void Start() { | |
GetComponent<Text>().text = ResolveStringValue(id); | |
} | |
void OnValidate() { | |
GetComponent<Text>().text = ResolveStringValue(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment