Files
Fishing2/Assets/Scripts/NBC/Language/Runtime/LanguageConcrete/LanguageText.cs

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 = Lan.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.TryGetValue(language, out var language1))
{
_currentLanguageDictionary = language1;
return true;
}
Debug.LogError("语言包不存在");
return false;
}
}
}