示例#1
0
        private void LoadTextLanguagesIntoDropdowns()
        {
            if (textLanguagesDropdown || textLanguagesTMPDropdown)
            {
                var textLanguageList = new List <string>();

                if (ProjectSettings.TextProjectLanguages.Count > 0)
                {
                    foreach (var language in ProjectSettings.TextProjectLanguages)
                    {
                        var culture = Cultures.GetCulture(language);
                        textLanguageList.Add(culture.NativeName);
                    }
                }
                else
                {
                    // If no project settings have been defined, show all available cultures
                    foreach (var culture in Cultures.GetCultures())
                    {
                        textLanguageList.Add(culture.NativeName);
                    }
                }


                PopulateLanguagesListToDropdown(textLanguageList, textLanguagesTMPDropdown, textLanguagesDropdown, ref textLanguageSelected, PreferencesSetting.TextLanguage);
            }
        }
        private void LoadTextLanguagesIntoDropdowns()
        {
            if (textLanguagesDropdown || textLanguagesTMPDropdown)
            {
                var textLanguageList = new List <string>();

                foreach (var localization in yarnProject.localizations)
                {
                    var culture = Cultures.GetCulture(localization.LocaleCode);
                    textLanguageList.Add(culture.DisplayName);
                }

                PopulateLanguagesListToDropdown(textLanguageList, textLanguagesTMPDropdown, textLanguagesDropdown, ref textLanguageSelected, PreferencesSetting.TextLanguage);
            }
        }
示例#3
0
        private void ProcessError(Exception ex)
        {
            var error      = ex as HttpException;
            int statusCode = error == null ? 500 : error.GetHttpCode();

            string culture = Cultures.GetCulture(ModelUserContext.CurrentLanguage);

            switch (statusCode)
            {
            case 404:
                Response.Redirect("~/" + culture + "/Error/Http404");
                break;

            default:
                Response.Redirect("~/" + culture + "/Error/HttpError");
                break;
            }
        }
        private void PopulateLanguagesListToDropdown(List <string> languageList, TMP_Dropdown tmpDropdown, Dropdown dropdown, ref int selectedLanguageIndex, PreferencesSetting setting)
        {
            switch (setting)
            {
            case PreferencesSetting.TextLanguage:
                selectedLanguageIndex = languageList.IndexOf(TextLanguage);
                break;

            case PreferencesSetting.AudioLanguage:
                selectedLanguageIndex = languageList.IndexOf(AudioLanguage);
                break;
            }

            var displayNames = new List <string>();

            foreach (var culture in languageList)
            {
                displayNames.Add(Cultures.GetCulture(culture).NativeName);
            }

            if (dropdown)
            {
                dropdown.ClearOptions();
                dropdown.AddOptions(displayNames);
#if UNITY_2019_1_OR_NEWER
                dropdown.SetValueWithoutNotify(selectedLanguageIndex);
#else
                dropdown.value = selectedLanguageIndex;
#endif
            }

            if (tmpDropdown)
            {
                tmpDropdown.ClearOptions();
                tmpDropdown.AddOptions(displayNames);
#if UNITY_2019_1_OR_NEWER
                tmpDropdown.SetValueWithoutNotify(selectedLanguageIndex);
#else
                tmpDropdown.value = selectedLanguageIndex;
#endif
            }
        }
        private void LoadAudioLanguagesIntoDropdowns()
        {
            if (audioLanguagesDropdown || audioLanguagesTMPDropdown)
            {
                var audioLanguageList = new List <string>();

                foreach (var localization in yarnProject.localizations)
                {
                    if (localization.ContainsLocalizedAssets == false)
                    {
                        continue;
                    }

                    var culture = Cultures.GetCulture(localization.LocaleCode);
                    audioLanguageList.Add(culture.DisplayName);
                }

                PopulateLanguagesListToDropdown(audioLanguageList, textLanguagesTMPDropdown, textLanguagesDropdown, ref textLanguageSelected, PreferencesSetting.TextLanguage);
            }
        }
