public override void OnInspectorGUI()
        {
            database = Resources.Load <TranslatableTextDatabase>("Texts/TranslatablesDatabase");
            if (!database)
            {
                GUILayout.BeginVertical();
                EditorGUILayout.LabelField("TranslatablesDatabase is not set.");
                EditorGUILayout.LabelField("Create a TranslatablesDatabase in Resources/Texts/TranslatablesDatabase.asset");
                GUILayout.EndVertical();
                return;
            }


            SerializedObject   mapperObj        = new SerializedObject(mapper);
            SerializedProperty labelMapListProp = mapperObj.FindProperty("labelMapList");

            // Update the list
            mapperObj.Update();


            EditorGUILayout.Space();
            if (GUILayout.Button("Add New", GUILayout.Width(80)))
            {
                Undo.RecordObject(mapper, "Added new mapping");
                mapper.labelMapList.Add(new LabelAndText());
                Undo.FlushUndoRecordObjects();
            }
            if (labelMapListProp.arraySize > 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Label", GUILayout.Width(200));
                GUILayout.Label("Text", GUILayout.Width(200));
                EditorGUILayout.EndHorizontal();
            }
            for (int i = 0; i < labelMapListProp.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                SerializedProperty item  = labelMapListProp.GetArrayElementAtIndex(i);
                SerializedProperty label = item.FindPropertyRelative("label");
                label.objectReferenceValue = EditorGUILayout.ObjectField(label.objectReferenceValue, typeof(TMP_Text), true, GUILayout.Width(200));

                string[] displayOpts = PrependOption("<None>", database.GetTexts());
                int      oldIndex    = 0;
                if (mapper.labelMapList[i].text != null)
                {
                    oldIndex = database.GetIndexByTranslationKey(mapper.labelMapList[i].text.translationKey) + 1;
                }
                int selected = EditorGUILayout.IntPopup(oldIndex, displayOpts, GetIndexes(displayOpts.Length), GUILayout.Width(200));
                if (oldIndex != selected)
                {
                    Undo.RecordObject(mapper, "Changed a mapping");
                    if (selected > 0)
                    {
                        mapper.labelMapList[i].text = database.translatables[selected - 1];
                    }
                    else
                    {
                        mapper.labelMapList[i].text = null;
                    }
                    Undo.FlushUndoRecordObjects();
                }
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    labelMapListProp.DeleteArrayElementAtIndex(i);
                }
                EditorGUILayout.EndHorizontal();
            }

            mapperObj.ApplyModifiedProperties();
        }
 private void OnEnable()
 {
     database = (TranslatableTextDatabase)target;
 }
        public override void OnInspectorGUI()
        {
            if (database.translatables == null)
            {
                database.translatables = new List <TranslatableText>();
            }


            database.isTranslation = EditorGUILayout.ToggleLeft("is a Translation?", database.isTranslation, GUILayout.Width(180));

            if (database.isTranslation)
            {
                TranslatableTextDatabase auxDB = (TranslatableTextDatabase)EditorGUILayout.ObjectField("Original Database", database.original, typeof(TranslatableTextDatabase), false);
                if (auxDB != null && !auxDB.Equals(database))
                {
                    database.original = auxDB;
                }
            }

            if (database.isTranslation && (database.original == null || database.original.GetTexts() == null))
            {
                GUILayout.Label("You need to specify the original database for this translation and it must contain at least one item");
                return;
            }

            if (GUILayout.Button("Add New", GUILayout.Width(80)))
            {
                database.translatables.Add(new TranslatableText());
            }

            for (int i = 0; i < database.translatables.Count; i++)
            {
                TranslatableText item = database.translatables[i];
                EditorGUILayout.LabelField(new GUIContent("Translation Key: " + item.translationKey, "Internal key used to match the original with the translations"));
                if (database.isTranslation)
                {
                    EditorGUILayout.LabelField("Original Translation Key: " + ((item.original != null)?item.original.translationKey:""));
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Original", GUILayout.Width(50));
                    int selected = database.original.GetIndexByTranslationKey(item.translationKey) + 1;

                    string[] displayOpts = PrependOption("<None>", database.original.GetTexts());
                    selected = EditorGUILayout.IntPopup(selected, displayOpts, GetIndexes(displayOpts.Length), GUILayout.Width(100));
                    if (selected > 0)
                    {
                        item.original       = database.original.translatables[selected - 1];
                        item.translationKey = item.original.translationKey;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (string.IsNullOrEmpty(item.translationKey) && !database.isTranslation)
                {
                    item.translationKey = "text-" + ShortGuid.NewGuid();
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Text", GUILayout.Width(50));
                item.Text = EditorGUILayout.TextField(item.Text, GUILayout.Width(300));
                bool removed = false;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    database.translatables.RemoveAt(i);
                    removed = true;
                }
                EditorGUILayout.EndHorizontal();
                if (!removed)
                {
                    database.translatables[i] = item;
                }
            }

            EditorUtility.SetDirty(database);
        }
        private void OnWizardCreate()
        {
            if (translatablesDatabase == null)
            {
                EditorUtility.DisplayDialog("Error", "You need to select the translatables database", "OK");
                return;
            }
            if (translatablesDatabase.isTranslation && translatablesDatabase.original != null)
            {
                // Instead of the original database, a translation was chosen, but we can set it to the right one.
                translatablesDatabase = translatablesDatabase.original;
            }
            TranslatableTextDatabase databaseToSave = null;
            string path = EditorUtility.OpenFilePanelWithFilters("Open label translation file", "", new string[] { "Text file", "txt" });

            if (path.Length != 0)
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    databaseToSave               = CreateInstance <TranslatableTextDatabase>();
                    databaseToSave.original      = translatablesDatabase;
                    databaseToSave.isTranslation = true;
                    databaseToSave.translatables = new List <TranslatableText>();
                    Regex regex     = new Regex(@"^(.+?)(?: *):(?: *)(.*)$");
                    int   lineCount = 0;
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        lineCount++;
                        // Ignore comments and empty lines
                        if (line.StartsWith("//") || line.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (regex.IsMatch(line))
                        {
                            Match            m = regex.Match(line);
                            string           originalContent = m.Groups[1].Value;
                            TranslatableText originalText    = FindByOriginalContent(originalContent);
                            if (originalText == null)
                            {
                                EditorUtility.DisplayDialog("Error", "The original text for a label couldn't be found. Aborting", "OK");
                                return;
                            }
                            string           translation    = m.Groups[2].Value;
                            TranslatableText translatedText = new TranslatableText();
                            translatedText.original       = originalText;
                            translatedText.translationKey = originalText.translationKey;
                            translatedText.Text           = translation;
                            databaseToSave.translatables.Add(translatedText);
                        }
                        else
                        {
                            Debug.LogWarningFormat("LabelTranslationImporter: The line number {0} doesn't matches the format", lineCount);
                        }
                    }
                }
            }
            else
            {
                Debug.LogWarning("LabelTranslationImporter: No input file selected. Process aborted");
                return;
            }
            if (databaseToSave != null)
            {
                string baseFolder      = "Resources/" + localeSettings.baseFolder + "/" + locale.langCode + "/Texts";
                string targetDirectory = CreateIntermediateFolders(baseFolder);
                AssetDatabase.CreateAsset(databaseToSave, targetDirectory + "/TranslatablesDatabase.asset");
                AssetDatabase.SaveAssets();
            }
        }