예제 #1
0
        //adding words to database
        private async void AddToDatabase(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(TranslatedText.Text))
            {
                string [] words = { ToTranslateText.Text.ToLower(), TranslatedText.Text.ToLower() };

                string languagePair = StringOperation.CreatingLangugePair(fromLanguageButton.Content.ToString(), toLanguageButton.Content.ToString());
                languagePair = languagePair.Replace("|", "");

                DatabaseConnection dbCon = new DatabaseConnection(languagePair);
                dbCon.InsertingValue(words[0], words[1]);

                if (dbCon.SearchingForWord(languagePair, words[0]))
                {
                    dbCon.IncreasingValue(languagePair, words[0]);
                }

                MessageDialog msg = new MessageDialog(String.Format("Added '{0} ➤ {1}' to {2} database!", words[0], words[1], languagePair));
                await msg.ShowAsync();

                ToTranslateText.Text = "";
                TranslatedText.Text  = "";
            }
            else
            {
                MessageDialog msg = new MessageDialog("You can't add empty translation to database!");
                await msg.ShowAsync();
            }
        }
예제 #2
0
        //translate two string with translate google app
        public async void GTranslateText()
        {
            if (!String.IsNullOrEmpty(ToTranslateText.Text))
            {
                try
                {
                    //erasing white spaces from string thats appear more then one time
                    Regex  regex           = new Regex("[ ]{2,}");
                    string toTranslateText = regex.Replace(ToTranslateText.Text.Trim(), " ");

                    //creating language pair to translation
                    string languagePair = StringOperation.CreatingLangugePair(fromLanguageButton.Content.ToString(), toLanguageButton.Content.ToString());

                    //translation
                    GTranslator translator = new GTranslator(toTranslateText, languagePair);

                    //added translation to textblock
                    TranslatedText.Text  = translator.translation;
                    ToTranslateText.Text = toTranslateText;
                }
                catch
                {
                    //if no internet connection
                    MessageDialog msg = new MessageDialog("You don't have an internet connection!");
                    await msg.ShowAsync();

                    ToTranslateText.Text = "";
                    TranslatedText.Text  = "";
                }
            }
        }