You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhishingAwarenessSimulation/Assets/Scripts/LocalizedTextComponent.cs

49 lines
1.4 KiB
C#

using UnityEngine;
using TMPro;
using ArabicSupport;
[RequireComponent(typeof(TextMeshProUGUI))]
public class LocalizedTextComponent : MonoBehaviour
{
public string localizationKey;
private TextMeshProUGUI tmp;
private void Start()
{
tmp = GetComponent<TextMeshProUGUI>();
if (LanguageManager.Instance != null)
{
LanguageManager.Instance.Register(this);
UpdateText();
}
else
{
Debug.LogWarning($"LanguageManager is not initialized yet for {gameObject.name}. Skipping registration.");
}
}
void OnDestroy()
{
if (LanguageManager.Instance != null)
{
LanguageManager.Instance.Unregister(this);
}
}
public void UpdateText()
{
if (LanguageManager.Instance == null)
{
Debug.LogWarning($"LanguageManager not available when updating text for {gameObject.name}");
return;
}
bool isArabic = LanguageManager.Instance.currentLanguage == "Arabic";
string rawText = LanguageManager.Instance.GetLocalizedText(localizationKey);
tmp.text = isArabic ? ArabicFixer.Fix(rawText) : rawText;
tmp.font = LanguageManager.Instance.GetCurrentFont();
//tmp.isRightToLeftText = isArabic;
//tmp.alignment = isArabic ? TextAlignmentOptions.Right : TextAlignmentOptions.Left;
}
}