예제 #1
0
 protected static void GetLocalizationFiles()
 {
     try {
         LocalizatronEditor.langFiles = new List <string>();
         if (!Directory.Exists(Settings.LANGUAGE_PATH + Path.DirectorySeparatorChar))
         {
             Directory.CreateDirectory(Settings.LANGUAGE_PATH + Path.DirectorySeparatorChar);
         }
         string[] paths = Directory.GetFiles(Settings.LANGUAGE_PATH);
         foreach (string path in paths)
         {
             if (path.Contains(Settings.LANGUAGE_EXTENSION) && !path.Contains(".meta"))
             {
                 LocalizatronEditor.langFiles.Add(path);
             }
         }
         LocalizatronEditor.Log("Localization files loaded successfully!");
     }
     catch (Exception e) {
         if (IS_DEBUG)
         {
             LocalizatronEditor.Log("Failed to inizialize files: " + e.Message);
         }
     }
 }
예제 #2
0
 protected static void SaveLocalizationFile(string fileName, string content)
 {
     System.IO.File.WriteAllText(Application.dataPath + Settings.SAVING_LANGUAGE_PATH + fileName + Settings.LANGUAGE_EXTENSION, content);
     LocalizatronEditor.Log("Localization files (" + fileName + ") saved!");
 }
예제 #3
0
 static void OpenLocalizationWindow()
 {
     LocalizatronEditor.GetLocalizationFiles();
     EditorWindow.GetWindow(typeof(LocalizatronEditor), false, "Localizatron");
 }
