Exemple #1
0
	public static void Report (string message) {
		string bugInfo = GetBugInfo(message);
		Console.Error.WriteLine(bugInfo);

		try {
			RunBugBuddy(bugInfo);
		}
		catch (Exception) {
			BasicErrorDialog errorDialog = new BasicErrorDialog(noBugBuddyPrimaryMessage, noBugBuddySecondaryMessage);
			errorDialog.Show();
		}
	}
	private bool DoTranslation () {
		if (Base.Ui.View.Selection.Count != 1) //TODO: for now, only works if 1 subtitle is selected
			return false;

		/* Show language selection dialogs if no languages are selected */
		if (!Base.SpellLanguages.HasActiveTextLanguage) {
			Base.Dialogs.Get(typeof(SetTextLanguageDialog)).Show();
			if (!Base.SpellLanguages.HasActiveTextLanguage)
				return false;
		}

		if (!Base.SpellLanguages.HasActiveTranslationLanguage) {
			Base.Dialogs.Get(typeof(SetTranslationLanguageDialog)).Show();
			if (!Base.SpellLanguages.HasActiveTranslationLanguage)
				return false;
		}

		try {
			Subtitle subtitle = Base.Document.Subtitles[Path];
			if (leftToRight) {
				this.previousValue = subtitle.Translation.Get();
				string translatedText = Translator.TranslateText(subtitle.Text.Get(), Base.SpellLanguages.ActiveTextLanguage.ID, Base.SpellLanguages.ActiveTranslationLanguage.ID, Translator.TIMEOUT);
				subtitle.Translation.Set(translatedText);
			}
			else {
				this.previousValue = subtitle.Text.Get();
				string translatedText = Translator.TranslateText(subtitle.Translation.Get(), Base.SpellLanguages.ActiveTranslationLanguage.ID, Base.SpellLanguages.ActiveTextLanguage.ID, Translator.TIMEOUT);
				subtitle.Text.Set(translatedText);
			}

			//TODO: if only one subtitle selected, set the cursor on the translated text box and select its text. If multiple subtitles translated, select those subtitles.
			return true;
		}
		catch (TranslatorException e) { //TODO know which exceptions are originally thrown. Check if it's possible to have the second error message in the application language.
			Console.Error.WriteLine(e);
			BasicErrorDialog errorDialog = new BasicErrorDialog(Catalog.GetString("Could not translate the chosen subtitle."), e.Message);
			errorDialog.Show();
			return false;
		}
	}