示例#1
0
        void ShowExportGUI()
        {
            if (GUILayout.Button("Экспорт"))
            {
                string folderPath = EditorUtility.OpenFolderPanel("Выберите папку для сохранения.", "", "");
                if (availableFileFormats[chosenFileFormat] == csvFileEnding)
                {
                    string fullPath = folderPath + "/" + exportFileName + csvFileEnding;
                    CSVParser.Write(fullPath, CSVParser.GetDelimiter(delimiter),
                                    new List <string>(LanguageHandlerEditor.LoadLanguageFile(null, true).Keys), LanguageHandlerEditor.LoadAllLanguageFiles());

                    Debug.Log("Экспортирован файл CSV в " + fullPath);
                    this.Close();
                }
                else if (availableFileFormats[chosenFileFormat] == xlsFileEnding)
                {
                    string fullPath = folderPath + "/" + exportFileName + xlsFileEnding;
                    XLSExporter.Write(fullPath, "Languages",
                                      new List <string>(LanguageHandlerEditor.LoadLanguageFile(null, true).Keys), LanguageHandlerEditor.LoadAllLanguageFiles());

                    Debug.Log("Экспортирован файл XLS в " + fullPath);
                    this.Close();
                }
                else
                {
                    Debug.LogError("BulkUpdateWindow: Неподдерживаемый формат экспорта!");
                }
            }
        }
        public void InitializeCultureCollections(bool reloadAllCultures = false)
        {
            if (reloadAllCultures)
            {
                allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());
            }

            availableCultures    = LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures);
            nonAvailableCultures = LanguageHandlerEditor.GetNonAvailableLanguages(allCultures);

            availableCultures.cultureInfos.Sort((a, b) =>
            {
                return(a.englishName.CompareTo(b.englishName));
            });
            nonAvailableCultures.cultureInfos.Sort((a, b) =>
            {
                return(a.englishName.CompareTo(b.englishName));
            });

            availableCultures.cultureInfos.Insert(0, new SmartCultureInfo(string.Empty, "ROOT", "ROOT", false));

            languageListAdaptor     = new SmartCultureInfoListAdaptor(availableCultures.cultureInfos, DrawAvailableLanguageItem, 28);
            languageListContextMenu = new SmartCultureInfoMenuControl();

            createListAdaptor     = new CreateLanguageListAdaptor(nonAvailableCultures.cultureInfos, DrawCreateLanguageItem, 15);
            createListContextMenu = new CreateLanguageMenuControl();

            settingsAdaptor     = new SettingsListAdaptor(settingsList, DrawSettingsItem, 110);
            settingsContextMenu = new SettingsMenuControl();
        }
示例#3
0
        void UpdateFromCSV(string chosenUpdateFile)
        {
            LanguageHandlerEditor.UpdateLanguageFile(chosenCulture.languageCode, CSVParser.Read(chosenUpdateFile, CSVParser.GetDelimiter(delimiter)));

            if (parentWindow.translateLanguageWindow != null)
            {
                parentWindow.translateLanguageWindow.ReloadLanguage();
            }
        }
示例#4
0
        void UpdateFromXLS(string chosenUpdateFile)
        {
            var values = XLSExporter.Read(chosenUpdateFile);

            LanguageHandlerEditor.UpdateLanguageFile(chosenCulture.languageCode, values);

            if (parentWindow.translateLanguageWindow != null)
            {
                parentWindow.translateLanguageWindow.ReloadLanguage();
            }
        }
示例#5
0
        /// <summary>
        /// Loads all the language files with their raw values
        /// </summary>
        /// <returns>A dictionary with all the language dictionaries. The language codes are being used as keys</returns>
        public static Dictionary <string, Dictionary <string, string> > LoadAllLanguageFiles()
        {
            var allLanguages      = new Dictionary <string, Dictionary <string, string> >();
            var availableCultures = LanguageHandlerEditor.CheckAndSaveAvailableLanguages(SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath()));

            foreach (SmartCultureInfo info in availableCultures.cultureInfos)
            {
                allLanguages.Add(info.languageCode, LoadLanguageFile(info.languageCode, false));
            }

            return(allLanguages);
        }
        void OnCreateLanguageClick(SmartCultureInfo info)
        {
            SmartCultureInfo chosenCulture = allCultures.FindCulture(info);

            if (chosenCulture == null)
            {
                Debug.LogError("язык: " + info.englishName + " не может быть создан");
                return;
            }
            LanguageHandlerEditor.CreateNewLanguage(chosenCulture.languageCode);

            InitializeCultureCollections();
        }
