void SelectLanguageGUI() { GUILayout.BeginHorizontal(); currentLanguage = EditorDrawGUIUtil.DrawPopup("当前语言", currentLanguage, config.gameExistLanguages, (lan) => { if (!string.IsNullOrEmpty(selectFullFileName)) { currentFileDataTable = LanguageDataUtils.LoadFileData(lan, selectFullFileName); } Debug.Log("切换到:" + lan); LanguageManager.SetLanguage(lan); }); if (currentLanguage == SystemLanguage.Chinese) { currentLanguage = SystemLanguage.ChineseSimplified; } if (GUILayout.Button("加载上一次保存")) { DataManager.CleanCache(); LanguageManager.IsInit = false; GlobalEvent.DispatchEvent(EditorEvent.LanguageDataEditorChange); currentFileDataTable = LanguageDataUtils.LoadFileData(currentLanguage, selectFullFileName); GUI.FocusControl(""); } if (GUILayout.Button("检查修复多语言完整性")) { CheckAllLanguageFileIntact(); } GUILayout.EndHorizontal(); }
private void Init() { win = this; config= LanguageDataUtils.LoadEditorConfig(); if(config == null) { return; } if (!config.gameExistLanguages.Contains(currentLanguage)) { currentLanguage = config.defaultLanguage; } s_languageFullKeyFileNameList= LanguageDataEditorUtils.LoadLangusgeAllFileNames(currentLanguage); if (!string.IsNullOrEmpty(selectFullFileName)) { currentFileDataTable = LanguageDataUtils.LoadFileData(currentLanguage, selectFullFileName); } if (treeViewState == null) treeViewState = new TreeViewState(); treeView = new FolderTreeView(treeViewState); treeView.SetData(s_languageFullKeyFileNameList); treeView.dblclickItemCallBack = ModuleFileDblclickItemCallBack; treeView.selectCallBack = ModuleFileFolderSelectCallBack; }
private void CreateNewLangusge(SystemLanguage lan) { if (config == null) { config = new LanguageSettingConfig(); } if (config.defaultLanguage == SystemLanguage.Unknown) { config.defaultLanguage = lan; config.gameExistLanguages.Add(lan); currentLanguage = lan; } else { foreach (var item in s_languageFullKeyFileNameList) { DataTable dt = LanguageDataUtils.LoadFileData(config.defaultLanguage, item); Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (var id in dt.TableIDs) { dic.Add(id, ""); } CreateLanguageNewFile(lan, item, dic); } } SaveData(); AssetDatabase.Refresh(); Init(); }
private static DataTable LoadDataTable(SystemLanguage language, string fullFileName) { if (Application.isPlaying) { string name = GetLanguageDataName(language, fullFileName); TextAsset text = ResourceManager.Load <TextAsset>(name); if (text == null) { Debug.LogError("Error: no Language file :" + name); return(null); } if (loadTextFileTimesDic.ContainsKey(name)) { loadTextFileTimesDic[name]++; } else { loadTextFileTimesDic.Add(name, 1); } DataTable data = DataTable.Analysis(text.text); return(data); } else { return(LanguageDataUtils.LoadFileData(language, fullFileName)); } }
/// <summary> /// 检查修复多语言完整性 /// </summary> private void CheckAllLanguageFileIntact() { List <string> defaultFullKeyNameList = LanguageDataEditorUtils.LoadLangusgeAllFileNames(config.defaultLanguage); StringBuilder logBuider = new StringBuilder(); logBuider.Append("开始修复多语言完整....\n"); logBuider.Append("基准语言:" + config.defaultLanguage + "\n"); foreach (var nowLan in config.gameExistLanguages) { if (nowLan == config.defaultLanguage) { continue; } logBuider.Append("开始检查语言:" + nowLan + "\n"); List <string> nowFullKeyNameList = LanguageDataEditorUtils.LoadLangusgeAllFileNames(nowLan); foreach (var fullKeyFileName in defaultFullKeyNameList) { DataTable dt = LanguageDataUtils.LoadFileData(config.defaultLanguage, fullKeyFileName); if (!nowFullKeyNameList.Contains(fullKeyFileName)) { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (var id in dt.TableIDs) { dic.Add(id, ""); } CreateLanguageNewFile(nowLan, fullKeyFileName, dic); logBuider.Append(nowLan + "缺少文件:" + fullKeyFileName + " 已添加!\n"); } else { DataTable nowDT = LanguageDataUtils.LoadFileData(nowLan, fullKeyFileName); List <string> addKeys = new List <string>(); foreach (var id in dt.TableIDs) { if (!nowDT.TableIDs.Contains(id)) { addKeys.Add(id); } } AddNewKey(nowLan, fullKeyFileName, addKeys.ToArray()); if (addKeys.Count > 0) { logBuider.Append(nowLan + "=>" + fullKeyFileName + "缺少字段:\n"); foreach (var item in addKeys) { logBuider.Append("\t" + item + "\n"); } logBuider.Append("\n"); } } } } logBuider.Append("多语言完整性修复完成!\n"); AssetDatabase.Refresh(); Debug.Log(logBuider.ToString()); ShowNotification(new GUIContent("修复完成")); }
private void DeleteKey(string fullKeyFileName, string key) { foreach (var language in config.gameExistLanguages) { DataTable data = LanguageDataUtils. LoadFileData(language, fullKeyFileName); data.RemoveData(key); LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); } }
/// <summary> /// 模块文件中双击操作,选择文件 /// </summary> /// <param name="t"></param> private void ModuleFileDblclickItemCallBack(FolderTreeViewItem t) { if (t.isDirectory) return; selectFullFileName = t.fullPath; currentFileDataTable = LanguageDataUtils.LoadFileData(currentLanguage, selectFullFileName); toolbarOption = 1; }
/// <summary> /// 获取某种语言的多语言值 /// </summary> /// <param name="language"></param> /// <param name="fullFileName">"/"格式的文件名</param> /// <param name="key"></param> /// <returns></returns> private string GetLanguageValue(SystemLanguage language, string fullFileName, string key) { DataTable data = LanguageDataUtils.LoadFileData(language, fullFileName); if (data.ContainsKey(key) && data[key].ContainsKey(LanguageManager.c_valueKey)) { return(data[key][LanguageManager.c_valueKey]); } return(""); }
private void AddNewKey(string fullKeyFileName, string key) { foreach (var language in config.gameExistLanguages) { DataTable data = LanguageDataUtils.LoadFileData(language, fullKeyFileName); SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); } }
public static List <string> GetLanguageAllFunKeyList() { List <string> list = new List <string>(); LanguageSettingConfig config = LanguageDataUtils.LoadEditorConfig(); List <string> allFilePath = LoadLangusgeAllFileNames(config.defaultLanguage); foreach (var item in allFilePath) { DataTable data = LanguageDataUtils.LoadFileData(config.defaultLanguage, item); foreach (var key in data.TableIDs) { list.Add(item + "/" + key); } } return(list); }
void SelectLanguageGUI() { GUILayout.BeginHorizontal(); currentLanguage = EditorDrawGUIUtil.DrawPopup("当前语言", currentLanguage, config.gameExistLanguages, (lan) => { }); if (currentLanguage == SystemLanguage.Chinese) currentLanguage = SystemLanguage.ChineseSimplified; if (GUILayout.Button("加载上一次保存")) { DataManager.CleanCache(); LanguageManager.IsInit = false; GlobalEvent.DispatchEvent(EditorEvent.LanguageDataEditorChange); currentFileDataTable = LanguageDataUtils.LoadFileData(currentLanguage, selectFullFileName); GUI.FocusControl(""); } GUILayout.EndHorizontal(); }
private void CreateNewLangusge(SystemLanguage lan) { if (config.defaultLanguage == SystemLanguage.Unknown) { config.defaultLanguage = lan; currentLanguage = lan; } else { foreach (var item in s_languageFullKeyFileNameList) { DataTable dt = LanguageDataUtils.LoadFileData(config.defaultLanguage, item); Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (var id in dt.TableIDs) { dic.Add(id, ""); } CreateLanguageNewFile(lan, item, dic); } } }
private void SearchValueGUI() { searchValue = EditorDrawGUIUtil.DrawSearchField(searchValue); if (!string.IsNullOrEmpty(searchValue)) { if (searchValue.Contains("/")) { string[] tempV = searchValue.Split('/'); string key = tempV[tempV.Length - 1]; int indexEnd = searchValue.LastIndexOf("/"); string moduleName = searchValue.Remove(indexEnd); if (s_languageFullKeyFileNameList.Contains(moduleName)) { if (selectFullFileName != moduleName) { selectFullFileName = moduleName; Debug.Log("moduleName :" + moduleName); currentFileDataTable = LanguageDataUtils.LoadFileData(currentLanguage, selectFullFileName); Debug.Log("currentFileDataTable :" + currentFileDataTable); Debug.Log(" keys:" + currentFileDataTable.TableIDs.Count); } searchKey = key; } else { selectFullFileName = ""; searchKey = ""; } } else { searchKey = searchValue; } } else { searchKey = ""; } }
void MergeLanguage(string path, SystemLanguage language) { Debug.Log("MergeLanguage " + path); string languageKey = FileTool.GetFileNameByPath(FileTool.RemoveExpandName(path)).Replace(LanguageManager.c_DataFilePrefix + language + "_", "").Replace("_", "/"); Debug.Log("languageKey " + languageKey); string content = ResourceIOTool.ReadStringByFile(path); DataTable aimLanguage = DataTable.Analysis(content); DataTable localLanguage = LanguageDataUtils.LoadFileData(language, languageKey); foreach (var key in aimLanguage.TableIDs) { string value = aimLanguage[key].GetString(LanguageManager.c_valueKey); SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, value); if (!localLanguage.TableIDs.Contains(key)) { Debug.Log("新增字段 " + key + " -> " + value); localLanguage.AddData(sd); } else { if (localLanguage[key].GetString(LanguageManager.c_valueKey) != value) { Debug.Log("更新字段 key" + key + " Value >" + localLanguage[key].GetString(LanguageManager.c_valueKey) + "< newValue >" + value + "<"); localLanguage[key] = sd; } } } LanguageDataEditorUtils.SaveData(language, languageKey, localLanguage); }
private void AddNewKey(SystemLanguage language, string fullKeyFileName, string[] keys) { if (keys == null || keys.Length == 0) { return; } DataTable data = LanguageDataUtils.LoadFileData(language, fullKeyFileName); foreach (var key in keys) { if (data.ContainsKey(key)) { continue; } SingleData sd = new SingleData(); sd.Add(LanguageManager.c_mainKey, key); sd.Add(LanguageManager.c_valueKey, ""); data.AddData(sd); } LanguageDataEditorUtils.SaveData(language, fullKeyFileName, data); UnityEditor.AssetDatabase.Refresh(); }