123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Xml;
- public class Language
- {
-
- private static Dictionary<string, string> lanDict = new Dictionary<string, string>();
- private static SystemLanguage currentLan;
- private static bool initialized;
-
- public static void Init (SystemLanguage lan)
- {
- Debuger.Log("Init Language "+lan.ToString());
- initialized = true;
- currentLan = lan;
- TextAsset textAsset = (TextAsset)Resources.Load("XML/Config/All/word_config");
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(textAsset.text);
- lanDict.Clear ();
- XmlNode mapNode = xml.SelectSingleNode("data");
- XmlNodeList nodeList = mapNode.SelectNodes("item");
- for(int i=0; i<nodeList.Count; i++)
- {
- XmlElement el = nodeList [i] as XmlElement;
- string title = el.GetAttribute ("title");
- string label = el.GetAttribute ("label");
- string word = el.GetAttribute (lan.ToString());
- string key = title + "_" + label;
- if (lanDict.ContainsKey (key))
- Debuger.LogError ("Language duplicate "+key);
- else
- lanDict.Add (key, word);
- }
- }
- private static SystemLanguage GetSystemLanguage()
- {
- // return SystemLanguage.Chinese;
- // return SystemLanguage.English;
- if(Application.systemLanguage == SystemLanguage.Chinese || Application.systemLanguage == SystemLanguage.ChineseSimplified)
- return SystemLanguage.Chinese;
- return SystemLanguage.English;
- }
- public static SystemLanguage GetCurrentLanguage()
- {
- if(!initialized)
- Init (GetSystemLanguage());
- return currentLan;
- }
-
- public static string GetStr(string page, string id)
- {
- if (!initialized)
- Init (GetSystemLanguage ());
- string key = page + "_" + id;
- if (lanDict.ContainsKey (key)) {
- string str = lanDict [key];
- str = str.Replace ("\\n", "\n");
- return str;
- }
- string error = "Topic missing page["+page+"] id["+id+"]";
- Debuger.LogError(error);
- return error;
- }
- }
|