GetFullKey() public method

Gets the full key value with identifiers and everything
public GetFullKey ( string parsedKey ) : string
parsedKey string /// Parsed key. (Clean key originally from GetCleanKey) ///
return string
Beispiel #1
0
        void SaveRootLanguageFile()
        {
            var changeNewRootKeys   = new Dictionary <string, string>();
            var changeNewRootValues = new Dictionary <string, string>();

            for (int i = 0; i < changedRootKeys.Count; i++)
            {
                SerializableStringPair             rootKey   = changedRootKeys[i];
                SerializableLocalizationObjectPair rootValue = changedRootValues[i];
                //Check for possible duplicates and rename them
                string newKeyValue = LanguageDictionaryHelper.AddNewKeyPersistent(changeNewRootKeys,
                                                                                  rootKey.originalValue,
                                                                                  rootValue.changedValue.GetFullKey(rootKey.changedValue));

                //Check for possible duplicates and rename them(same as above)
                LanguageDictionaryHelper.AddNewKeyPersistent(changeNewRootValues, newKeyValue, rootValue.changedValue.TextValue);
            }

            //Add the full values before saving
            var changeNewRootKeysToSave   = new Dictionary <string, string>();
            var changeNewRootValuesToSave = new Dictionary <string, string>();

            foreach (var rootKey in changeNewRootKeys)
            {
                LocalizedObject thisLocalizedObject = parsedRootValues[rootKey.Key];
                changeNewRootKeysToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), rootKey.Value);
                changeNewRootValuesToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), changeNewRootValues[rootKey.Key]);
            }



            SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());

            LanguageHandlerEditor.SaveRootLanguageFile(changeNewRootKeysToSave, changeNewRootValuesToSave, LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures));

            //Fire the root language changed event
            if (OnRootFileChanged != null)
            {
                OnRootFileChanged();
            }

            //Reload the window(in case of duplicate keys)
            SetRootValues(LanguageHandlerEditor.LoadParsedLanguageFile(null, true));
        }
Beispiel #2
0
    /// <summary>
    /// Adds a new key to a dictionary<string,string> and does not stop until a unique key is found
    /// </summary>
    public static string AddNewKeyPersistent(Dictionary <string, string> thisDictionary, string desiredKey, string newValue)
    {
        LocalizedObjectType thisKeyType = LocalizedObject.GetLocalizedObjectType(desiredKey);

        //Clean the key from unwanted type identifiers
        //Nothing will happen to a regular string, since a string doesn't have an identifier
        desiredKey = LocalizedObject.GetCleanKey(desiredKey, thisKeyType);

        if (!thisDictionary.ContainsKey(desiredKey) && thisKeyType == LocalizedObjectType.STRING)
        {
            thisDictionary.Add(desiredKey, newValue);
            return(desiredKey);
        }
        else
        {
            bool   newKeyFound = false;
            int    count       = 0;
            string newKeyName  = desiredKey;
            while (!newKeyFound)
            {
                if (!thisDictionary.ContainsKey(newKeyName))
                {
                    bool duplicateFound = false;
                    foreach (KeyValuePair <string, string> stringPair in thisDictionary)
                    {
                        string cleanKey = LocalizedObject.GetCleanKey(stringPair.Key);
                        if (cleanKey == newKeyName)
                        {
                            duplicateFound = true;
                            break;
                        }
                    }
                    if (!duplicateFound)
                    {
                        thisDictionary.Add(LocalizedObject.GetFullKey(newKeyName, thisKeyType), newValue);
                        newKeyFound = true;
                        return(desiredKey);
                    }
                    else
                    {
                        newKeyName = desiredKey + count;
                        count++;
                    }
                }
                else
                {
                    newKeyName = desiredKey + count;
                    count++;
                }
            }
            Debug.Log("Duplicate keys in dictionary was found! - renaming key:" + desiredKey + " to:" + newKeyName);
            return(newKeyName);
        }
    }
        string GetTestData(string testKey, string testValue, LocalizedObjectType objectType)
        {
            StringBuilder resxData = new StringBuilder(resxTemplateDataStart);

            resxData.Append("<data name=\"");
            resxData.Append(LocalizedObject.GetFullKey(testKey, objectType));
            resxData.Append("\" xml:space=\"preserve\">\n");
            resxData.Append("<value>");
            resxData.Append(testValue);
            resxData.Append("</value>\n");
            resxData.Append("</data>\n");
            resxData.Append(resxTemplateDataEnd);

            return(resxData.ToString());
        }
