/// <summary> /// 解析字典。 /// </summary> /// <param name="dictionaryData">要解析的字典数据。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析字典成功。</returns> public override bool ParseData(ILocalizationManager localizationManager, string dictionaryString, object userData) { try { string currentLanguage = GameEntry.Localization.Language.ToString(); List <LocalizationSerializableObject> localizationSerializableObjects = JsonMapper.ToObject <List <LocalizationSerializableObject> >(dictionaryString); foreach (var localizationSerializableObject in localizationSerializableObjects) { if (localizationSerializableObject.language != currentLanguage) { continue; } foreach (var item in localizationSerializableObject.dic) { if (!localizationManager.AddRawString(item.Key, item.Value)) { Log.Warning("Can not add raw string with key '{0}' which may be invalid or duplicate.", item.Key); return(false); } } } return(true); } catch (Exception exception) { Log.Warning("Can not parse dictionary data with exception '{0}'.", exception.ToString()); return(false); } }
/// <summary> /// 解析字典。 /// </summary> /// <param name="localizationManager">本地化管理器。</param> /// <param name="dictionaryBytes">要解析的字典二进制流。</param> /// <param name="startIndex">字典二进制流的起始位置。</param> /// <param name="length">字典二进制流的长度。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析字典成功。</returns> public override bool ParseData(ILocalizationManager localizationManager, byte[] dictionaryBytes, int startIndex, int length, object userData) { try { using (MemoryStream memoryStream = new MemoryStream(dictionaryBytes, startIndex, length, false)) { using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8)) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { string dictionaryKey = binaryReader.ReadString(); string dictionaryValue = binaryReader.ReadString(); if (!localizationManager.AddRawString(dictionaryKey, dictionaryValue)) { Log.Warning("Can not add raw string with dictionary key '{0}' which may be invalid or duplicate.", dictionaryKey); return(false); } } } } return(true); } catch (Exception exception) { Log.Warning("Can not parse dictionary bytes with exception '{0}'.", exception.ToString()); return(false); } }
/// <summary> /// 解析字典。 /// </summary> /// <param name="dictionaryString">要解析的字典字符串。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析字典成功。</returns> public override bool ParseData(ILocalizationManager localizationManager, string dictionaryString, object userData) { try { string currentLanguage = GameEntry.Localization.Language.ToString(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(dictionaryString); XmlNode xmlRoot = xmlDocument.SelectSingleNode("Dictionaries"); XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes; for (int i = 0; i < xmlNodeDictionaryList.Count; i++) { XmlNode xmlNodeDictionary = xmlNodeDictionaryList.Item(i); if (xmlNodeDictionary.Name != "Dictionary") { continue; } string language = xmlNodeDictionary.Attributes.GetNamedItem("Language").Value; if (language != currentLanguage) { continue; } XmlNodeList xmlNodeStringList = xmlNodeDictionary.ChildNodes; for (int j = 0; j < xmlNodeStringList.Count; j++) { XmlNode xmlNodeString = xmlNodeStringList.Item(j); if (xmlNodeString.Name != "String") { continue; } string key = xmlNodeString.Attributes.GetNamedItem("Key").Value; string value = xmlNodeString.Attributes.GetNamedItem("Value").Value; if (!localizationManager.AddRawString(key, value)) { Log.Warning("Can not add raw string with key '{0}' which may be invalid or duplicate.", key); return(false); } } } return(true); } catch (Exception exception) { Log.Warning("Can not parse dictionary data with exception '{0}'.", exception.ToString()); return(false); } }
/// <summary> /// 解析字典。 /// </summary> /// <param name="localizationManager">本地化管理器。</param> /// <param name="dictionaryString">要解析的字典字符串。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否解析字典成功。</returns> public override bool ParseData(ILocalizationManager localizationManager, string dictionaryString, object userData) { try { int position = 0; string dictionaryLineString = null; while ((dictionaryLineString = dictionaryString.ReadLine(ref position)) != null) { if (dictionaryLineString[0] == '#') { continue; } string[] splitedLine = dictionaryLineString.Split(ColumnSplitSeparator, StringSplitOptions.None); if (splitedLine.Length != ColumnCount) { Log.Warning("Can not parse dictionary line string '{0}' which column count is invalid.", dictionaryLineString); return(false); } string dictionaryKey = splitedLine[1]; string dictionaryValue = splitedLine[3]; if (!localizationManager.AddRawString(dictionaryKey, dictionaryValue)) { Log.Warning("Can not add raw string with dictionary key '{0}' which may be invalid or duplicate.", dictionaryKey); return(false); } } return(true); } catch (Exception exception) { Log.Warning("Can not parse dictionary string with exception '{0}'.", exception.ToString()); return(false); } }
/// <summary> /// 增加字典。 /// </summary> /// <param name="key">字典主键。</param> /// <param name="value">字典内容。</param> /// <returns>是否增加字典成功。</returns> protected bool AddRawString(string key, string value) { return(m_LocalizationManager.AddRawString(key, value)); }
/// <summary> /// 增加字典。 /// </summary> /// <param name="dictionaryKey">字典主键。</param> /// <param name="dictionaryValue">字典内容。</param> /// <returns>是否增加字典成功。</returns> protected bool AddRawString(string dictionaryKey, string dictionaryValue) { return(m_LocalizationManager.AddRawString(dictionaryKey, dictionaryValue)); }