현지화 시스템 캐싱 로직 재수정
This commit is contained in:
parent
90afe5129a
commit
632b8ebb4f
@ -3,6 +3,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Localization;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
@ -16,7 +17,7 @@ public enum TableName
|
|||||||
|
|
||||||
public class LocalizationManager : Singleton<LocalizationManager>, IManager
|
public class LocalizationManager : Singleton<LocalizationManager>, IManager
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, string> _localizedCache = new();
|
private readonly Dictionary<string, LocalizedString> _localizedCache = new();
|
||||||
private string _currentLocaleCode;
|
private string _currentLocaleCode;
|
||||||
private bool _isInitialized;
|
private bool _isInitialized;
|
||||||
|
|
||||||
@ -40,11 +41,16 @@ public void PreInit()
|
|||||||
|
|
||||||
foreach (var entry in stringTable.Values)
|
foreach (var entry in stringTable.Values)
|
||||||
{
|
{
|
||||||
if (entry == null || string.IsNullOrEmpty(entry.KeyId.ToString())) continue;
|
if (entry == null || string.IsNullOrEmpty(entry.Key)) continue;
|
||||||
|
|
||||||
if (!_localizedCache.ContainsKey(entry.Key))
|
if (!_localizedCache.ContainsKey(entry.Key))
|
||||||
{
|
{
|
||||||
_localizedCache.Add(entry.Key, entry.GetLocalizedString());
|
var localizedString = new LocalizedString
|
||||||
|
{
|
||||||
|
TableReference = tableName,
|
||||||
|
TableEntryReference = entry.Key
|
||||||
|
};
|
||||||
|
_localizedCache.Add(entry.Key, localizedString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,12 +71,12 @@ public void PostInit()
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 현재 선택된 로케일 기준으로 로컬라이징 텍스트를 가져옵니다.
|
/// 현재 선택된 로케일 기준으로 로컬라이징 텍스트를 가져옵니다.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetString(string key)
|
public LocalizedString GetLocalizedString(string key)
|
||||||
{
|
{
|
||||||
if (!_isInitialized)
|
if (!_isInitialized)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("[LocalizationManager] 호출 전에 초기화되지 않았습니다.");
|
Debug.LogWarning("[LocalizationManager] 호출 전에 초기화되지 않았습니다.");
|
||||||
return $"[Uninitialized:{key}]";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_localizedCache.TryGetValue(key, out var value)) return value;
|
if (_localizedCache.TryGetValue(key, out var value)) return value;
|
||||||
@ -79,6 +85,12 @@ public string GetString(string key)
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetString(string key)
|
||||||
|
{
|
||||||
|
var localizedString = GetLocalizedString(key);
|
||||||
|
return LocalizationSettings.StringDatabase.GetLocalizedString(localizedString.TableReference, key, LocalizationSettings.SelectedLocale);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 현재 사용 중인 로케일 코드 반환 (예: "ko", "en", "ja")
|
/// 현재 사용 중인 로케일 코드 반환 (예: "ko", "en", "ja")
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user