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); }
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)); }
public void AddKey(string key, string value) { if (parsedRootValues.ContainsKey(key)) { return; } LocalizedObject dummyObject = new LocalizedObject(); dummyObject.ObjectType = LocalizedObjectType.STRING; dummyObject.TextValue = key; string addedKey = LanguageDictionaryHelper.AddNewKeyPersistent(parsedRootValues, key, dummyObject); LocalizedObject copyObject = new LocalizedObject(); copyObject.ObjectType = LocalizedObjectType.STRING; copyObject.TextValue = value; changedRootKeys.Add(new SerializableStringPair(addedKey, addedKey)); changedRootValues.Add(new SerializableLocalizationObjectPair(addedKey, copyObject)); }
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); }
public void AddToObjectDictionary_UniqueNames() { var testDictionary = new Dictionary <string, LocalizedObject>(); string tempKey = "TestKey"; LocalizedObject tempStringValue = new LocalizedObject(); tempStringValue.ObjectType = LocalizedObjectType.STRING; tempStringValue.TextValue = "TEMP"; LocalizedObject tempAudioValue = new LocalizedObject(tempStringValue); tempAudioValue.ObjectType = LocalizedObjectType.AUDIO; LocalizedObject tempPrefabValue = new LocalizedObject(tempStringValue); tempPrefabValue.ObjectType = LocalizedObjectType.GAME_OBJECT; LocalizedObject tempTextureValue = new LocalizedObject(tempStringValue); tempTextureValue.ObjectType = LocalizedObjectType.TEXTURE; LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary, tempKey, tempStringValue); LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary, tempKey, new LocalizedObject(tempStringValue)); LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary, tempKey, tempAudioValue); LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary, tempKey, tempPrefabValue); LanguageDictionaryHelper.AddNewKeyPersistent(testDictionary, tempKey, tempTextureValue); }
/// <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("Deleted key!:" + deletedKey); DeleteFileFromResources(deletedKey, cultureInfo); } } }