40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using RotaryHeart.Lib.SerializableDictionary;
|
|
namespace BITKit
|
|
{
|
|
public sealed class TranslateSO : ScriptableObject
|
|
{
|
|
public SerializableDictionaryBase<string, string> dictionary = new();
|
|
public string Get(string text, bool isLocalization = true)
|
|
{
|
|
foreach (var word in dictionary)
|
|
{
|
|
var value = word.Value;
|
|
if (isLocalization)
|
|
{
|
|
value = DI.Get<ITranslator>().Translate(value);
|
|
}
|
|
text = text.Replace(word.Key, value);
|
|
}
|
|
return text;
|
|
}
|
|
public string GetAt(string key, bool isLocalization = true)
|
|
{
|
|
var translater = DI.Get<ITranslator>();
|
|
if (dictionary.TryGetValue(key, out var value))
|
|
{
|
|
if (isLocalization)
|
|
value = translater.Translate(value);
|
|
return value;
|
|
}
|
|
else
|
|
{
|
|
/* if (isLocalization)
|
|
value = translater.Translate(value); */
|
|
return key;
|
|
}
|
|
}
|
|
}
|
|
} |