Beispiel #1
0
        // PRIVATE METHODS: --------------------------------------------------------------------------------------------

        private void ExportLanguage(int index)
        {
            SerializedProperty spLanguages = this.languages.serializedProperty.GetArrayElementAtIndex(index);
            int          language          = spLanguages.FindPropertyRelative("language").intValue;
            int          size         = this.spTranslationList.arraySize;
            Translations translations = new Translations((SystemLanguage)language);

            for (int i = 0; i < size; ++i)
            {
                SerializedProperty property = this.spTranslationList.GetArrayElementAtIndex(i);
                int key = property.FindPropertyRelative("key").intValue;

                if (key == 0)
                {
                    continue;
                }

                bool translationFound      = false;
                SerializedProperty content = property.FindPropertyRelative("content");
                for (int j = 0; !translationFound && j < content.arraySize; ++j)
                {
                    SerializedProperty contentItem = content.GetArrayElementAtIndex(j);
                    if (contentItem.FindPropertyRelative("language").intValue == language)
                    {
                        string text = contentItem.FindPropertyRelative("text").stringValue;
                        if (!string.IsNullOrEmpty(text))
                        {
                            translationFound = true;
                            translations.AddTranslation(key, text);
                        }
                    }
                }

                if (!translationFound)
                {
                    string placeholder = property.FindPropertyRelative("placeholder").stringValue;
                    translations.AddTranslation(key, placeholder);
                }
            }

            string fileName = string.Format("{0}.json", ((SystemLanguage)language).ToString());
            string savePath = EditorUtility.SaveFilePanel(MSG_SAVE, "", fileName, "json");

            if (string.IsNullOrEmpty(savePath))
            {
                EditorApplication.Beep();
                return;
            }

            File.WriteAllText(savePath, EditorJsonUtility.ToJson(translations, true));
        }