/// <summary> /// Gets a SmartCultureInfoCollection with all the cultures not available in this workspace /// </summary> /// <param name="allCultures">The list of all the available cultures</param> /// <returns>A SmartCultureInfoCollection with all the cultures not available in this workspace</returns> public static SmartCultureInfoCollection GetNonAvailableLanguages(SmartCultureInfoCollection allCultures) { SmartCultureInfoCollection nonCreatedLanguages = new SmartCultureInfoCollection(); foreach(SmartCultureInfo cultureInfo in allCultures.cultureInfos) { if(!FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode))) { nonCreatedLanguages.AddCultureInfo(cultureInfo); } } return nonCreatedLanguages; }
/// <summary> /// Checks all the created languages and Saves the AvailableCultures xml. /// </summary> /// <param name="allCultures">A list of all the available cultures</param> /// <returns>A list of all the created languages</returns> public static SmartCultureInfoCollection CheckAndSaveAvailableLanguages(SmartCultureInfoCollection allCultures) { SmartCultureInfoCollection createdCultures = new SmartCultureInfoCollection(); foreach(SmartCultureInfo cultureInfo in allCultures.cultureInfos) { if(FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode))) { createdCultures.AddCultureInfo(cultureInfo); } } createdCultures.Serialize(LocalizationWorkspace.AvailableCulturesFilePath()); return createdCultures; }
private void SaveAndRebuild() { //Copy everything into a dictionary Dictionary <string, string> newLanguageValues = new Dictionary <string, string>(); foreach (var objectPair in loadedLanguageValues) { if (objectPair.changedValue.ObjectType == LocalizedObjectType.STRING) { newLanguageValues.Add(objectPair.changedValue.GetFullKey(objectPair.keyValue), objectPair.changedValue.TextValue); } else { //Delete the file in case there was a file there previously LanguageHandlerEditor.DeleteFileFromResources(objectPair.changedValue.GetFullKey(objectPair.keyValue), currentCultureInfo); //Store the path to the file string pathValue = string.Empty; if (objectPair.changedValue.OverrideLocalizedObject) { pathValue = "override=" + objectPair.changedValue.OverrideObjectLanguageCode; } else { pathValue = LanguageHandlerEditor.CopyFileIntoResources(objectPair, currentCultureInfo); } newLanguageValues.Add(objectPair.changedValue.GetFullKey(objectPair.keyValue), pathValue); } } LanguageHandlerEditor.SaveLanguageFile(newLanguageValues, LocalizationWorkspace.LanguageFilePath(currentCultureInfo.languageCode)); guiChanged = false; GUIUtility.keyboardControl = 0; if (Application.isPlaying && LanguageManager.HasInstance) { LanguageManager.Instance.ChangeLanguage(currentCultureInfo.languageCode); } }
public static void UpdateLanguageFile(string languageCode, List <List <string> > values) { Dictionary <string, string> languageItems = null; if (FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(languageCode))) { languageItems = LanguageHandlerEditor.LoadLanguageFile(languageCode, false); } else { languageItems = new Dictionary <string, string>(); } int updatedKeys = 0; foreach (List <string> row in values) { if (row.Count != 2) { continue; } string key = row[0].TrimStart('\r', '\n').TrimEnd('\r', '\n').Trim(); string value = row[1]; if (!languageItems.ContainsKey(key)) { continue; } languageItems[key] = value; updatedKeys++; } LanguageHandlerEditor.SaveLanguageFile(languageItems, LocalizationWorkspace.LanguageFilePath(languageCode)); Debug.Log("Updated language:" + languageCode + ", Keys updated:" + updatedKeys); }
/// <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); } } }