示例#7
0
 void OnWatchedFileChanged(object source, FileSystemEventArgs e)
 {
     EditorThreadQueuer.QueueOnMainThread(() => {
         Console.WriteLine("Файл изменен. Перезагрузка...");
         List <List <string> > values = CSVParser.Read(e.FullPath, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));
         LanguageHandlerEditor.UpdateLanguageFile(currentCultureInfo.languageCode, values);
         ReloadLanguage();
         if (Application.isPlaying && LanguageManager.HasInstance)
         {
             LanguageManager.Instance.ChangeLanguage(currentCultureInfo.languageCode);
         }
         Repaint();
     });
 }
示例#8
0
        /// <summary>
        /// Draws the GUI for when the automatic translator is initialized and available for translation
        /// </summary>
        void DrawAvailableAutoTranslationGUI(float fullWindowWidth, Rect newPosition)
        {
            newPosition.width          = fullWindowWidth * 0.69f;
            translateFromLanguageValue = EditorGUI.Popup(newPosition, "Translate From", translateFromLanguageValue, availableTranslateLangEnglishNames);
            newPosition.x += fullWindowWidth * 0.7f;

            if (oldTranslateFromLanguageValue != translateFromLanguageValue)
            {
                oldTranslateFromLanguageValue = translateFromLanguageValue;
                //The value have been changed, load the language file of the other language that you want to translate from
                //I load it like this to show the translate buttons only on the ones that can be translated i.e some values
                //in the "from" language could be an empty string - no use in translating that
                if (translateFromDictionary != null)
                {
                    translateFromDictionary.Clear();
                    translateFromDictionary = null;
                }
                if (translateFromLanguageValue != 0)
                {
                    string englishName = availableTranslateLangEnglishNames[translateFromLanguageValue];
                    foreach (SmartCultureInfo info in availableTranslateFromLanguages)
                    {
                        if (info.englishName == englishName)
                        {
                            translateFromDictionary = LanguageHandlerEditor.LoadParsedLanguageFile(info.languageCode, false);
                            translateFromLanguage   = info.languageCode;
                            break;
                        }
                    }
                }
            }

            newPosition.width = fullWindowWidth * 0.14f;
            if (translateFromLanguageValue != 0)
            {
                if (GUI.Button(newPosition, "Перевести весь текст"))
                {
                    if (translateFromLanguageValue != 0)
                    {
                        TranslateAllText();
                    }
                }
                newPosition.x += fullWindowWidth * 0.15f;
            }
            if (GUI.Button(newPosition, "Обновить"))
            {
                CheckIfCanBeTranslated();
            }
        }
示例#9
0
        void ExportToCSV(string chosenExportFolder)
        {
            string name  = chosenCulture.englishName + " - " + chosenCulture.languageCode + ".csv";
            var    input = new List <List <string> >();
            Dictionary <string, LocalizedObject> languageItems = LanguageHandlerEditor.LoadParsedLanguageFile(chosenCulture.languageCode, false);

            foreach (var item in languageItems)
            {
                var row = new List <string>();
                row.Add(item.Key);
                row.Add(item.Value.TextValue);
                input.Add(row);
            }
            CSVParser.Write(chosenExportFolder + "/" + name, CSVParser.GetDelimiter(delimiter), input);
        }
示例#10
0
        void OnGotAvailableLanguages(bool success, List <string> availableLanguages)
        {
            if (!success)
            {
                return;
            }

            availableTranslateFromLanguages.Clear();
            //Clear the array
            if (availableTranslateLangEnglishNames != null)
            {
                Array.Clear(availableTranslateLangEnglishNames, 0, availableTranslateLangEnglishNames.Length);
                availableTranslateLangEnglishNames = null;
            }

            if (translateFromDictionary != null)
            {
                translateFromDictionary.Clear();
                translateFromDictionary = null;
            }
            translateFromLanguageValue    = 0;
            oldTranslateFromLanguageValue = 0;

            List <string> englishNames = new List <string>();

            englishNames.Add("None");
            if (availableLanguages.Contains(currentCultureInfo.languageCode))
            {
                canLanguageBeTranslated = true;

                SmartCultureInfoCollection allCultures       = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());
                SmartCultureInfoCollection availableCultures = LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures);

                foreach (SmartCultureInfo cultureInfo in availableCultures.cultureInfos)
                {
                    if (cultureInfo.languageCode != currentCultureInfo.languageCode && availableLanguages.Contains(cultureInfo.languageCode))
                    {
                        availableTranslateFromLanguages.Add(cultureInfo);
                        englishNames.Add(cultureInfo.englishName);
                    }
                }
            }
            else
            {
                canLanguageBeTranslated = false;
            }
            availableTranslateLangEnglishNames = englishNames.ToArray();
        }
