diff --git a/Assets/_DDD/_Scripts/GameFramework/Localization/LocalizationManager.cs b/Assets/_DDD/_Scripts/GameFramework/Localization/LocalizationManager.cs index 4ada9b995..6dab72e88 100644 --- a/Assets/_DDD/_Scripts/GameFramework/Localization/LocalizationManager.cs +++ b/Assets/_DDD/_Scripts/GameFramework/Localization/LocalizationManager.cs @@ -1,5 +1,8 @@ +using System.Collections.Generic; using UnityEngine.Localization.Settings; using System.Linq; +using System.Threading.Tasks; +using UnityEngine; namespace DDD { @@ -11,28 +14,69 @@ public enum TableName Global_Message, } - public static class LocalizationManager + public class LocalizationManager : Singleton, IManager { + private readonly Dictionary _localizedCache = new(); + private string _currentLocaleCode; + private bool _isInitialized; + + public void PreInit() + { + _localizedCache.Clear(); + _currentLocaleCode = GetCurrentLocaleCode(); + + foreach (TableName table in System.Enum.GetValues(typeof(TableName))) + { + if (table == TableName.None) continue; + + var tableName = table.ToString(); + var stringTable = LocalizationSettings.StringDatabase.GetTable(tableName); + + if (stringTable == null) + { + Debug.LogWarning($"[Localization] Table not found: {tableName}"); + continue; + } + + foreach (var entry in stringTable.Values) + { + if (entry == null || string.IsNullOrEmpty(entry.KeyId.ToString())) continue; + + if (!_localizedCache.ContainsKey(entry.Key)) + { + _localizedCache.Add(entry.Key, entry.GetLocalizedString()); + } + } + } + + _isInitialized = true; + } + + public Task Init() + { + return Task.CompletedTask; + } + + public void PostInit() + { + + } + /// /// 현재 선택된 로케일 기준으로 로컬라이징 텍스트를 가져옵니다. /// - public static string GetString(TableName table, string key) + public string GetString(string key) { - if (table == TableName.None || string.IsNullOrEmpty(key)) - return $"[Invalid:{table}/{key}]"; + if (!_isInitialized) + { + Debug.LogWarning("[LocalizationManager] 호출 전에 초기화되지 않았습니다."); + return $"[Uninitialized:{key}]"; + } - var locale = LocalizationSettings.SelectedLocale; - var tableName = table.ToString(); - - var stringTable = LocalizationSettings.StringDatabase.GetTable(tableName, locale); - if (stringTable == null) - return $"[Missing Table:{tableName}]"; - - var entry = stringTable.GetEntry(key); - if (entry == null) - return $"[Missing Key:{key}]"; - - return entry.GetLocalizedString(); + if (_localizedCache.TryGetValue(key, out var value)) return value; + + Debug.LogError("[LocalizationManager] key값이 존재하지 않습니다."); + return null; } /// @@ -46,12 +90,13 @@ public static string GetCurrentLocaleCode() /// /// 로케일 코드로 현재 언어를 설정합니다. (예: "ko", "en", "ja") /// - public static void SetLocale(string code) + public void SetLocale(string code) { - var locale = LocalizationSettings.AvailableLocales.Locales - .FirstOrDefault(l => l.Identifier.Code == code); + var locale = LocalizationSettings.AvailableLocales.Locales.FirstOrDefault(l => l.Identifier.Code == code); if (locale != null) + { LocalizationSettings.SelectedLocale = locale; + } } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/GlobalMessageUi.cs b/Assets/_DDD/_Scripts/GameUi/GlobalMessageUi.cs index da527157a..e119e5de7 100644 --- a/Assets/_DDD/_Scripts/GameUi/GlobalMessageUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/GlobalMessageUi.cs @@ -53,7 +53,7 @@ private void TryDisplayNext() var evt = _messageQueue.Dequeue(); _isDisplayingMessage = true; - _messageText.text = LocalizationManager.GetString(TableName.Global_Message, evt.NewMessageKey); + _messageText.text = LocalizationManager.Instance.GetString(evt.NewMessageKey); Open(); _fadeTween?.Kill();