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 Initialize(SmartCultureInfo thisCultureInfo, bool forceNewLanguage = false)
        {
            if (thisCultureInfo != null)
            {
                if (undoManager == null)
                {
                    // Instantiate Undo Manager
                    undoManager = new HOEditorUndoManager(this, "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("Copy", 0.1f);
                listColumns.AddColumn("Translate", 0.1f);
                listColumns.AddColumn("Key", 0.21f);
                listColumns.AddColumn("Comment", 0.21f);
                listColumns.AddColumn("Override", 0.07f);
                listColumns.AddColumn("Value", 0.25f);
                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();
                }
            }
        }
Esempio n. 3
0
        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);
                }
            }
        }