현지화 시스템 로직 수정
캐싱된 key값 사용으로 변경
This commit is contained in:
parent
ad6f8fa409
commit
90afe5129a
@ -1,5 +1,8 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine.Localization.Settings;
|
using UnityEngine.Localization.Settings;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
@ -11,28 +14,69 @@ public enum TableName
|
|||||||
Global_Message,
|
Global_Message,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LocalizationManager
|
public class LocalizationManager : Singleton<LocalizationManager>, IManager
|
||||||
{
|
{
|
||||||
|
private readonly Dictionary<string, string> _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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 현재 선택된 로케일 기준으로 로컬라이징 텍스트를 가져옵니다.
|
/// 현재 선택된 로케일 기준으로 로컬라이징 텍스트를 가져옵니다.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetString(TableName table, string key)
|
public string GetString(string key)
|
||||||
{
|
{
|
||||||
if (table == TableName.None || string.IsNullOrEmpty(key))
|
if (!_isInitialized)
|
||||||
return $"[Invalid:{table}/{key}]";
|
{
|
||||||
|
Debug.LogWarning("[LocalizationManager] 호출 전에 초기화되지 않았습니다.");
|
||||||
|
return $"[Uninitialized:{key}]";
|
||||||
|
}
|
||||||
|
|
||||||
var locale = LocalizationSettings.SelectedLocale;
|
if (_localizedCache.TryGetValue(key, out var value)) return value;
|
||||||
var tableName = table.ToString();
|
|
||||||
|
|
||||||
var stringTable = LocalizationSettings.StringDatabase.GetTable(tableName, locale);
|
Debug.LogError("[LocalizationManager] key값이 존재하지 않습니다.");
|
||||||
if (stringTable == null)
|
return null;
|
||||||
return $"[Missing Table:{tableName}]";
|
|
||||||
|
|
||||||
var entry = stringTable.GetEntry(key);
|
|
||||||
if (entry == null)
|
|
||||||
return $"[Missing Key:{key}]";
|
|
||||||
|
|
||||||
return entry.GetLocalizedString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,12 +90,13 @@ public static string GetCurrentLocaleCode()
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 로케일 코드로 현재 언어를 설정합니다. (예: "ko", "en", "ja")
|
/// 로케일 코드로 현재 언어를 설정합니다. (예: "ko", "en", "ja")
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SetLocale(string code)
|
public void SetLocale(string code)
|
||||||
{
|
{
|
||||||
var locale = LocalizationSettings.AvailableLocales.Locales
|
var locale = LocalizationSettings.AvailableLocales.Locales.FirstOrDefault(l => l.Identifier.Code == code);
|
||||||
.FirstOrDefault(l => l.Identifier.Code == code);
|
|
||||||
if (locale != null)
|
if (locale != null)
|
||||||
|
{
|
||||||
LocalizationSettings.SelectedLocale = locale;
|
LocalizationSettings.SelectedLocale = locale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,7 +53,7 @@ private void TryDisplayNext()
|
|||||||
var evt = _messageQueue.Dequeue();
|
var evt = _messageQueue.Dequeue();
|
||||||
_isDisplayingMessage = true;
|
_isDisplayingMessage = true;
|
||||||
|
|
||||||
_messageText.text = LocalizationManager.GetString(TableName.Global_Message, evt.NewMessageKey);
|
_messageText.text = LocalizationManager.Instance.GetString(evt.NewMessageKey);
|
||||||
Open();
|
Open();
|
||||||
|
|
||||||
_fadeTween?.Kill();
|
_fadeTween?.Kill();
|
||||||
|
Loading…
Reference in New Issue
Block a user