46 lines
766 B
C#
46 lines
766 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace OHM.UnityToolkit.Localization
|
|
{
|
|
public class LocalizedText : MonoBehaviour
|
|
{
|
|
public string key;
|
|
|
|
public TextWrapper text;
|
|
|
|
private void Awake()
|
|
{
|
|
text = GetComponent<TextWrapper>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
ApplyLocalization();
|
|
LocalizationManager.Instance.OnLangChanged.AddListener(ApplyLocalization);
|
|
}
|
|
|
|
public void ChangeKey(string key)
|
|
{
|
|
this.key = key;
|
|
ApplyLocalization();
|
|
}
|
|
|
|
public void ApplyLocalization()
|
|
{
|
|
SetText(string.IsNullOrEmpty(key)
|
|
? string.Empty
|
|
: LocalizationUtils.Localize(LocalizationManager.Instance.CurrentLocale, key));
|
|
}
|
|
|
|
private void SetText(string content)
|
|
{
|
|
if (text != null)
|
|
{
|
|
text.text = content;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|