示例#6
0
    private void DrawLocalizationGUI()
    {
        using (var changed = new EditorGUI.ChangeCheckScope())
        {
            var previousLocalizationDatabase = localizationDatabaseProperty.objectReferenceValue as LocalizationDatabase;

            // Show the 'localization database' property
            EditorGUILayout.PropertyField(localizationDatabaseProperty);

            // If this changed to a valid value, update that database so
            // that it tracks all selected programs
            if (changed.changed)
            {
                var newObjectReference = localizationDatabaseProperty.objectReferenceValue;

                if (previousLocalizationDatabase != null && previousLocalizationDatabase != newObjectReference)
                {
                    // The property used to refer to a localization
                    // database, but that's changed. Tell the previous
                    // value to stop tracking this program.
                    foreach (YarnImporter importer in serializedObject.targetObjects)
                    {
                        if (importer.programContainer == null)
                        {
                            continue;
                        }
                        previousLocalizationDatabase.RemoveTrackedProgram(importer.programContainer);

                        // Mark that the localization database has changed,
                        // so needs to be saved
                        EditorUtility.SetDirty(previousLocalizationDatabase);
                    }
                }

                // Tell the new database that it should track us
                if (newObjectReference is LocalizationDatabase database)
                {
                    foreach (YarnImporter importer in serializedObject.targetObjects)
                    {
                        // If we don't actually have a program (because of
                        // a compile error), there's nothing to do here
                        if (importer.programContainer == null)
                        {
                            continue;
                        }
                        database.AddTrackedProgram(importer.programContainer);

                        // Mark that the localization database should save
                        // changes
                        EditorUtility.SetDirty(previousLocalizationDatabase);
                    }
                }
            }
        }

        // If no localization database is provided, offer a button that
        // will create a new one that 1. tracks this script 2. has a
        // localization set to this script's base language 3. and also we
        // make sure that this project's language list includes this
        // program's base language.
        if (localizationDatabaseProperty.objectReferenceValue == null)
        {
            if (GUILayout.Button("Create New Localization Database"))
            {
                YarnImporterUtility.CreateNewLocalizationDatabase(serializedObject);
            }
        }

        // For every localization in the localization database:
        // - If we have a TextAsset for it, show it here
        // - If we don't, create a button that creates one
        //
        // We only do this if we're editing a single object, because each
        // separate script will have its own translations.
        if (serializedObject.isEditingMultipleObjects == false && localizationDatabaseProperty.objectReferenceValue != null)
        {
            EditorGUI.indentLevel += 1;
            var importer             = serializedObject.targetObject as YarnImporter;
            var localizationDatabase = localizationDatabaseProperty.objectReferenceValue as LocalizationDatabase;

            var languagesList = new List <string>();
            languagesList.Add(importer.baseLanguageID);

            // Expose the base language asset in the inspector, but disable
            // it because it's always a derived sub-asset
            using (new EditorGUI.DisabledScope(true))
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PropertyField(baseLanguageProperty, new GUIContent(importer.baseLanguageID));

                    // Not actually used, but makes this base language item
                    // visually consistent with the additional ones below
                    GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(false));
                }


            foreach (SerializedProperty localization in localizationsProperty)
            {
                var nameProperty           = localization.FindPropertyRelative("languageName");
                var assetReferenceProperty = localization.FindPropertyRelative("text");
                var languageName           = nameProperty.stringValue;
                var languageDisplayName    = Cultures.GetCulture(languageName).DisplayName;

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PropertyField(assetReferenceProperty, new GUIContent(languageDisplayName));

                    if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                    {
                        // We delete this property twice:
                        // - once to clear the value from the array entry
                        // - again to remove the cleared entry from the
                        //   array
                        //
                        // (If the entry is already empty, the first delete
                        // will remove it; the second delete appears to be
                        // a no-op, so it's safe.)
                        localization.DeleteCommand();
                        localization.DeleteCommand();
                    }
                }


                // Mark that we've seen this language name
                languagesList.Add(languageName);
            }

            // For each language that's present in the localization
            // database but not present in this script, offer buttons that
            // create a CSV for that language
            var languagesMissing = localizationDatabase.GetLocalizationLanguages().Except(languagesList);

            foreach (var language in languagesMissing)
            {
                if (GUILayout.Button($"Create {language} Localization"))
                {
                    YarnImporterUtility.CreateLocalizationForLanguageInProgram(serializedObject, language);
                }
            }

            // Show a warning for any languages that the script has a
            // localization for, but that the database doesn't call for
            var languagesExtraneous = languagesList.Except(localizationDatabase.GetLocalizationLanguages());

            if (languagesExtraneous.Count() > 0)
            {
                EditorGUILayout.HelpBox($"This script has localizations for the following languages, but the localization database isn't set up to use them: {string.Join(", ", languagesExtraneous)}", MessageType.Warning);
            }

            // TODO: is it possible to interleave the property fields for
            // existing localisations with buttons, in alphabetical order
            // of language code?

            EditorGUI.indentLevel -= 1;

            if (GUILayout.Button("Update Localizations"))
            {
                YarnImporterUtility.UpdateLocalizationCSVs(serializedObject);
            }

            EditorGUILayout.HelpBox("To add a new localization, select the Localization Database, and click Create New Localization.", MessageType.Info);
        }
    }