feat:1、添加项目
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using BallKingdomCrush;
|
||||
using UnityEngine;
|
||||
using System.Globalization;
|
||||
|
||||
public static class Language
|
||||
{
|
||||
private static Dictionary<string, Dictionary<string, string>> _localizedText;
|
||||
private static string _currentLanguage;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
|
||||
var systemLanguage = Application.systemLanguage;
|
||||
|
||||
Debug.Log($"barry Initialize systemLanguage = {systemLanguage}");
|
||||
|
||||
var lang = "en";
|
||||
if (DataMgr.selectLanguage.Value != -1)
|
||||
{
|
||||
lang = getISOCode((SystemLanguage)DataMgr.selectLanguage.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (systemLanguage == SystemLanguage.English)
|
||||
{
|
||||
lang = "en";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.French)
|
||||
{
|
||||
lang = "fr";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.German)
|
||||
{
|
||||
lang = "de";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.Spanish)
|
||||
{
|
||||
lang = "es";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.Portuguese)
|
||||
{
|
||||
lang = "pt";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.Japanese)
|
||||
{
|
||||
lang = "ja";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.Korean)
|
||||
{
|
||||
lang = "ko";
|
||||
}
|
||||
else if (systemLanguage == SystemLanguage.Russian)
|
||||
{
|
||||
lang = "ru";
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentLanguage(lang);
|
||||
}
|
||||
|
||||
public static void setCurrentLanguage(string lang)
|
||||
{
|
||||
_currentLanguage = lang;
|
||||
PlayerPrefsKit.WriteString("LangIdKey", lang);
|
||||
}
|
||||
|
||||
public static string getCurrentLanguage()
|
||||
{
|
||||
return _currentLanguage;
|
||||
}
|
||||
|
||||
public static void LoadLocalizedText()
|
||||
{
|
||||
if (_localizedText == null)
|
||||
{
|
||||
_localizedText = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
|
||||
var localization = LoadKit.Instance.LoadAsset<TextAsset>("TextAsset", "localization");
|
||||
string json = localization.text;
|
||||
_localizedText = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
|
||||
}
|
||||
|
||||
public static string GetContent(string key)
|
||||
{
|
||||
if (_localizedText == null || !_localizedText.ContainsKey(_currentLanguage) || !_localizedText[_currentLanguage].ContainsKey(key))
|
||||
{
|
||||
return key; // 如果找不到对应的键,返回键本身
|
||||
}
|
||||
|
||||
return _localizedText[_currentLanguage][key];
|
||||
}
|
||||
|
||||
public static string GetContentParams(string key, params object[] args)
|
||||
{
|
||||
if (_localizedText == null || !_localizedText.ContainsKey(_currentLanguage) || !_localizedText[_currentLanguage].ContainsKey(key))
|
||||
{
|
||||
return key; // 如果找不到对应的键,返回键本身
|
||||
}
|
||||
|
||||
string localizedString = _localizedText[_currentLanguage][key];
|
||||
return string.Format(localizedString, args);
|
||||
}
|
||||
|
||||
public static string getISOCode(SystemLanguage code)
|
||||
{
|
||||
if (code == SystemLanguage.English)
|
||||
{
|
||||
return "en";
|
||||
}
|
||||
else if (code == SystemLanguage.French)
|
||||
{
|
||||
return "fr";
|
||||
}
|
||||
else if (code == SystemLanguage.German)
|
||||
{
|
||||
return "de";
|
||||
}
|
||||
else if (code == SystemLanguage.Spanish)
|
||||
{
|
||||
return "es";
|
||||
}
|
||||
else if (code == SystemLanguage.Portuguese)
|
||||
{
|
||||
return "pt";
|
||||
}
|
||||
else if (code == SystemLanguage.Japanese)
|
||||
{
|
||||
return "ja";
|
||||
}
|
||||
else if (code == SystemLanguage.Korean)
|
||||
{
|
||||
return "ko";
|
||||
}
|
||||
else if (code == SystemLanguage.Russian)
|
||||
{
|
||||
return "ru";
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user