/// <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; }
/// <summary> /// Generates the SmartCultureInfoCollection xml with all the available language infos and keeps any difference in old data /// as well. /// </summary> /// <returns>If the operation was successful</returns> public static bool GenerateCultureInfoCollection(SmartCultureInfoCollection previousCollection) { if (!DirectoryUtility.Create(CultureInfoDataFolderPath())) { return(false); } SmartCultureInfoCollection availableCultures = new SmartCultureInfoCollection(); availableCultures.version = SmartCultureInfoCollection.LatestVersion; if (previousCollection != null) { //Add all cultures from the previous collection in case any one of them were custom made foreach (var cultureInfo in previousCollection.cultureInfos) { availableCultures.AddCultureInfo(cultureInfo); } } //Get all the cultures from Microsofts CultureInfo in the System.Globalization namespace CultureInfo[] cultureInfos = CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures); foreach (var cultureInfo in cultureInfos) { if (availableCultures.FindCulture(cultureInfo.Name) == null) { availableCultures.AddCultureInfo(new SmartCultureInfo(cultureInfo.Name, cultureInfo.EnglishName, cultureInfo.NativeName, cultureInfo.TextInfo.IsRightToLeft)); } } foreach (var cultureInfo in ExtraCultureInfos) { if (availableCultures.FindCulture(cultureInfo) == null) { availableCultures.AddCultureInfo(new SmartCultureInfo(cultureInfo.languageCode, cultureInfo.englishName, cultureInfo.nativeName, cultureInfo.isRightToLeft)); } } availableCultures.Serialize(CultureInfoCollectionFilePath()); return(true); }
void OnGUI() { if (LocalizationWindowUtility.ShouldShowWindow()) { GUILayout.Label("Create a new culture info", EditorStyles.boldLabel); languageCode = EditorGUILayout.TextField("Language Code", languageCode); if (languageCode != null) { languageCode = languageCode.RemoveWhitespace(); } englishName = EditorGUILayout.TextField("English Name", englishName); nativeName = EditorGUILayout.TextField("Native Name", nativeName); isRightToLeft = EditorGUILayout.Toggle("Is Right To Left", isRightToLeft); if (GUILayout.Button("Create")) { SmartCultureInfo newInfo = new SmartCultureInfo(); newInfo.languageCode = languageCode; newInfo.englishName = englishName.Trim(); newInfo.nativeName = nativeName.Trim(); newInfo.isRightToLeft = isRightToLeft; SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath()); if (!allCultures.IsCultureInCollection(newInfo)) { allCultures.AddCultureInfo(newInfo); allCultures.Serialize(LocalizationWorkspace.CultureInfoCollectionFilePath()); LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures); showHelpMessage = true; helpMessageType = MessageType.Info; helpMessage = string.Format("Successfully created language!\n Language Code: {0}\n English Name:{1}\n Native Name:{2}\n IsRightToLeft:{3}", newInfo.languageCode, newInfo.englishName, newInfo.nativeName, newInfo.isRightToLeft); if (parentWindow != null) { parentWindow.InitializeCultureCollections(true); } this.Close(); } else { SmartCultureInfo conflictingCulture = allCultures.FindCulture(newInfo); string conflictingVariable = null; if (conflictingCulture.languageCode.ToLower() == newInfo.languageCode.ToLower()) { conflictingVariable = "Language Code:" + newInfo.languageCode; } else if (conflictingCulture.englishName.ToLower() == newInfo.englishName.ToLower()) { conflictingVariable = "English Name:" + newInfo.englishName; } showHelpMessage = true; helpMessageType = MessageType.Error; helpMessage = string.Format("Failed to create language!\n Conflicting variable - {0}\n\n", conflictingVariable); helpMessage += string.Format("Conflicting Culture \n Language Code: {0}\n English Name:{1}\n Native Name:{2}", conflictingCulture.languageCode, conflictingCulture.englishName, conflictingCulture.nativeName); } } if (showHelpMessage) { EditorGUILayout.HelpBox(helpMessage, helpMessageType); } } }
void OnGUI() { if (LocalizationWindowUtility.ShouldShowWindow()) { GUILayout.Label("Создать новую информацию о культуре", EditorStyles.boldLabel); languageCode = EditorGUILayout.TextField("Код языка", languageCode); if (languageCode != null) { languageCode = languageCode.RemoveWhitespace(); } englishName = EditorGUILayout.TextField("Английское имя", englishName); nativeName = EditorGUILayout.TextField("Родное имя", nativeName); isRightToLeft = EditorGUILayout.Toggle("Справа налево", isRightToLeft); if (GUILayout.Button("Создать")) { SmartCultureInfo newInfo = new SmartCultureInfo(); newInfo.languageCode = languageCode; newInfo.englishName = englishName.Trim(); newInfo.nativeName = nativeName.Trim(); newInfo.isRightToLeft = isRightToLeft; SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath()); if (!allCultures.IsCultureInCollection(newInfo)) { allCultures.AddCultureInfo(newInfo); allCultures.Serialize(LocalizationWorkspace.CultureInfoCollectionFilePath()); LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures); showHelpMessage = true; helpMessageType = MessageType.Info; helpMessage = string.Format("Язык успешно создан!\n Код языка: {0}\n Английское имя:{1}\n Родное имя:{2}\n Справа налево:{3}", newInfo.languageCode, newInfo.englishName, newInfo.nativeName, newInfo.isRightToLeft); if (parentWindow != null) { parentWindow.InitializeCultureCollections(true); } this.Close(); } else { SmartCultureInfo conflictingCulture = allCultures.FindCulture(newInfo); string conflictingVariable = null; if (conflictingCulture.languageCode.ToLower() == newInfo.languageCode.ToLower()) { conflictingVariable = "Language Code:" + newInfo.languageCode; } else if (conflictingCulture.englishName.ToLower() == newInfo.englishName.ToLower()) { conflictingVariable = "English Name:" + newInfo.englishName; } showHelpMessage = true; helpMessageType = MessageType.Error; helpMessage = string.Format("Не удалось создать язык!\n Конфликтующая переменная - {0}\n\n", conflictingVariable); helpMessage += string.Format("Конфликтующая культура \n Код языка: {0}\n Английское имя:{1}\n Родное имя:{2}", conflictingCulture.languageCode, conflictingCulture.englishName, conflictingCulture.nativeName); } } if (showHelpMessage) { EditorGUILayout.HelpBox(helpMessage, helpMessageType); } } }