|
@@ -19,10 +19,11 @@ public class Language
|
|
|
Public
|
|
|
}
|
|
|
|
|
|
+ private static bool Inited;
|
|
|
+
|
|
|
public static string[] availableArr = new string[]{Enabled.ChineseSimplified.ToString(), Enabled.English.ToString(), Enabled.ChineseTraditional.ToString() };
|
|
|
|
|
|
private static SystemLanguage defaultLan = SystemLanguage.English;
|
|
|
- public static XmlDocument xml;
|
|
|
|
|
|
public static string lan = SystemLanguage.English.ToString();
|
|
|
public static string lanForUI = SystemLanguage.English.ToString();
|
|
@@ -43,30 +44,50 @@ public class Language
|
|
|
}
|
|
|
public static Dictionary<CurrentLanguage, TextAsset> languageDic;
|
|
|
|
|
|
- public static Dictionary<CurrentLanguage, XmlDocument> XmlDocumentDictionary
|
|
|
+ public static Dictionary<CurrentLanguage, List<XmlDocument>> XmlDocumentDictionary
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (xmlDocumentDictionary == null)
|
|
|
{
|
|
|
- xmlDocumentDictionary = new Dictionary<CurrentLanguage, XmlDocument>();
|
|
|
- XmlDocument xmlDocument = new XmlDocument();
|
|
|
- xmlDocument.LoadXml(LanguageDic[CurrentLanguage.English].text);
|
|
|
- xmlDocumentDictionary.Add(CurrentLanguage.English, xmlDocument);
|
|
|
- xmlDocument = new XmlDocument();
|
|
|
- xmlDocument.LoadXml(LanguageDic[CurrentLanguage.ChineseSimplified].text);
|
|
|
- xmlDocumentDictionary.Add(CurrentLanguage.ChineseSimplified, xmlDocument);
|
|
|
- xmlDocument = new XmlDocument();
|
|
|
- xmlDocument.LoadXml(LanguageDic[CurrentLanguage.ChineseTraditional].text);
|
|
|
- xmlDocumentDictionary.Add(CurrentLanguage.ChineseTraditional, xmlDocument);
|
|
|
+ InitLanguageDocument();
|
|
|
}
|
|
|
return xmlDocumentDictionary;
|
|
|
}
|
|
|
}
|
|
|
- public static Dictionary<CurrentLanguage, XmlDocument> xmlDocumentDictionary;
|
|
|
+ public static Dictionary<CurrentLanguage, List<XmlDocument>> xmlDocumentDictionary;
|
|
|
+
|
|
|
+ public static void InitLanguageDocument()
|
|
|
+ {
|
|
|
+ xmlDocumentDictionary = new Dictionary<CurrentLanguage, List<XmlDocument>>();
|
|
|
+ XmlDocument xmlDocument = new XmlDocument();
|
|
|
+ xmlDocument.LoadXml(LanguageDic[CurrentLanguage.English].text);
|
|
|
+ xmlDocumentDictionary.Add(CurrentLanguage.English, new List<XmlDocument> { xmlDocument });
|
|
|
+ xmlDocument = new XmlDocument();
|
|
|
+ xmlDocument.LoadXml(LanguageDic[CurrentLanguage.ChineseSimplified].text);
|
|
|
+ xmlDocumentDictionary.Add(CurrentLanguage.ChineseSimplified, new List<XmlDocument> { xmlDocument });
|
|
|
+ xmlDocument = new XmlDocument();
|
|
|
+ xmlDocument.LoadXml(LanguageDic[CurrentLanguage.ChineseTraditional].text);
|
|
|
+ xmlDocumentDictionary.Add(CurrentLanguage.ChineseTraditional, new List<XmlDocument> { xmlDocument });
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void AddLanguageDocument(CurrentLanguage language, XmlDocument document)
|
|
|
+ {
|
|
|
+ if (xmlDocumentDictionary == null)
|
|
|
+ {
|
|
|
+ InitLanguageDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ XmlDocumentDictionary[language].Add(document);
|
|
|
+ }
|
|
|
|
|
|
public static void Initialize()
|
|
|
{
|
|
|
+ if (Inited)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Inited = true;
|
|
|
LanguageManager.CurrentLanguage = ConfigManager.GetStringFormConfig("Language").ToEnum<CurrentLanguage>();
|
|
|
if (Initializer.Instance.AuditEdition)
|
|
|
{
|
|
@@ -89,8 +110,6 @@ public class Language
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- xml = XmlDocumentDictionary[LanguageManager.CurrentLanguage];
|
|
|
-
|
|
|
if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
|
|
|
{
|
|
|
ResourceManager.Get<Button>(CanvasLabel.L_TraChi).interactable = true;
|
|
@@ -127,10 +146,10 @@ public class Language
|
|
|
{
|
|
|
LanguageManager.CurrentLanguage = currentLanguage;
|
|
|
|
|
|
- TextAsset textAsset = LanguageDic[currentLanguage];
|
|
|
+ //TextAsset textAsset = LanguageDic[currentLanguage];
|
|
|
|
|
|
- xml = new XmlDocument();
|
|
|
- xml.LoadXml(textAsset.text);
|
|
|
+ //xmls = new XmlDocument();
|
|
|
+ //xmls.LoadXml(textAsset.text);
|
|
|
}
|
|
|
|
|
|
//public static void Init(string lan)
|
|
@@ -153,17 +172,17 @@ public class Language
|
|
|
// xml.LoadXml(text);
|
|
|
//}
|
|
|
|
|
|
- public static bool initialized
|
|
|
- {
|
|
|
- get{
|
|
|
- return xml != null;
|
|
|
- }
|
|
|
- }
|
|
|
+ // public static bool initialized
|
|
|
+ //{
|
|
|
+ // get{
|
|
|
+ // return xmls != null;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
public static void LoadFromResource()
|
|
|
{
|
|
|
//TextAsset textasset = ResourcesManager.Instance.LoadConfig("xml/lan", lan);
|
|
|
- xml = new XmlDocument ();
|
|
|
+ //xmls = new XmlDocument ();
|
|
|
//xml.LoadXml (textasset.text);
|
|
|
}
|
|
|
|
|
@@ -245,43 +264,26 @@ public class Language
|
|
|
}
|
|
|
|
|
|
public static string GetStr(string page, string id)
|
|
|
- {
|
|
|
- if(xml == null)
|
|
|
- {
|
|
|
- Initialize();
|
|
|
- }
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- XmlNode pageNode = xml.SelectSingleNode("lan/"+page);
|
|
|
- XmlNode node = pageNode.SelectSingleNode(id);
|
|
|
- if(node != null)
|
|
|
- return node.InnerText.Replace("\\n", "\n");
|
|
|
- }
|
|
|
- catch(Exception e)
|
|
|
- {
|
|
|
- Debug.LogException(e);
|
|
|
- }
|
|
|
-
|
|
|
- string error = "Topic missing page["+page+"] id["+id+"]";
|
|
|
- Debug.LogError(error);
|
|
|
- return error;
|
|
|
- }
|
|
|
+ {
|
|
|
+ return GetStr(page, id, LanguageManager.CurrentLanguage);
|
|
|
+ }
|
|
|
|
|
|
public static string GetStr(string page, string id, CurrentLanguage language)
|
|
|
{
|
|
|
- XmlDocument xmlDocument = XmlDocumentDictionary[language];
|
|
|
+ List<XmlDocument> documents = XmlDocumentDictionary[language];
|
|
|
|
|
|
- try
|
|
|
+ foreach (var document in documents)
|
|
|
{
|
|
|
- XmlNode pageNode = xmlDocument.SelectSingleNode("lan/" + page);
|
|
|
+ XmlNode pageNode = document.SelectSingleNode("lan/" + page);
|
|
|
+ if (pageNode == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
XmlNode node = pageNode.SelectSingleNode(id);
|
|
|
if (node != null)
|
|
|
+ {
|
|
|
return node.InnerText.Replace("\\n", "\n");
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Debug.LogException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
string error = "Topic missing page[" + page + "] id[" + id + "]";
|
|
@@ -336,21 +338,21 @@ public class Language
|
|
|
private static Font defaultFont;
|
|
|
public static Font font;
|
|
|
|
|
|
- public static Font GetFont()
|
|
|
- {
|
|
|
- if (xml == null || font == null)
|
|
|
- {
|
|
|
- if(defaultFont == null)
|
|
|
- {
|
|
|
- Debug.LogError("Language not init");
|
|
|
- defaultFont = Font.CreateDynamicFontFromOSFont("Arial", 20);
|
|
|
- }
|
|
|
- return defaultFont;
|
|
|
- }
|
|
|
- return font;
|
|
|
- //return "Fonts/" + SystemLanguage.ChineseTraditional.ToString();
|
|
|
- //return "Fonts/" + SystemLanguage.Chinese.ToString();
|
|
|
- }
|
|
|
+ // public static Font GetFont()
|
|
|
+ // {
|
|
|
+ //if (xmls == null || font == null)
|
|
|
+ // {
|
|
|
+ // if(defaultFont == null)
|
|
|
+ // {
|
|
|
+ // Debug.LogError("Language not init");
|
|
|
+ // defaultFont = Font.CreateDynamicFontFromOSFont("Arial", 20);
|
|
|
+ // }
|
|
|
+ // return defaultFont;
|
|
|
+ // }
|
|
|
+ //return font;
|
|
|
+ // //return "Fonts/" + SystemLanguage.ChineseTraditional.ToString();
|
|
|
+ // //return "Fonts/" + SystemLanguage.Chinese.ToString();
|
|
|
+ // }
|
|
|
|
|
|
public static Font GetFont(Enabled font)
|
|
|
{
|
|
@@ -402,10 +404,10 @@ public class Language
|
|
|
return isIn;
|
|
|
}
|
|
|
|
|
|
- public static bool IsLanguageInit()
|
|
|
- {
|
|
|
- return (xml == null) ? false : true;
|
|
|
- }
|
|
|
+ //public static bool IsLanguageInit()
|
|
|
+ //{
|
|
|
+ // return (xmls == null) ? false : true;
|
|
|
+ //}
|
|
|
|
|
|
public static string GetLanguagePath()
|
|
|
{
|