private void DrawCurrentLanguagePopup(TranslationManager translationManager)
        {
            string[] translatedLanguages = translationManager.GetTranslatedLanguages()
                                           .Select(it => it.ToString())
                                           .ToArray();
            if (translatedLanguages.IsNullOrEmpty())
            {
                // No translations found. Just use the default field
                EditorGUILayout.PropertyField(serializedObject.FindProperty("currentLanguage"));
                return;
            }

            int index = Array.IndexOf(translatedLanguages, translationManager.currentLanguage.ToString());

            if (index < 0)
            {
                index = 0;
            }

            int newIndex = EditorGUILayout.Popup("Current Language", index, translatedLanguages);

            if (newIndex != index)
            {
                if (Enum.TryParse(translatedLanguages[newIndex], false, out SystemLanguage newLanguage))
                {
                    translationManager.currentLanguage = newLanguage;
                    if (translationManager.currentLanguage == translationManager.defaultPropertiesFileLanguage)
                    {
                        translationManager.ClearFallbackLanguageTranslations();
                        translationManager.UpdateTranslatorsInScene();
                        MarkTranslatorsAsDirty();
                    }
                    else
                    {
                        translationManager.ClearCurrentLanguageTranslations();
                        translationManager.UpdateTranslatorsInScene();
                        MarkTranslatorsAsDirty();
                    }
                }
                else
                {
                    Debug.LogError($"Could not parse new value for currentLanguage: {translatedLanguages[newIndex]}");
                }
            }
        }
        public override void OnInspectorGUI()
        {
            TranslationManager translationManager = target as TranslationManager;

            DrawDefaultInspectorWithoutProperties(this.serializedObject, "currentLanguage", "defaultPropertiesFileLanguage");

            // currentLanguage popup field should only show translated languages
            DrawCurrentLanguagePopup(translationManager);

            // defaultPropertiesFileLanguage
            EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultPropertiesFileLanguage"));

            if (GUILayout.Button("Reload Translations"))
            {
                ReloadTranslationsAndUpdateScene(translationManager);
            }

            serializedObject.ApplyModifiedProperties();
        }
        private void InitSingleInstance()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (instance != null &&
                instance != this)
            {
                // This instance is not needed.
                Destroy(gameObject);
                return;
            }
            instance = this;

            // Move object to top level in scene hierarchy.
            // Otherwise this object will be destroyed with its parent, even when DontDestroyOnLoad is used.
            transform.SetParent(null);
            DontDestroyOnLoad(gameObject);
        }
 private void ReloadTranslationsAndUpdateScene(TranslationManager translationManager)
 {
     translationManager.ReloadTranslationsAndUpdateScene();
     MarkTranslatorsAsDirty();
 }
 private static bool TryGetActiveInstance(out TranslationManager translationManager)
 {
     translationManager = Instance;
     return(translationManager != null &&
            translationManager.gameObject.activeSelf);
 }