using System; using System.Collections; using System.Collections.Generic; using UnityEngine; #if RH_SerializedDictionary using RotaryHeart.Lib.SerializableDictionary; #endif using AYellowpaper.SerializedCollections; namespace BITKit { public sealed class TranslateSO : ScriptableObject { #if RH_SerializedDictionary public SerializableDictionaryBase dictionary = new(); #else public SerializedDictionary dictionary = new(); #endif public string Get(string text, bool isLocalization = true) { foreach (var word in dictionary) { var value = word.Value; if (isLocalization) { try { value = DI.Get().Translate(value); } catch (NullReferenceException){} } text = text.Replace(word.Key, value); } return text; } public string GetAt(string key, bool isLocalization = true) { if (dictionary.TryGetValue(key, out var value)) { try { if (isLocalization) { var translater = DI.Get(); value = translater.Translate(value); } } catch (NullReferenceException){} return value; } else { /* if (isLocalization) value = translater.Translate(value); */ return key; } } } }