public void LoadEntries(string langKey, Dictionary <string, string> dictionary)
        {
            foreach (var wordKey in dictionary.Keys)
            {
                LocalizationEntry current = new LocalizationEntry();

                current.languageKey = langKey;
                current.wordKey     = wordKey;
                current.wordValue   = dictionary[wordKey];

                LoadEntries(current);
            }
        }
예제 #2
0
        private void DisplayValues()
        {
            //Header
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("KEY", GUILayout.MinWidth(100), GUILayout.MaxWidth(200));

                foreach (var lang in languageKeys)
                {
                    EditorGUILayout.LabelField(lang, GUILayout.MinWidth(50), GUILayout.MaxWidth(500));
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            //DisplayValues
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            foreach (string wk in wordKeys)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginHorizontal(GUILayout.MinWidth(100), GUILayout.MaxWidth(200));
                if (GUILayout.Button("•", GUILayout.MinWidth(15), GUILayout.Height(23)))
                {
                    //Edit Entry
                    ShowEditPopup(wk);
                }

                EditorGUILayout.SelectableLabel(wk, GUILayout.Height(25));
                EditorGUILayout.EndHorizontal();

                foreach (string lk in languageKeys)
                {
                    var entry = tempEntries.Where(e => e.languageKey == lk && e.wordKey == wk).FirstOrDefault();
                    if (entry == null)
                    {
                        entry             = new LocalizationEntry();
                        entry.wordKey     = wk;
                        entry.languageKey = lk;
                    }
                    entry.wordValue = EditorGUILayout.TextField(entry.wordValue, GUILayout.MinWidth(50), GUILayout.MaxWidth(500), GUILayout.Height(25));
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();
            EditorGUILayout.Space();
        }
        public void LoadEntries(LocalizationEntry entry)
        {
            if (!_entries.Contains(entry))
            {
                _entries.Add(entry);
            }

            if (!_langKeys.Contains(entry.languageKey))
            {
                _langKeys.Add(entry.languageKey);
            }

            if (!_wordKeys.Contains(entry.wordKey))
            {
                _wordKeys.Add(entry.wordKey);
            }
        }
예제 #4
0
        public bool AddEntry(LocalizationEntry newEntry)
        {
            if (tempEntries.Exists(e => e.wordKey == newEntry.wordKey && e.languageKey == newEntry.languageKey))
            {
                return(false);
            }

            tempEntries.Add(newEntry);
            if (!wordKeys.Contains(newEntry.wordKey))
            {
                wordKeys.Add(newEntry.wordKey);
            }
            if (!languageKeys.Contains(newEntry.languageKey))
            {
                languageKeys.Add(newEntry.languageKey);
            }

            return(true);
        }
        public LocalizationEntry GetEntry(string langKey, string wordKey)
        {
            LocalizationEntry resultEntry = null;

            if (!LangKeysContains(langKey))
            {
                return(resultEntry);
            }
            if (!WordKeysContains(wordKey))
            {
                return(resultEntry);
            }
            var temp = _entries.Where(e => e.languageKey == langKey && e.wordKey == wordKey);

            if (temp.Count() != 1)
            {
                return(resultEntry);
            }

            resultEntry = temp.First();

            return(resultEntry);
        }
예제 #6
0
        public bool UpdateEntry(LocalizationEntry originalEntry, LocalizationEntry updatedEntry)
        {
            List <LocalizationEntry> targetEntries = tempEntries.Where(e => e.wordKey == originalEntry.wordKey && e.languageKey == originalEntry.languageKey).ToList();

            if (targetEntries.Count == 0)
            {
                return(false);
            }

            for (int i = 0; i < targetEntries.Count; i++)
            {
                targetEntries[i].Copy(updatedEntry);
            }

            int index = wordKeys.IndexOf(originalEntry.wordKey);

            if (index >= 0)
            {
                wordKeys[index] = updatedEntry.wordKey;
            }

            return(true);
        }
 public bool EntriesContains(LocalizationEntry entry)
 {
     return(_entries.Contains(entry));
 }
예제 #8
0
        public void OnGUI()
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            //EditorGUILayout.SelectableLabel(""+this.position.height);
            //EditorGUILayout.SelectableLabel(""+this.position.width);

            switch (_currentType)
            {
            case PopUpType.None:
                break;

            case PopUpType.Add:
            {
                //Key Label
                EditorGUILayout.BeginHorizontal();
                {
                    //EditorGUILayout.LabelField("KEY", GUILayout.MinWidth(50), GUILayout.MaxWidth(75));
                    GUI.SetNextControlName("KEY");
                    wordKey = EditorGUILayout.TextField("KEY", wordKey);
                    entries.ForEach(e => e.wordKey = wordKey);
                }
                EditorGUILayout.EndHorizontal();
                //if (originalWordKey != wordKey)
                {
                    if (!mainWindow.CheckWordKeyValidity(wordKey))
                    {
                        EditorGUILayout.HelpBox("Invalid key", MessageType.Error);
                    }
                }
                EditorGUILayout.Separator();

                //Langs
                langScroll = EditorGUILayout.BeginScrollView(langScroll);
                foreach (var lk in originalLangKeys)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        LocalizationEntry current = entries.Find(e => e.wordKey == wordKey && e.languageKey == lk);
                        EditorGUILayout.PrefixLabel(lk);
                        current.wordValue = EditorGUILayout.TextArea(current.wordValue, GUILayout.Height(50));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();
                if (GUILayout.Button("Add"))
                {
                    if (!mainWindow.CheckWordKeyValidity(wordKey))
                    {
                        EditorGUILayout.HelpBox("Invalid key", MessageType.Error);
                    }
                    else
                    {
                        foreach (var e in entries)
                        {
                            mainWindow.AddEntry(e);
                        }
                        Close();
                    }
                }

                break;
            }

            case PopUpType.Edit:
            {
                //Key Label
                EditorGUILayout.BeginHorizontal();
                {
                    GUI.SetNextControlName("KEY");
                    wordKey = EditorGUILayout.TextField("KEY", wordKey);
                    entries.ForEach(e => e.wordKey = wordKey);
                }
                EditorGUILayout.EndHorizontal();
                if (originalWordKey != wordKey)
                {
                    if (!mainWindow.CheckWordKeyValidity(wordKey))
                    {
                        EditorGUILayout.HelpBox("Invalid key", MessageType.Error);
                    }
                }
                EditorGUILayout.Separator();
                //Langs
                langScroll = EditorGUILayout.BeginScrollView(langScroll);
                foreach (var lk in originalLangKeys)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        LocalizationEntry current = entries.Find(e => e.wordKey == wordKey && e.languageKey == lk);
                        EditorGUILayout.PrefixLabel(lk);
                        current.wordValue = EditorGUILayout.TextArea(current.wordValue, GUILayout.Height(50));
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();

                if (GUILayout.Button("Update"))
                {
                    if (originalWordKey != wordKey)
                    {
                        if (!mainWindow.CheckWordKeyValidity(wordKey))
                        {
                            ShowNotification(new GUIContent("Key already present!"));
                        }
                        else
                        {
                            Close();
                            mainWindow.UpdateEntry(originalEntries, entries);
                        }
                    }
                    else
                    {
                        Close();
                        mainWindow.UpdateEntry(originalEntries, entries);
                    }
                }

                if (GUILayout.Button("Remove"))
                {
                    mainWindow.RemoveEntry(originalWordKey);
                    ShowNotification(new GUIContent("Key Removed!"));
                    Close();
                }

                break;
            }

            default:
                break;
            }

            if (GUILayout.Button("Close"))
            {
                this.Close();
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }