using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Localization.Settings; public class TextHandler : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public static string getText(string key){ bool hasLeftBracket = false; bool hasRightBracket = false; if(key.Contains("(")){ hasLeftBracket = true; key = key.Replace("(",""); } if(key.Contains(")")){ hasRightBracket = true; key = key.Replace(")",""); } if(key[0].Equals(Char.ToUpperInvariant(key[0]))){ key = Char.ToLowerInvariant(key[0]) + key.Substring(1); } string text = LocalizationSettings.StringDatabase.GetLocalizedString("MyTexts",key); if(hasLeftBracket){ text = "(" + text; } if(hasRightBracket){ text = text + ")"; } return text; } public static string translate(string text){ string result = ""; string[] parts = text.Split(" "); for(int i = 0; i < parts.Length; i++){ try{ int.Parse(parts[i]); result += parts[i] + " "; } catch(Exception){ if(parts[i].Contains("/")){ result += parts[i] + " "; } else{ result += getText(parts[i]) + " "; } } } return result; } }