예제 #4
0
    protected void EditFileWindow()
    {
        try {
            EditorGUILayout.LabelField("Editing locale: " + this.selectedFile, EditorStyles.boldLabel);

            EditorGUILayout.Space();

            this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition, GUILayout.MaxWidth(450), GUILayout.MaxHeight(450), GUILayout.ExpandHeight(false));

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Key Filter", EditorStyles.boldLabel);
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();
            this.keyFilter = EditorGUILayout.TextField(this.keyFilter);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Value Filter", EditorStyles.boldLabel);
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();
            this.valueFilter = EditorGUILayout.TextField(this.valueFilter);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Key", EditorStyles.boldLabel);
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Value", EditorStyles.boldLabel);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();


            if (this.localeDict == null)
            {
                this.localeDict = this.inEditorLoadLanguageTable(Application.dataPath + Settings.SAVING_LANGUAGE_PATH + this.selectedFile + Settings.LANGUAGE_EXTENSION);
            }

            bool isFiltered = false;

            foreach (KeyValuePair <string, string> pair in this.localeDict)
            {
                string tmpKey = "", tmpValue = "";
                if (this.keyFilter != "" || this.valueFilter != "")
                {
                    isFiltered = true;
                    if (this.keyFilter != "" && this.valueFilter != "")
                    {
                        if (pair.Key.ToLower().Contains(this.keyFilter.ToLower()) && pair.Value.ToLower().Contains(this.valueFilter.ToLower()))
                        {
                            EditorGUILayout.BeginHorizontal();

                            EditorGUILayout.BeginVertical();
                            tmpKey = EditorGUILayout.TextField(pair.Key);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.BeginVertical();
                            tmpValue = EditorGUILayout.TextField(pair.Value);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    else if (this.keyFilter != "")
                    {
                        if (pair.Key.ToLower().Contains(this.keyFilter.ToLower()))
                        {
                            EditorGUILayout.BeginHorizontal();

                            EditorGUILayout.BeginVertical();
                            tmpKey = EditorGUILayout.TextField(pair.Key);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.BeginVertical();
                            tmpValue = EditorGUILayout.TextField(pair.Value);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    else if (this.valueFilter != "")
                    {
                        if (pair.Value.ToLower().Contains(this.valueFilter.ToLower()))
                        {
                            EditorGUILayout.BeginHorizontal();

                            EditorGUILayout.BeginVertical();
                            tmpKey = EditorGUILayout.TextField(pair.Key);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.BeginVertical();
                            tmpValue = EditorGUILayout.TextField(pair.Value);
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();

                    EditorGUILayout.BeginVertical();
                    tmpKey = EditorGUILayout.TextField(pair.Key);
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();
                    tmpValue = EditorGUILayout.TextField(pair.Value);
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.EndHorizontal();
                }
                if (this.finalContentDict.ContainsKey(pair.Key))
                {
                    this.finalContentDict.Remove(pair.Key);
                }
                if (tmpKey != "")
                {
                    this.finalContentDict[tmpKey] = tmpValue;
                }
            }

            if (!isFiltered)
            {
                this.localeDict = new Dictionary <string, string>(this.finalContentDict);
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();
            if (GUILayout.Button("Add entry"))
            {
                guiEvents.Enqueue(() =>
                {
                    try {
                        this.localeDict.Add("Entry-" + DateTime.Now.Ticks, "");
                    }
                    catch (Exception e) {
                        if (LocalizatronEditor.IS_DEBUG)
                        {
                            LocalizatronEditor.Log(e.Message);
                        }
                    }
                });
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();
            if (GUILayout.Button("< Back"))
            {
                this.selectedFile = "";
                this.localeDict   = null;
                this.finalContentDict.Clear();
                this._context = CONTEXT.FILES_MANAGER;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            if (GUILayout.Button("Save locale"))
            {
                string finalContent = "";

                foreach (KeyValuePair <string, string> kv in this.finalContentDict)
                {
                    finalContent += "<key>" + kv.Key + "</key><value>" + kv.Value + "</value>\n";
                }
                LocalizatronEditor.SaveLocalizationFile(this.selectedFile, finalContent);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndScrollView();
        }
        catch (Exception e) {
            if (LocalizatronEditor.IS_DEBUG)
            {
                LocalizatronEditor.Log(e.Message);
            }
            EditorGUILayout.EndScrollView();
        }
    }
예제 #5
0
    protected void FileManagerWindow()
    {
        try {
            EditorGUILayout.LabelField("Localization files", EditorStyles.boldLabel);

            EditorGUILayout.Space();

            EditorGUILayout.BeginScrollView(this.scrollPositionFileManager, GUILayout.MaxWidth(450), GUILayout.MaxHeight(450), GUILayout.ExpandHeight(false));
            foreach (string entry in LocalizatronEditor.langFiles)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.TextField(Path.GetFileName(entry).Replace(Settings.LANGUAGE_EXTENSION, ""));
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                if (GUILayout.Button("Delete", EditorStyles.miniButtonLeft, GUILayout.Width(45)))
                {
                    OnDeleteFileInFileManagerWindow(entry);
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                if (GUILayout.Button("Edit", EditorStyles.miniButtonRight, GUILayout.Width(45)))
                {
                    this.selectedFile = Path.GetFileName(entry).Replace(Settings.LANGUAGE_EXTENSION, "");
                    this.localeDict   = this.inEditorLoadLanguageTable(Application.dataPath + Settings.SAVING_LANGUAGE_PATH + this.selectedFile + Settings.LANGUAGE_EXTENSION);
                    if (this.localeDict.Count == 0)
                    {
                        this.localeDict.Add("Entry-" + DateTime.Now.Ticks, "");
                    }
                    this._context = CONTEXT.EDIT_FILE;
                    LocalizatronEditor.Log("Selected localization file: " + this.selectedFile);
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();
            this.newFileName = EditorGUILayout.TextField(this.newFileName);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            if (GUILayout.Button("Add new localization file"))
            {
                if (this.newFileName != "" && this.newFileName != null)
                {
                    LocalizatronEditor.langFiles.Add(Settings.LANGUAGE_PATH + this.newFileName);
                    LocalizatronEditor.SaveLocalizationFile(this.newFileName, "<key></key><value></value>");
                    this.newFileName = "";
                }
                else
                {
                    LocalizatronEditor.Log("You cannot add an unnamed file!");
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndScrollView();
        }
        catch {
            if (LocalizatronEditor.IS_DEBUG)
            {
                LocalizatronEditor.Log("Updated missing ref of deleted file");
            }
            EditorGUILayout.EndScrollView();
        }
    }
예제 #6
0
 protected void OnDeleteFileInFileManagerWindow(string entry)
 {
     LocalizatronEditor.langFiles.Remove(entry);
     LocalizatronEditor.DeleteLocalizationFile(entry);
 }
예제 #7
0
 protected static void DeleteLocalizationFile(string filePath)
 {
     System.IO.File.Delete(Application.dataPath + Settings.SAVING_LANGUAGE_PATH + Path.GetFileName(filePath));
     LocalizatronEditor.Log("Localization files (" + Path.GetFileName(filePath) + ") deleted!");
 }