/// <summary> /// Translates a given text to a target language. /// </summary> /// <param name="text">The content to translate.</param> /// <param name="targetLanguage">Required. Target language code.</param> public string TranslateText(string text = "[TEXT_TO_TRANSLATE]", string targetLanguage = "en") { Google.Cloud.Translation.V2.TranslationClient translationServiceClient = Google.Cloud.Translation.V2.TranslationClient.Create(); TranslationResult response = translationServiceClient.TranslateText(text, targetLanguage, "ja"); return(response.TranslatedText); }
public MainForm() { InitializeComponent(); dataContext = new DBClassesDataContext(); languageService = new LanguageService(dataContext); wordService = new WordService(dataContext); translationDBservice = new TranslationDBService(dataContext); applicationSettingsService = new ApplicationSettingsService(dataContext); titleToShortTitleMap = new Dictionary <String, String>(); selectLanguageComboBox.SelectedItem = "All"; //default insertLanguageComboBox.SelectedItem = "Polish"; //default isInternetAccess = checkInternetConnection(); if (isInternetAccess) { System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\\Programming\\IPNew\\IPV\\IP\\Inzenyria_programowania-ce5078cd8d32.json"); client = Google.Cloud.Translation.V2.TranslationClient.Create(); googleTranslate = new TranslationAPIService(client); foreach (Google.Cloud.Translation.V2.Language language in client.ListLanguages("en")) { if (languageService.checkIfLanguageExistsInDB(language.Name)) { insertLanguageComboBox.Items.Add(language.Name); titleToShortTitleMap.Add(language.Name, language.Code); } } } else { MessageBox.Show("Looks like you don't have internet connection, you can't add words, you can only exercise them."); } }