多语言微调

This commit is contained in:
lishuo committed 2021-11-11 14:20:08 +08:00
1 parent 51834b709c
commit eb9338390c
19 files changed
+2132 -1735

No files matched your search

+8 -1
View File
@@ -44,6 +44,13 @@ namespace Assets.Scripts.Apis
httpClient = new System.Net.Http.HttpClient(httpClientHandler);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HandleHeaders(httpClient.DefaultRequestHeaders);
App.ChangeLanguageEvent += App_ChangeLanguageEvent;
}
//语言切换
private static void App_ChangeLanguageEvent()
{
httpClient.DefaultRequestHeaders.Remove("Language");
httpClient.DefaultRequestHeaders.Add("Language", App.GetLocalLanguage());
}
protected async Task<bool> GetAsFileSync(string url, string fileName)
@@ -478,7 +485,7 @@ namespace Assets.Scripts.Apis
private void AddLanguage()
{
httpClient.DefaultRequestHeaders.Remove("Language");
httpClient.DefaultRequestHeaders.Add("Language", "en");
httpClient.DefaultRequestHeaders.Add("Language", App.GetLocalLanguage());
}
/// <summary>
+56 -1
View File
@@ -12,10 +12,13 @@ using Assets.Scripts;
using System;
using System.Threading.Tasks;
using System.Timers;
using Newtonsoft.Json;
public delegate void ChangeLanguageDelegate();
public static class App
{
public static string Host = "http://192.168.0.101:5085/";
public static string Host = "http://192.168.0.102:5082/";
public static string AppVersion = Application.version;
@@ -100,9 +103,61 @@ public static class App
public static float canvasWidth { get; set; }
public static string WorkoutsUrl { get; internal set; }
public static long delayTime { get; set; }
private static string language { get; set; }
public static Dictionary<string, string> LanguageManager { get; set; }
#region 语言改变事件
public static event ChangeLanguageDelegate ChangeLanguageEvent;
static Dictionary<string, Dictionary<string, string>> dic;
public static string GetLocalLanguage()
{
return language;
}
public static void ChangeLanguage(string lan)
{
language = lan;
if (dic.ContainsKey(language))
{
LanguageManager = dic[language];
}
if (ChangeLanguageEvent != null)
{
ChangeLanguageEvent();
}
}
public static string GetLocalString(string value)
{
if (LanguageManager != null && LanguageManager.ContainsKey(value))
{
return LanguageManager[value];
}
return value;
}
private static void InitLanguage()
{
var systemLanguage = Application.systemLanguage.ToString().ToLower();
if (systemLanguage.Contains("chinese"))
{
language = "zh";
}
else
{
language = "en";
}
var a = Resources.Load<TextAsset>("UI/language");
dic = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(a.text);
if (dic.ContainsKey(language))
{
LanguageManager = dic[language];
}
}
#endregion
static App()
{
InitLanguage();
#if !UNITY_EDITOR
//Host = "http://pf.juze.pro/";
//Host = "http://192.168.0.101:5087/";
+9 -9
View File
@@ -187,9 +187,9 @@ public class LoginController : BaseScene
years.options = regOptions.years;
months.options = regOptions.months;
days.options = regOptions.days;
years.captionText.text = "Year";
months.captionText.text = "Month";
days.captionText.text = "Day";
years.captionText.text = App.GetLocalString("Year");
months.captionText.text = App.GetLocalString("Month");
days.captionText.text = App.GetLocalString("Day");
years.onValueChanged.AddListener((int index) =>
{
if (index != -1 && months.value != -1)
@@ -207,7 +207,7 @@ public class LoginController : BaseScene
}
});
genders.options = regOptions.genders;
genders.captionText.text = "Gender";
genders.captionText.text = App.GetLocalString("Gender");
countrys.options = regOptions.countrys;
countrys.value = regOptions.countryDefaultValue;
countrys.onValueChanged.AddListener((int index) =>
@@ -215,7 +215,7 @@ public class LoginController : BaseScene
countrys.transform.Find("RawImage").GetComponent<RawImage>().texture = regOptions.GetCountryImage(index);
});
units.options = regOptions.units;
units.captionText.text = "Display Units";
units.captionText.text = App.GetLocalString("Display Units");
signForm = new SignForm()
{
email = email,
@@ -765,16 +765,16 @@ public class LoginController : BaseScene
{
var btn = signPage1.Find("Captcha").Find("BtnGet");
var btnText = signPage1.Find("Captcha").Find("BtnGet").Find("Text").GetComponent<Text>();
btnText.text = $"Again({time--})";
btnText.text = $"{App.GetLocalString("Again")}({time--})";
if (time < 0)
{
btnText.text = "Get";
btnText.text = App.GetLocalString("Get");
btn.GetComponent<Button>().enabled = true;
btn.GetComponent<Button>().interactable = true;
startCaptcha = false;
//timer.Stop();
}
timer = 1.0f;
timer += 1.0f;
}
}
@@ -1167,7 +1167,7 @@ public class LoginController : BaseScene
if (type == 0)
{
pageNums = 4;
signContainer.Find("signText").GetComponent<Text>().text = "SIGN UP";
signContainer.Find("signText").GetComponent<Text>().text = App.GetLocalString("SIGN UP");
wxLogin2.gameObject.SetActive(false);
signPage1.Find("next").gameObject.SetActive(true);
signPage1.Find("BtnModiPass").gameObject.SetActive(false);
+1 -1
View File
@@ -66,7 +66,7 @@ namespace Assets.Scripts.UI.Control
isSelected = false;
this.mInnerInputField.OnDeselect(eventData);
transform.Find("Placeholder").GetComponent<Text>().text = placeHolderText;
transform.Find("Placeholder").GetComponent<Text>().text = App.GetLocalString(placeHolderText);
//var image = this.transform.GetComponent<Image>();
//var png1 = Resources.Load<Sprite>("Images/ipt-0");
//image.sprite = png1;
+3
View File
@@ -85,6 +85,9 @@ public class Confirm : PFUIPanel
ok = "Yes";
cancel = "No";
}
ok = App.GetLocalString(ok);
cancel = App.GetLocalString(cancel);
_ok.transform.Find("Text").GetComponent<Text>().text = ok;
_cancel.transform.Find("Text").GetComponent<Text>().text = cancel;
}
@@ -54,13 +54,14 @@ namespace Assets.Scripts.UI.Prefab.Login
{
months.Add(new Dropdown.OptionData(m.ToString()));
}
days = new List<Dropdown.OptionData>();
genders = new List<Dropdown.OptionData>() {new Dropdown.OptionData("Male"), new Dropdown.OptionData("FeMale") };
genders = new List<Dropdown.OptionData>() {new Dropdown.OptionData(App.GetLocalString("Male")), new Dropdown.OptionData(App.GetLocalString("FeMale")) };
var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson);
countrys = countryList.Select(x => new Dropdown.OptionData(x.country)).ToList();
countryDefaultValue = countryList.FindIndex(x => x.country == "中国");
units = new List<Dropdown.OptionData>() { new Dropdown.OptionData("Metric"), new Dropdown.OptionData("Imperial") };
units = new List<Dropdown.OptionData>() { new Dropdown.OptionData(App.GetLocalString("Metric")), new Dropdown.OptionData(App.GetLocalString("Imperial")) };
}
public Texture GetCountryImage(int index)
{
@@ -9,7 +9,7 @@ namespace Assets.Scripts.UI.Prefab.MapList
{
public class MapFilterOptions
{
public static List<Dropdown.OptionData> distances = new string[] {"All",
public static List<Dropdown.OptionData> distances = new string[] {App.GetLocalString("All"),
"0-5KM",
"5-10KM",
"10-20KM",
@@ -20,7 +20,7 @@ namespace Assets.Scripts.UI.Prefab.MapList
"Over 200KM", }.Select(x=>new Dropdown.OptionData(x)).ToList();
public static Dictionary<string, string> distanceDict = new Dictionary<string, string>()
{
{"All","" },
{App.GetLocalString("All"),"" },
{"0-5KM","0-5" },
{"5-10KM","5-10" },
{"10-20KM","10-20" },
@@ -32,7 +32,7 @@ namespace Assets.Scripts.UI.Prefab.MapList
};
public static Dictionary<string,string> diffDict = new Dictionary<string, string>()
{
{"FLAT","0-100" },
{App.GetLocalString("FLAT"),"0-100" },
{"LV.4","100-250" },
{"LV.3","250-350" },
{"LV.2","350-550" },
@@ -40,11 +40,22 @@ namespace Assets.Scripts.UI.Prefab.MapList
{"HC","750-99999" },
};
public static List<Dropdown.OptionData> sorts = new string[] {
"Near", "Trend","Name","Distance","Difficulty","Time"
App.GetLocalString("Near"), App.GetLocalString("Trend"), App.GetLocalString("Name"), App.GetLocalString("Distance"), App.GetLocalString("Difficulty"), App.GetLocalString("Time")
}.Select(x => new Dropdown.OptionData(x)).ToList();
public static Dictionary<string, string> sortsDict = new Dictionary<string, string>()
{
{App.GetLocalString("Near"),"Near" },
{App.GetLocalString("Trend"),"Trend" },
{App.GetLocalString("Name"),"Name" },
{App.GetLocalString("Distance"),"Distance" },
{App.GetLocalString("Difficulty"),"Difficulty" },
{App.GetLocalString("Time"),"Time" },
};
public static Dictionary<string, string> diffDisplayDict = new Dictionary<string, string>()
{
{"FLAT","0-100" },
{App.GetLocalString("FLAT"),"0-100" },
{"LV.4","100-250" },
{"LV.3","250-350" },
{"LV.2","350-550" },
@@ -175,7 +175,7 @@ public class EditUserController : PFUIPanel, INativeOnMobileImageSelect
mSexDropdown.ClearOptions();
mSexDropdown.AddOptions(new List<string>
{
"Male","Female"
App.GetLocalString("Male"),App.GetLocalString("Female")
});
mUnitDropdown.ClearOptions();
mUnitDropdown.AddOptions(UIManager.Instance.loginRegOptions.units);
@@ -222,7 +222,9 @@ public class MapListController : PFUIPanel
drop.value = 0;
drop.onValueChanged.AddListener((int index)=>
{
sort = drop.options[index].text;
var text = drop.options[index].text;
sort = MapFilterOptions.sortsDict[text];
if (sort == "Trend")
{
sort = "Hot";
+6 -1
View File
@@ -941,11 +941,16 @@ public class UIManager : MonoBehaviour
Confirm confirm = null;
public static void ShowConfirm(string title, string content, UnityAction action,int type = 2,UnityAction cancel = null)
{
if (UIManager.Instance == null)
{
return;
}
if(UIManager.Instance.confirm == null)
title = App.GetLocalString(title);
content = App.GetLocalString(content);
if (UIManager.Instance.confirm == null)
{
UIManager.Instance.confirm = UIManager.Instance.GetInstance<Confirm>("Confirm", ref UIManager.Instance.confirm);
UIManager.Show(UIManager.Instance.confirm, null, true);