コード例 #1
0
        public void loadModel()
        {
            StringBuilder engine = new StringBuilder(255);

            Win32.GetPrivateProfileString("ENGINE", "engine", "", engine, 255, dataSourcePath);

            if (engine.ToString().Equals("BING"))
            {
                model.setEngine(TranslateSettingsModel.Engine.BING);
            }
            else
            {
                model.setEngine(TranslateSettingsModel.Engine.MYMEMORY);
            }

            StringBuilder email = new StringBuilder(255);

            Win32.GetPrivateProfileString("MYMEMORY", "email", "", email, 255, dataSourcePath);

            model.email = email.ToString();

            StringBuilder clientCred = new StringBuilder(255);

            Win32.GetPrivateProfileString("BING", "ClientIDAndSecret", "", clientCred, 255, dataSourcePath);

            if (clientCred.ToString().Contains(";"))
            {
                model.setClientCredentials(new Pair(clientCred.ToString().Split(';')[0], clientCred.ToString().Split(';')[1]));
            }

            StringBuilder allLangs = new StringBuilder(1023);

            Win32.GetPrivateProfileString("TRANSLATE", "ALLLANGUAGES", "", allLangs, 1023, dataSourcePath);

            if (allLangs.ToString().Contains(";"))
            {
                List <Pair> allLanguages = new List <Pair>();

                string[] allLangPair = allLangs.ToString().Split(';');

                foreach (string codeNamePair in allLangPair)
                {
                    string[] pair = codeNamePair.Split(':');
                    allLanguages.Add(new Pair(pair[0], pair[1]));
                }
                model.setAllLanguages(allLanguages);
            }

            StringBuilder langPref = new StringBuilder(255);

            Win32.GetPrivateProfileString("TRANSLATE", "LANGUAGEPREF", "", langPref, 255, dataSourcePath);

            if (langPref.ToString().Contains(":"))
            {
                string[] pref = langPref.ToString().Split(':');
                model.setLanguagePreference(new Pair(pref[0], pref[1]));
            }
        }
コード例 #2
0
        internal static Boolean initLanguages()
        {
            try
            {
                if (trSettingsModel.getAllLanguages().Count == 0)
                {
                    Util.writeInfoLog("All languages empty in the model, trying to fetch..");

                    List <Pair> fetchedList = new List <Pair>();
                    fetchedList.AddRange(translateEngine.GetSupportedLanguages());
                    trSettingsModel.setAllLanguages(fetchedList);
                    trSettingsModel.setLanguagePreference(translateEngine.getDefaultLanguagePreference());
                }
                return(true);
            }
            catch (Exception ex)
            {
                handleException(ex);
                return(false);
            }
        }