Exemplo n.º 1
0
        /// <summary>
        /// 将File内容读进来并存储
        /// </summary>
        /// <param name="_fileInfo"></param>
        private void ReadCSVFile(FileInfo _fileInfo)
        {
            string file, strViewFilter, strKey, strValue;

            file = _fileInfo.Name.Split('.')[0];
            if (!LocalizeDataTable.ContainsKey(file))
            {
                LocalizeDataTable.Add(file, new Dictionary <string, Dictionary <string, string> >());
            }

            ScpReader tmpCSVDocument = new ScpReader(_fileInfo.FullName, true, 2);

            string tmpCurrentView = string.Empty;

            for (int i = 0; i < tmpCSVDocument.GetRecordCount(); ++i)
            {
                //读"界面名"
                strViewFilter = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_View, i == 0?string.Empty: tmpCurrentView);
                if (i == 0 && strViewFilter == string.Empty)
                {
                    Trace.LogError("配置表 " + file + " 出错!!第一个ViewFilter不能是空的。");
                    break;
                }
                else if (strViewFilter == string.Empty)//表当前位置与上一个位置的ViewFilter一致
                {
                    strViewFilter = tmpCurrentView;
                }
                else if (strViewFilter != tmpCurrentView)//表当前位置属于另一个ViewFilter
                {
                    tmpCurrentView = strViewFilter;
                }
                //读"关键字"
                strKey = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_Key, string.Empty);
                if (strKey == string.Empty)
                {
                    Trace.LogError("配置表:" + file + ",在界面:" + strViewFilter + " 有个关键字是空的,这是不允许的出错。");
                    break;
                }
                //读"显示内容"
                strValue = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_Value, string.Empty);
                if (strValue == string.Empty)
                {
                    Trace.LogWarning("配置表:" + file + ",在界面:" + strViewFilter + ",有个值:" + strKey + " 显示的内容是空的,虽然这是允许,但请注意下。");
                }
                if (!LocalizeDataTable[file].ContainsKey(strViewFilter))
                {
                    LocalizeDataTable[file].Add(strViewFilter, new Dictionary <string, string>());
                }
                if (LocalizeDataTable[file][strViewFilter].ContainsKey(strKey))
                {
                    Trace.LogError("配置表: " + file + ",在界面:" + strViewFilter + ",有个值:" + strKey + " 是重复的,这是不允许的,请修改。");
                }
                else
                {
                    LocalizeDataTable[file][strViewFilter].Add(strKey, strValue);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取指定的本地化数据
 /// </summary>
 /// <param name="_strFile">数据所存在的文件</param>
 /// <param name="_strFilter">数据所存在的组</param>
 /// <param name="_strKey">数据的Key</param>
 /// <param name="_strFallback">没找到指定数据时返回的值</param>
 /// <returns>本地化数据</returns>
 public string Get(string _strFile, string _strViewFilter, string _strKey, string _strFallback)
 {
     if (LocalizeDataTable == null)
     {
         Trace.LogWarning("是否没加载本地化数据表?");
         return(_strFallback);
     }
     if (!LocalizeDataTable.ContainsKey(_strFile))
     {
         //ReadCSVFile(_strFile);
         ReadCSVMPKFile(_strFile);
     }
     if (!LocalizeDataTable[_strFile].ContainsKey(_strViewFilter) ||
         !LocalizeDataTable[_strFile][_strViewFilter].ContainsKey(_strKey))
     {
         Debug.LogWarning("没找到用于本地化的数据:" + _strFile + "->" + _strViewFilter + "->" + _strKey);
         return(_strFallback);
     }
     return(LocalizeDataTable[_strFile][_strViewFilter][_strKey]);
 }
Exemplo n.º 3
0
        private void ReadCSVMPKFile(string _strFileName)
        {
            string strFilePath, strViewFilter, strKey, strValue;

            //file = _fileInfo.Name.Split('.')[0];
            string strFormatEditor  = "{0}{1}/UI/{2}.csv";
            string strFormatRunning = "{0}{1}\\UI\\{2}.csv";
            string strConfigPath    = Initialize.Instance != null ? ViewConfigManager.DataScpPath : ViewConfigManager.Editor_DataScpPath;

            strFilePath = string.Format(Initialize.Instance != null ? strFormatRunning : strFormatEditor, strConfigPath, Language.Name, _strFileName);//ViewConfigManager.DataScpPath + Language.Name + "\\UI\\" + _strFileName+".csv";//

            if (!LocalizeDataTable.ContainsKey(_strFileName))
            {
                LocalizeDataTable.Add(_strFileName, new Dictionary <string, Dictionary <string, string> >());
            }

            ScpReader tmpCSVDocument = new ScpReader(strFilePath, true, 2);

            string tmpCurrentView = string.Empty;

            for (int i = 0; i < tmpCSVDocument.GetRecordCount(); ++i)
            {
                //读"界面名"
                strViewFilter = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_View, i == 0 ? string.Empty : tmpCurrentView);
                if (i == 0 && strViewFilter == string.Empty)
                {
                    Trace.LogError("配置表 " + _strFileName + " 出错!!第一个ViewFilter不能是空的。");
                    break;
                }
                else if (strViewFilter == string.Empty)//表当前位置与上一个位置的ViewFilter一致
                {
                    strViewFilter = tmpCurrentView;
                }
                else if (strViewFilter != tmpCurrentView)//表当前位置属于另一个ViewFilter
                {
                    tmpCurrentView = strViewFilter;
                }
                //读"关键字"
                strKey = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_Key, string.Empty);
                if (strKey == string.Empty)
                {
                    Trace.LogError("配置表:" + _strFileName + ",在界面:" + strViewFilter + " 有个关键字是空的,这是不允许的出错。");
                    break;
                }
                //读"显示内容"
                strValue = tmpCSVDocument.GetString(i, (int)ELocalizationFile.ELF_Value, string.Empty);
                if (strValue == string.Empty)
                {
                    Trace.LogWarning("配置表:" + _strFileName + ",在界面:" + strViewFilter + ",有个值:" + strKey + " 显示的内容是空的,虽然这是允许,但请注意下。");
                }
                if (!LocalizeDataTable[_strFileName].ContainsKey(strViewFilter))
                {
                    LocalizeDataTable[_strFileName].Add(strViewFilter, new Dictionary <string, string>());
                }
                if (LocalizeDataTable[_strFileName][strViewFilter].ContainsKey(strKey))
                {
                    Trace.LogError("配置表: " + _strFileName + ",在界面:" + strViewFilter + ",有个值:" + strKey + " 是重复的,这是不允许的,请修改。");
                }
                else
                {
                    LocalizeDataTable[_strFileName][strViewFilter].Add(strKey, strValue);
                }
            }
        }