示例#1
0
    /// <summary>
    /// 获取字典信息
    /// </summary>
    /// <param name="dictionarie">枚举</param>
    public static List <DictionariesEntity> GetDictionaries(DictionariesEnum dictionarie)
    {
        XmlDocument xmldoc = new XmlDocument();

        xmldoc.Load(path);
        XmlNodeList xnl = xmldoc.SelectSingleNode("Dictionaries").ChildNodes;
        List <DictionariesEntity> list = new List <DictionariesEntity>();

        foreach (XmlNode xn in xnl)
        {
            if (xn.Attributes["name"].Value == dictionarie.ToStr())
            {
                XmlNodeList childList = xn.ChildNodes;
                foreach (XmlNode xn2 in childList)
                {
                    DictionariesEntity entity = new DictionariesEntity();
                    entity.ID     = xn2.Attributes["ID"].Value.ToInt();
                    entity.Title  = xn2.InnerText;
                    entity.Remark = xn2.Attributes["Remark"].Value;
                    list.Add(entity);
                }
            }
        }
        return(list);
    }
示例#2
0
 /// <summary>
 /// Récupère la chaîne ayant pour clé key
 /// </summary>
 /// <param name="dictionary">Dictionnaire dans lequel chercher</param>
 /// <param name="key">Clé du texte a récupérer</param>
 /// <returns>Renvoi le texte qui à pour clé key. Renvoi la clé si elle ne correspond à aucun texte</returns>
 private string GetText(DictionariesEnum dictionary, string key)
 {
     if (texts.ContainsKey(dictionary))
     {
         if (texts[dictionary].ContainsKey(key))
         {
             // Rajout de la gestion des clés de lang
             return(GestionCle(texts[dictionary][key], dictionary, key));
         }
         else
         {
             return(dictionary.ToString() + "_" + key);
         }
     }
     else
     {
         return("No dictionary : " + dictionary);
     }
 }
示例#3
0
    /// <summary>
    /// 获取字典信息名称
    /// </summary>
    /// <param name="dictionarie"></param>
    /// <returns></returns>
    public static string GetDictionariesTitle(DictionariesEnum dictionarie, int id)
    {
        XmlDocument xmldoc = new XmlDocument();

        xmldoc.Load(path);
        XmlNodeList xnl   = xmldoc.SelectSingleNode("Dictionaries").ChildNodes;
        string      title = "";

        foreach (XmlNode xn in xnl)
        {
            if (xn.Attributes["name"].Value == dictionarie.ToStr())
            {
                XmlNodeList childList = xn.ChildNodes;
                foreach (XmlNode xn2 in childList)
                {
                    if (xn2.Attributes["ID"].Value.ToInt() == id)
                    {
                        title = xn2.InnerText;
                    }
                }
            }
        }
        return(title);
    }
示例#4
0
            /// <summary>
            /// Parse le texte pour remplacer les clés de lang par leur valeur
            /// </summary>
            /// <param name="texte"></param>
            /// <returns></returns>
            private string GestionCle(string texte, DictionariesEnum dictionary, string key)
            {
                char   c;
                string res = "";
                string tmp, tmpRes = "";

                for (int i = 0; i < texte.Length; i++)
                {
                    c = texte[i];

                    if (c == '{')
                    {
                        tmp = "";
                        while (i + 1 < texte.Length && texte[i + 1] != ':' && texte[i + 1] != '}')
                        {
                            i++;
                            tmp += texte[i];
                        }
                        if (i + 1 >= texte.Length)
                        {
                            Debug.LogError("Erreur de clé dans le lang : " + dictionary.ToString() + ", " + key);
                            break;
                        }

                        i++;
                        if (i + 1 < texte.Length)
                        {
                            if (texte[i + 1] == 'b')
                            {
                                i = i + 4;
                            }
                            else if (texte[i + 1] == 'g')
                            {
                                i = i + 5;
                            }
                            else
                            {
                                Debug.LogError("Erreur de clé (girl ou boy) dans le lang : " + dictionary.ToString() + ", " + key);
                                break;
                            }
                        }
                        else
                        {
                            Debug.LogError("Erreur de clé dans le lang : " + dictionary.ToString() + ", " + key);
                            break;
                        }

                        if (tmpRes == "")
                        {
                            Debug.LogError("Erreur de clé incohérente dans le lang : " + dictionary.ToString() + ", " + key);
                            break;
                        }

                        res += tmpRes;
                        continue;
                    }

                    res += c;
                }

                return(res);
            }
示例#5
0
            /// <summary>
            /// Renvoi le dictionnaire associé au dictionnaire <paramref name="dictionary"/> pour la langue <paramref name="lang"/>.
            /// </summary>
            /// <param name="dictionary">dictionnaire qu'on veut charger</param>
            /// <param name="lang">langue qu'on veut charger</param>
            /// <returns></returns>
            private Dictionary <string, string> LoadTextDictionary(DictionariesEnum dictionary, LanguagesEnum lang)
            {
                TextAsset txtAsset = Resources.Load <TextAsset>("Lang/Texts/" + dictionary.ToString());

                if (txtAsset == null)
                {
                    Debug.LogError("Lang : no file at: Lang/Texts/" + dictionary.ToString());
                    return(null);
                }
                string txtString = txtAsset.text;

                string[] lines = txtString.Split(System.Environment.NewLine.ToCharArray());

                if (lines.Length <= 0)
                {
                    Debug.LogError("Lang : not enough lines in Lang/Texts/" + dictionary.ToString());
                    return(null);
                }

                string[] languages     = lines[0].Split('|');
                int      languageIndex = -1;

                for (int i = 0; i < languages.Length; i++)
                {
                    if (languages[i].Equals(lang.ToString()))
                    {
                        languageIndex = i;
                        break;
                    }
                }
                if (languageIndex < 0)
                {
                    Debug.LogError("Lang : " + lang.ToString() + " not found in Lang/Texts/" + dictionary.ToString());
                    return(null);
                }

                Dictionary <string, string> ret = new Dictionary <string, string>();

                string[] line;
                char[]   tmpCharArray;
                for (int i = 1; i < lines.Length; i++)
                {
                    line = lines[i].Split('|');
                    if (line.Length <= 0 || lines[i] == "")
                    {
                    }
                    else if (line.Length == 1)
                    {
                        Debug.LogError("LangPackage: dictionary " + dictionary + "  line " + i + " found only the key, skipping this line");
                    }
                    else if (!line[0].Equals(""))
                    {
                        tmpCharArray = line[languageIndex].ToCharArray();
                        if (tmpCharArray[0] == '"' && tmpCharArray[tmpCharArray.Length - 1] == '"')
                        {
                            line[languageIndex] = line[languageIndex].Substring(1, line[languageIndex].Length - 2);
                        }
                        line[languageIndex] = line[languageIndex].Replace("\"\"", "\"");
                        line[languageIndex] = line[languageIndex].Replace("\\n", "\n");
                        line[languageIndex] = line[languageIndex].Replace("{$pipe}", "|");
                        ret.Add(line[0], line[languageIndex]);
                    }
                }
                return(ret);
            }
示例#6
0
 /// <summary>
 /// Renvoi Instance.GetText(key)
 /// </summary>
 /// <param name="dictionary">Dictionnaire dans lequel chercher</param>
 /// <param name="key">Variable à passer à Instance.GetText</param>
 /// <returns>Instance.GetText(key)</returns>
 public static string Get(DictionariesEnum dictionary, string key)
 {
     return(Instance.GetText(dictionary, key));
 }