54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace NBC
|
|
{
|
|
public class LanguageText : ILanguage
|
|
{
|
|
/// <summary>
|
|
/// 多语言配置数据
|
|
/// </summary>
|
|
private readonly Dictionary<SystemLanguage, Dictionary<string, string>> _languages =
|
|
new Dictionary<SystemLanguage, Dictionary<string, string>>();
|
|
|
|
/// <summary>
|
|
/// 当前语言包键值对
|
|
/// </summary>
|
|
private Dictionary<string, string> _currentLanguageDictionary = new Dictionary<string, string>();
|
|
|
|
public string Get(string key)
|
|
{
|
|
if (_currentLanguageDictionary != null && _currentLanguageDictionary.TryGetValue(key, out var value))
|
|
{
|
|
return value;
|
|
}
|
|
|
|
return key;
|
|
}
|
|
|
|
public void AddLanguage(SystemLanguage language)
|
|
{
|
|
// var keys = GameConfig.Inst.GetLanguageConfig(LanguageConst.languageMap[language]);
|
|
// if (keys != null)
|
|
// {
|
|
// _languages[language] = keys;
|
|
// }
|
|
// else
|
|
// {
|
|
// _languages[language] = new Dictionary<string, string>();
|
|
// }
|
|
}
|
|
|
|
public bool UseLanguage(SystemLanguage language)
|
|
{
|
|
if (_languages.ContainsKey(language))
|
|
{
|
|
_currentLanguageDictionary = _languages[language];
|
|
return true;
|
|
}
|
|
|
|
Debug.LogError("语言包不存在");
|
|
return false;
|
|
}
|
|
}
|
|
} |