Beispiel #4
0
        public void AddToStringDictionary_UniqueNames()
        {
            Dictionary <string, string> testDictionary = new Dictionary <string, string>();
            string tempKey   = "TestKey";
            string tempValue = "temp";

            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.STRING),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.AUDIO),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.GAME_OBJECT),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.TEXTURE),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.STRING),
                                                         tempValue);
        }
        public void AddToStringDictionary_UniqueNames()
        {
            Dictionary <string, string> testDictionary = new Dictionary <string, string>();
            string tempKey   = "TestKey";
            string tempValue = "temp";

            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.String),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.Audio),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.GameObject),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.Texture),
                                                         tempValue);
            LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary,
                                                         LocalizedObject.GetFullKey(tempKey, LocalizedObjectType.String),
                                                         tempValue);
        }
    void OnGUI()
    {
        if (EditorWindowUtility.ShowWindow())
        {
            undoManager.CheckUndo();
            GUILayout.Label("Root Values", EditorStyles.boldLabel);

            //Search field
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Search for Key:", GUILayout.Width(100));
            searchText = EditorGUILayout.TextField(searchText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Key Type", GUILayout.Width(100));
            GUILayout.Label("Key");
            GUILayout.Label("Base Value/Comment");
            GUILayout.Label("Delete", EditorStyles.miniLabel, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            //Create the scroll view
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            //Delete key information
            bool deleteKey     = false;
            int  indexToDelete = 0;

            //Check if the user searched for a value
            bool didSearch = false;
            if (searchText != "")
            {
                didSearch = true;
                GUILayout.Label("Search Results - \"" + searchText + "\":", EditorStyles.boldLabel);
            }

            for (int i = 0; i < changedRootKeys.Count; i++)
            {
                SerializableStringPair rootValue = changedRootKeys[i];
                if (didSearch)
                {
                    //If the name of the key doesn't contain the search value, then skip a value
                    if (!rootValue.originalValue.ToLower().Contains(searchText.ToLower()))
                    {
                        continue;
                    }
                }
                EditorGUILayout.BeginHorizontal();

                //Popup of all the different key values
                changedRootValues[i].changedValue.ObjectType = (LocalizedObjectType)EditorGUILayout.Popup((int)changedRootValues[i].changedValue.ObjectType,
                                                                                                          keyTypes, GUILayout.Width(100));

                rootValue.changedValue = EditorGUILayout.TextField(rootValue.changedValue);
                changedRootValues[i].changedValue.TextValue = EditorGUILayout.TextField(changedRootValues[i].changedValue.TextValue);
                if (GUILayout.Button("Delete", GUILayout.Width(50)))
                {
                    deleteKey     = true;
                    indexToDelete = i;
                }

                EditorGUILayout.EndHorizontal();
            }

            //End the scrollview
            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Add New Key"))
            {
                AddNewKey();
            }

            //Delete the key outside the foreach loop
            if (deleteKey)
            {
                DeleteKey(indexToDelete);
            }

            if (guiChanged)
            {
                GUILayout.Label("- You have unsaved changes", EditorStyles.miniLabel);
            }

            //If any changes to the gui is made
            if (GUI.changed)
            {
                guiChanged = true;
            }

            GUILayout.Label("Save Changes", EditorStyles.boldLabel);
            GUILayout.Label("Remember to always press save when you have changed values", EditorStyles.miniLabel);
            if (GUILayout.Button("Save Root Language File"))
            {
                Dictionary <string, string> changeNewRootKeys   = new Dictionary <string, string>();
                Dictionary <string, string> changeNewRootValues = new Dictionary <string, string>();

                for (int i = 0; i < changedRootKeys.Count; i++)
                {
                    SerializableStringPair             rootKey   = changedRootKeys[i];
                    SerializableLocalizationObjectPair rootValue = changedRootValues[i];
                    //Check for possible duplicates and rename them
                    string newKeyValue = LocFileUtility.AddNewKeyPersistent(changeNewRootKeys, rootKey.originalValue, rootValue.changedValue.GetFullKey(rootKey.changedValue));

                    //Check for possible duplicates and rename them(same as above)
                    LocFileUtility.AddNewKeyPersistent(changeNewRootValues, newKeyValue, rootValue.changedValue.TextValue);
                }

                //Add the full values before saving
                Dictionary <string, string> changeNewRootKeysToSave   = new Dictionary <string, string>();
                Dictionary <string, string> changeNewRootValuesToSave = new Dictionary <string, string>();

                foreach (KeyValuePair <string, string> rootKey in changeNewRootKeys)
                {
                    LocalizedObject thisLocalizedObject = parsedRootValues[rootKey.Key];
                    changeNewRootKeysToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), rootKey.Value);
                    changeNewRootValuesToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), changeNewRootValues[rootKey.Key]);
                }

                LocFileUtility.SaveRootLanguageFile(changeNewRootKeysToSave, changeNewRootValuesToSave);

                //Fire the root language changed event
                if (OnRootFileChanged != null)
                {
                    OnRootFileChanged();
                }

                //Reload the window(in case of duplicate keys)
                SetRootValues(LocFileUtility.LoadParsedLanguageFile(null));
                guiChanged = false;
            }

            undoManager.CheckDirty();
        }
    }