示例#11
0
        /// <summary>
        /// Initializes the Language
        /// </summary>
        public void InitializeLanguage(SmartCultureInfo info, Dictionary <string, LocalizedObject> rootValues, Dictionary <string, LocalizedObject> languageValues)
        {
            this.rootValues = rootValues;
            this.loadedLanguageValues.Clear();
            this.loadedLanguageValues = LanguageHandlerEditor.CreateSerializableLocalizationList(languageValues);
            //Load assets
            LanguageHandlerEditor.LoadAllAssets(this.loadedLanguageValues);

            this.thisLanguage = (currentCultureInfo.englishName + " - " + currentCultureInfo.languageCode);
            rootFileChanged   = false;

            SortLanguageValues(sortType);
            localizedObjectAdaptor     = new LocalizedObjectListAdaptor(this.loadedLanguageValues, null, DrawLanguageValue, 17, true);
            localizedObjectContextMenu = new LocalizedObjectMenuControl();

            localizedObjectAdaptor.collapseMultiline = collapseMultilineFields;
        }
示例#12
0
        void ImportFromXLS(string chosenImportFile)
        {
            List <List <string> > values = XLSExporter.Read(chosenImportFile);

            if (chosenCulture == null)
            {
                Debug.LogError("Язык: " + chosenCulture.englishName + " не может быть создан");
                this.Close();
                return;
            }
            LanguageHandlerEditor.CreateNewLanguage(chosenCulture.languageCode, values);

            if (creationDelegate != null)
            {
                creationDelegate();
                creationDelegate = null;
            }
        }
示例#13
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));
        }
示例#14
0
        /// <summary>
        /// Creates a new workspace. Returns false if a workspace already exists
        /// </summary>
        /// <returns>If the creation was a success.</returns>
        public static bool Create()
        {
            if (Exists())
            {
                return(false);
            }

            if (DirectoryUtility.Create(WorkspaceFolderPath()))
            {
                if (!DirectoryUtility.Create(AutoGeneratedFolderPath()))
                {
                    return(false);
                }

                if (!DirectoryUtility.Create(ResourcesFolderFilePath()))
                {
                    return(false);
                }

                if (!DirectoryUtility.Create(DataFolderPath()))
                {
                    return(false);
                }

                if (!DirectoryUtility.Create(LanguageDataFolderPath()))
                {
                    return(false);
                }

                if (!GenerateCultureInfoCollection())
                {
                    return(false);
                }

                LanguageHandlerEditor.CreateRootResourceFile();

                AssetDatabase.Refresh();
                return(true);
            }

            return(false);
        }
示例#15
0
        /// <summary>
        /// Checks .resx files and converts them into text assets that can be used at runtime
        /// </summary>
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            //Only use this if there's a localization system created
            if (!LocalizationWorkspace.Exists())
            {
                return;
            }

            foreach (string asset in importedAssets)
            {
                if (asset.EndsWith(LocalizationWorkspace.resXFileEnding))
                {
                    string newFileName = LocalizationWorkspace.ResourcesFolderFilePath() + "/" + Path.GetFileNameWithoutExtension(asset) + LocalizationWorkspace.txtFileEnding;

                    if (!DirectoryUtility.CheckAndCreate(LocalizationWorkspace.ResourcesFolderFilePath()))
                    {
                        return;
                    }

                    //Delete the file if it already exists
                    if (FileUtility.Exists(newFileName))
                    {
                        FileUtility.Delete(newFileName);
                    }

                    string fileData = "";
                    using (StreamReader reader = new StreamReader(asset))
                    {
                        fileData = reader.ReadToEnd();
                    }


                    FileUtility.WriteToFile(newFileName, fileData);

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

                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                }
            }
        }
