// Returns the provided language or a similar one without the Region
        //(e.g. "English (Canada)" could be mapped to "english" or "English (United States)" if "English (Canada)" is not found
        public static string GetSupportedLanguage(string Language, bool ignoreDisabled = false)
        {
            // First try finding the language that matches one of the official languages
            string code = GoogleLanguages.GetLanguageCode(Language, false);

            if (!string.IsNullOrEmpty(code))
            {
                // First try finding if the exact language code is in one source
                for (int i = 0, imax = Sources.Count; i < imax; ++i)
                {
                    int Idx = Sources[i].GetLanguageIndexFromCode(code, true, ignoreDisabled);
                    if (Idx >= 0)
                    {
                        return(Sources[i].mLanguages[Idx].Name);
                    }
                }

                // If not, try checking without the region
                for (int i = 0, imax = Sources.Count; i < imax; ++i)
                {
                    int Idx = Sources[i].GetLanguageIndexFromCode(code, false, ignoreDisabled);
                    if (Idx >= 0)
                    {
                        return(Sources[i].mLanguages[Idx].Name);
                    }
                }
            }

            // If not found, then try finding an exact match for the name
            for (int i = 0, imax = Sources.Count; i < imax; ++i)
            {
                int Idx = Sources[i].GetLanguageIndex(Language, false, ignoreDisabled);
                if (Idx >= 0)
                {
                    return(Sources[i].mLanguages[Idx].Name);
                }
            }

            // Then allow matching "English (Canada)" to "english"
            for (int i = 0, imax = Sources.Count; i < imax; ++i)
            {
                int Idx = Sources[i].GetLanguageIndex(Language, true, ignoreDisabled);
                if (Idx >= 0)
                {
                    return(Sources[i].mLanguages[Idx].Name);
                }
            }

            return(string.Empty);
        }
예제 #2
0
        void OnGUI_AddLanguage(SerializedProperty Prop_Languages)
        {
            //--[ Add Language Upper Toolbar ]-----------------

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            mLanguages_NewLanguage = EditorGUILayout.TextField("", mLanguages_NewLanguage, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUI.enabled = !string.IsNullOrEmpty(mLanguages_NewLanguage);
            if (TestButton(eTest_ActionType.Button_AddLanguageManual, "Add", EditorStyles.toolbarButton, GUILayout.Width(50)))
            {
                Prop_Languages.serializedObject.ApplyModifiedProperties();
                mLanguageSource.AddLanguage(mLanguages_NewLanguage, GoogleLanguages.GetLanguageCode(mLanguages_NewLanguage));
                Prop_Languages.serializedObject.Update();
                mLanguages_NewLanguage = "";
                GUI.FocusControl(string.Empty);
            }
            GUI.enabled = true;

            GUILayout.EndHorizontal();


            //--[ Add Language Bottom Toolbar ]-----------------

            GUILayout.BeginHorizontal();

            //-- Language Dropdown -----------------
            string CodesToExclude = string.Empty;

            foreach (var LanData in mLanguageSource.mLanguages)
            {
                CodesToExclude = string.Concat(CodesToExclude, "[", LanData.Code, "]");
            }

            List <string> Languages = GoogleLanguages.GetLanguagesForDropdown(mLanguages_NewLanguage, CodesToExclude);

            GUI.changed = false;
            int index = EditorGUILayout.Popup(0, Languages.ToArray(), EditorStyles.toolbarDropDown);

            if (GUI.changed && index >= 0)
            {
                mLanguages_NewLanguage = GoogleLanguages.GetFormatedLanguageName(Languages[index]);
            }


            if (TestButton(eTest_ActionType.Button_AddLanguageFromPopup, "Add", EditorStyles.toolbarButton, GUILayout.Width(50)) && index >= 0)
            {
                Prop_Languages.serializedObject.ApplyModifiedProperties();
                mLanguages_NewLanguage = GoogleLanguages.GetFormatedLanguageName(Languages[index]);

                if (!string.IsNullOrEmpty(mLanguages_NewLanguage))
                {
                    mLanguageSource.AddLanguage(mLanguages_NewLanguage, GoogleLanguages.GetLanguageCode(mLanguages_NewLanguage));
                }
                Prop_Languages.serializedObject.Update();

                mLanguages_NewLanguage = "";
                GUI.FocusControl(string.Empty);
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.color = Color.white;
        }
예제 #3
0
 public void AddLanguage(string LanguageName)
 {
     AddLanguage(LanguageName, GoogleLanguages.GetLanguageCode(LanguageName));
 }