Exemple #1
0
        void OnKeyAdded(int addedIndex)
        {
            LocalizedObject dummyObject = new LocalizedObject();

            dummyObject.ObjectType = LocalizedObjectType.STRING;
            dummyObject.TextValue  = "New Value";

            string addedKey = LanguageDictionaryHelper.AddNewKeyPersistent(parsedRootValues, "New Key", dummyObject);

            LocalizedObject copyObject = new LocalizedObject();

            copyObject.ObjectType = LocalizedObjectType.STRING;
            copyObject.TextValue  = "New Value";

            changedRootKeys.Add(new SerializableStringPair(addedKey, addedKey));
            changedRootValues[addedIndex] = new SerializableLocalizationObjectPair(addedKey, copyObject);
        }
Exemple #2
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));
        }
        /// <summary>
        /// Saves the root language file and updates all the available languages.
        /// </summary>
        public static void SaveRootLanguageFile(Dictionary <string, string> changedRootKeys, Dictionary <string, string> changedRootValues, SmartCultureInfoCollection availableCultures)
        {
            //The dictionary with all the final changes
            Dictionary <string, string> changedDictionary = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> changedKey in changedRootKeys)
            {
                if (changedKey.Key == changedKey.Value)
                {
                    //The key is not changed, just add the key and the changed value to the new dictionary
                    LanguageDictionaryHelper.AddNewKeyPersistent(changedDictionary, changedKey.Key, changedRootValues[changedKey.Key]);
                }
                else
                {
                    //Add the new key along with the new changed value
                    LanguageDictionaryHelper.AddNewKeyPersistent(changedDictionary, changedKey.Value, changedRootValues[changedKey.Key]);
                }
            }

            //Look if any keys were deleted,(so that we can delete the created files)
            List <string>        deletedKeys  = new List <string>();
            IEnumerable <string> originalKeys = LoadLanguageFile(null, true).Keys;

            foreach (string originalKey in originalKeys)
            {
                bool foundMatch = false;
                foreach (KeyValuePair <string, string> changedKey in changedRootKeys)
                {
                    if (originalKey == changedKey.Key)
                    {
                        foundMatch = true;
                        break;
                    }
                }
                if (!foundMatch)
                {
                    deletedKeys.Add(originalKey);
                }
            }

            //Save the language file
            SaveLanguageFile(changedDictionary, LocalizationWorkspace.RootLanguageFilePath());

            //Change all the key values for all the translated languages
            var changedCultureValues = new Dictionary <string, string>();

            foreach (var cultureInfo in availableCultures.cultureInfos)
            {
                var currentCultureValues = LoadLanguageFile(cultureInfo.languageCode, false);
                foreach (var changedKey in changedRootKeys)
                {
                    string currentValue;
                    currentCultureValues.TryGetValue(changedKey.Key, out currentValue);
                    if (currentValue == null)
                    {
                        currentValue = "";
                    }

                    //If the key is changed, we need to change the asset names as well
                    if (changedKey.Key != changedKey.Value && currentValue != "")
                    {
                        LocalizedObjectType originalType = LocalizedObject.GetLocalizedObjectType(changedKey.Key);
                        LocalizedObjectType changedType  = LocalizedObject.GetLocalizedObjectType(changedKey.Value);

                        if (originalType != changedType)
                        {
                            //If the type is changed, then delete the asset and reset the value
                            DeleteFileFromResources(changedKey.Key, cultureInfo);
                            currentValue = "";
                        }
                        else
                        {
                            //just rename it otherwise
                            RenameFileFromResources(changedKey.Key, changedKey.Value, cultureInfo);
                        }
                    }

                    LanguageDictionaryHelper.AddNewKeyPersistent(changedCultureValues, changedKey.Value, currentValue);
                }

                //Save the language file
                SaveLanguageFile(changedCultureValues, LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode));
                changedCultureValues.Clear();

                //Remove all the deleted files associated with the deleted keys
                foreach (string deletedKey in deletedKeys)
                {
                    Debug.Log("Ключ удален!:" + deletedKey);
                    DeleteFileFromResources(deletedKey, cultureInfo);
                }
            }
        }