示例#16
0
        void ShowImportGUI()
        {
            if (GUILayout.Button("Импортировать"))
            {
                if (availableFileFormats[chosenFileFormat] == csvFileEnding)
                {
                    string file = EditorUtility.OpenFilePanel("Выберите CSV файл.", "", "");
                    if (file != null && file != "")
                    {
                        var values = CSVParser.Read(file, CSVParser.GetDelimiter(delimiter));
                        if (values.Count > 0)
                        {
                            LanguageHandlerEditor.BulkUpdateLanguageFiles(values);
                        }
                    }
                    this.Close();
                }
                else if (availableFileFormats[chosenFileFormat] == xlsFileEnding)
                {
                    string file = EditorUtility.OpenFilePanel("Выберите XLS файл.", "", "");
                    if (file != null && file != "")
                    {
                        var values = XLSExporter.Read(file);
                        if (values.Count > 0)
                        {
                            LanguageHandlerEditor.BulkUpdateLanguageFiles(values);
                        }
                    }
                    this.Close();
                }
                else
                {
                    Debug.LogError("BulkUpdateWindow: Неподдерживаемый формат импорта!");
                }

                if (parentWindow.translateLanguageWindow != null)
                {
                    parentWindow.translateLanguageWindow.ReloadLanguage();
                }
            }
        }
示例#17
0
        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);
            }
        }
        protected override void OnItemRemoving(ItemRemovingEventArgs args)
        {
            SmartCultureInfoListAdaptor smartAdaptor = args.adaptor as SmartCultureInfoListAdaptor;

            if (smartAdaptor == null)
            {
                return;
            }

            SmartCultureInfo info = smartAdaptor.GetCultureInfo(args.itemIndex);

            if (EditorUtility.DisplayDialog("Удалить " + info.englishName + "?",
                                            "Вы уверены, что хотите удалить " + info.englishName + " и весь его контент из проекта? Вы не сможете отменить это действие.",
                                            "Да, удали это.", "Отмена"))
            {
                LanguageHandlerEditor.DeleteLanguage(info);
                base.OnItemRemoving(args);
            }
            else
            {
                args.Cancel = true;
            }
        }
示例#19
0
        /// <summary>
        /// Refreshes the list containing the selectable keys
        /// </summary>
        /// <param name="sort">If the refreshed list should be sorted and filtered with a certain key type</param>
        /// <param name="sortType">The key type to use as filter</param>
        public static void RefreshList(bool sort, LocalizedObjectType sortType)
        {
            if (!Application.isPlaying)
            {
                parsedRootValues.Clear();

                Dictionary <string, LocalizedObject> values = LanguageHandlerEditor.LoadParsedLanguageFile(null, true);
                if (sort)
                {
                    loadedObjectType = sortType;
                    foreach (KeyValuePair <string, LocalizedObject> pair in values)
                    {
                        if (pair.Value.ObjectType == sortType)
                        {
                            parsedRootValues.Add(pair.Key);
                        }
                    }
                }
                else
                {
                    //Use invalid for showing all
                    loadedObjectType = LocalizedObjectType.INVALID;

                    parsedRootValues.AddRange(values.Keys);
                }

                if (parsedRootValues.Count > 0)
                {
                    parsedRootValues.Insert(0, "--- Ключ не выбран ---");               //No key selected
                }
                else
                {
                    parsedRootValues.Add("--- Нет локализованных ключей ---");               //No localized keys available
                }
            }
        }
示例#20
0
        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("Обновленный язык:" + languageCode + ", Ключ обновлен:" + updatedKeys);
        }
示例#21
0
        public void Initialize(SmartCultureInfo thisCultureInfo, bool forceNewLanguage = false)
        {
            if (thisCultureInfo != null)
            {
                if (undoManager == null)
                {
                    // Instantiate Undo Manager
                    undoManager = new HOEditorUndoManager(this, "GGLocalization - Translate Language Window");              //Smart Localization - Translate Language Window
                }

                if (thisCultureInfo != null)
                {
                    bool newLanguage = thisCultureInfo != this.currentCultureInfo ? true : false;

                    if (Application.isPlaying || forceNewLanguage)
                    {
                        newLanguage = true;
                    }

                    this.currentCultureInfo = thisCultureInfo;
                    if (loadedLanguageValues == null || loadedLanguageValues.Count < 1 || newLanguage)
                    {
                        InitializeLanguage(thisCultureInfo,
                                           LanguageHandlerEditor.LoadParsedLanguageFile(null, true),
                                           LanguageHandlerEditor.LoadParsedLanguageFile(thisCultureInfo.languageCode,
                                                                                        false));
                    }
                }

                settingsList.Clear();
                settingsList.Add("SETTINGS");
                settingsList.Add("CONVERTLINEBREAK");
                settingsList.Add("WATCHFILE");
                settingsList.Add("AUTOTRANSLATE");
                settingsList.Add("GENERAL");

#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3
                if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.WebPlayer &&
                    EditorUserBuildSettings.activeBuildTarget != BuildTarget.WebPlayerStreamed)
#endif
                {
                    settingsList.Add("SORT");
                }

                settingsList.Add("SEARCH");

                settingsAdaptor     = new SettingsListAdaptor(settingsList, DrawSettingsItem, 20);
                settingsContextMenu = new SettingsMenuControl();

                listColumns = new EditorColumns(0.02f, true);
                listColumns.AddColumn("Копия", 0.1f);           // Copy
                listColumns.AddColumn("Перевод", 0.1f);         // Translate
                listColumns.AddColumn("Ключ", 0.21f);           // Key
                listColumns.AddColumn("Комментарий", 0.21f);    // Comment
                listColumns.AddColumn("Переопределить", 0.07f); //Override
                listColumns.AddColumn("Значение", 0.25f);       // Value
                listColumns.RecalculateColumnWidths();

                if (EditorPrefs.HasKey(CollapseMultilineSaveKey))
                {
                    collapseMultilineFields = EditorPrefs.GetBool(CollapseMultilineSaveKey);
                }

                GUIUtility.keyboardControl = 0;

                SmartCultureInfoCollection allCultures       = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());
                SmartCultureInfoCollection availableCultures = LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures);
                otherAvailableLanguageCodes.Clear();
                otherAvailableLanguageCodesArray = null;
                foreach (SmartCultureInfo otherCulture in availableCultures.cultureInfos)
                {
                    if (otherCulture.languageCode != thisCultureInfo.languageCode)
                    {
                        otherAvailableLanguageCodes.Add(otherCulture.languageCode);
                    }
                }

                if (otherAvailableLanguageCodes.Count > 0)
                {
                    otherAvailableLanguageCodesArray = otherAvailableLanguageCodes.ToArray();
                }
            }
        }
