Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定语言的内容
        /// </summary>
        /// <param name="serverType">服务类型</param>
        /// <param name="itemId">单元ID</param>
        /// <param name="targetLang">目标语言</param>
        /// <returns>返回目标语言指定的内容</returns>
        public string GetLangWords(string serverType, string itemId, string targetLang)
        {
            if (_serverLangList != null && itemId != "")
            {
                if (serverType != "")
                {
                    if (_serverLangList.Contains(serverType))
                    {
                        Hashtable serverItemList = _serverLangList[serverType] as Hashtable;
                        if (serverItemList.Contains(itemId))
                        {
                            LanguageItem langItem = serverItemList[itemId] as LanguageItem;
                            return(langItem.GetMessage(targetLang, _defaultLang));
                        }
                    }

                    if (_serverLangList.Contains(_generalServerType))
                    {
                        Hashtable serverItemList = _serverLangList[_generalServerType] as Hashtable;
                        if (serverItemList.Contains(itemId))
                        {
                            LanguageItem langItem = serverItemList[itemId] as LanguageItem;
                            return(langItem.GetMessage(targetLang, _defaultLang));
                        }
                    }
                }
                else
                {
                    foreach (Hashtable serverItemList in _serverLangList.Values)
                    {
                        if (serverItemList.Contains(itemId))
                        {
                            LanguageItem langItem = serverItemList[itemId] as LanguageItem;
                            return(langItem.GetMessage(targetLang, _defaultLang));
                        }
                    }
                }
            }

            return("Error:" + itemId);
        }
Ejemplo n.º 2
0
        //添加到列表,返回itemId
        public string SetLangWords(string serverType, string itemId, string targetLang, string langWords)
        {
            if (serverType == "")
            {
                if (itemId == "")
                {
                    bool bFound = false;
                    foreach (string serverTypeKey in _serverLangList.Keys)
                    {
                        Hashtable itemList1 = _serverLangList[serverTypeKey] as Hashtable;
                        foreach (string itemId1 in itemList1.Keys)
                        {
                            LanguageItem langItem1 = itemList1[itemId1] as LanguageItem;
                            if (targetLang != "")
                            {
                                if (langItem1.GetMessage(targetLang, "") == langWords)
                                {
                                    serverType = serverTypeKey;
                                    itemId     = itemId1;
                                    bFound     = true;
                                    break;
                                }
                            }
                            else
                            {
                                targetLang = langItem1.GetMessageLang(langWords);
                                if (targetLang != "")
                                {
                                    serverType = serverTypeKey;
                                    itemId     = itemId1;
                                    bFound     = true;
                                    break;
                                }
                            }
                        }
                        if (bFound)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    foreach (string serverTypeKey in _serverLangList.Keys)
                    {
                        Hashtable itemList1 = _serverLangList[serverTypeKey] as Hashtable;
                        if (itemList1.Contains(itemId))
                        {
                            LanguageItem langItem1 = itemList1[itemId] as LanguageItem;
                            serverType = serverTypeKey;
                            if (targetLang == "")
                            {
                                targetLang = langItem1.GetMessageLang(langWords);
                            }
                            break;
                        }
                    }
                }

                if (serverType == "")
                {
                    serverType = _generalServerType;
                }
            }

            if (targetLang == "")
            {
                targetLang = _defaultLang;
            }

            Hashtable itemList;

            if (_serverLangList.Contains(serverType))
            {
                itemList = _serverLangList[serverType] as Hashtable;
            }
            else
            {
                itemList = new Hashtable();
                _serverLangList.Add(serverType, itemList);
            }

            LanguageItem langItem;

            if (itemId != "")
            {
                if (itemList.Contains(itemId))
                {
                    langItem = itemList[itemId] as LanguageItem;
                }
                else
                {
                    langItem = new LanguageItem();
                    itemList.Add(itemId, langItem);
                }
            }
            else
            {
                int maxItemId = 0;
                foreach (Hashtable itemList2 in _serverLangList.Values)
                {
                    foreach (string itemId2 in itemList2.Keys)
                    {
                        int itemId3 = 0;
                        try
                        {
                            itemId3 = Convert.ToInt32(itemId2);
                        }
                        catch
                        {
                        }
                        if (itemId3 > maxItemId)
                        {
                            maxItemId = itemId3;
                        }
                    }
                }
                itemId = (maxItemId + 1).ToString();

                langItem = new LanguageItem();
                itemList.Add(itemId, langItem);
            }

            langItem.AddMessage(targetLang, langWords);
            return(itemId);
        }