Exemple #1
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);
            }
        }
        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);
        }