示例#22
0
        void Initialize()
        {
            if (undoManager == null)
            {
                // Instantiate Undo Manager
                undoManager = new HOEditorUndoManager(this, "GGLocalization - Окно редактирования корневого языка");
            }
            if (keyTypes == null)
            {
                //Get the different key types
                List <string> enumNames = new List <string>(Enum.GetNames(typeof(LocalizedObjectType)));
                if (enumNames.Contains("INVALID"))
                {
                    enumNames.Remove("INVALID");
                }
                keyTypes = enumNames.ToArray();
            }

            if (changedRootKeys == null)
            {
                changedRootKeys = new List <SerializableStringPair>();
            }
            if (changedRootValues == null)
            {
                changedRootValues = new List <SerializableLocalizationObjectPair>();
            }
            if (parsedRootValues == null)
            {
                parsedRootValues = new Dictionary <string, LocalizedObject>();
            }

            if (parsedRootValues.Count < 1)
            {
                SetRootValues(LanguageHandlerEditor.LoadParsedLanguageFile(null, true));
            }

            settingsList.Clear();
            settingsList.Add("CONVERTLINEBREAK");
            settingsList.Add("GENERAL");
            settingsList.Add("SEARCH");

            settingsAdaptor     = new SettingsListAdaptor(settingsList, DrawSettingsItem, 20);
            settingsContextMenu = new SettingsMenuControl();

            localizedObjectAdaptor = new LocalizedObjectListAdaptor(changedRootValues, changedRootKeys, DrawRootPair, 17);

            if (localizedObjectContextMenu != null)
            {
                localizedObjectContextMenu.ClearEvents();
            }

            localizedObjectContextMenu = new LocalizedObjectMenuControl(OnKeyDeleted, OnKeyAdded);

            listColumns = new EditorColumns(0.1f);
            listColumns.AddColumn("Type", 0.1f);
            listColumns.AddColumn("Key", 0.45f);
            listColumns.AddColumn("Comment", 0.45f);
            listColumns.RecalculateColumnWidths();

            if (EditorPrefs.HasKey(CollapseMultilineSaveKey))
            {
                collapseMultilineFields = EditorPrefs.GetBool(CollapseMultilineSaveKey);
            }

            GUIUtility.keyboardControl = 0;
        }
示例#23
0
 void OnRootEditClick()
 {
     ShowRootEditWindow(LanguageHandlerEditor.LoadParsedLanguageFile(null, true));
 }
示例#24
0
 void OnDeleteLanguageClick(SmartCultureInfo cultureInfo)
 {
     LanguageHandlerEditor.DeleteLanguage(cultureInfo);
 }
示例#25
0
        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);
                }
            }
        }
示例#26
0
 public void ReloadLanguage()
 {
     InitializeLanguage(currentCultureInfo, LanguageHandlerEditor.LoadParsedLanguageFile(null, true), LanguageHandlerEditor.LoadParsedLanguageFile(currentCultureInfo.languageCode, false));
 }