/// <summary> /// Handles the Click event of the loadSourceResxToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void loadSourceResxToolStripMenuItem_Click(object sender, EventArgs e) { /* Create an instance of the open file dialog box. */ var openFileDialog = new OpenFileDialog { Filter = Resources.ResourceTranslatorForm_loadSourceResxToolStripMenuItem_Click_Text_Files___resx____resx_All_Files__________, FilterIndex = 1, Multiselect = false }; /* Set filter options and filter index. */ if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } resxStatusLabel.Text = _controller.InitResx(openFileDialog.FileName); _resxFilename = openFileDialog.SafeFileName; /* detect language from filename or set default en-US */ Match match = Regex.Match(openFileDialog.FileName, @"\.[a-z]{2}(-[A-Z]{2})?\.", RegexOptions.None); String srcLocale = match.ToString().Replace(".", ""); if (String.IsNullOrEmpty(srcLocale)) { srcLocale = "en-US"; Debug.Assert(_resxFilename != null, "_resxFilename != null"); _resxFilename = _resxFilename.Replace(".resx", ".en-US.resx"); } srcLocaleLabel.Text = srcLocale; startButton.Enabled = _controller.IsReadyToTranslate(); _bindingSource.DataSource = _controller.SessionModel.TranslationItems; loadSourceResxToolStripMenuItem.Enabled = false; }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { String exportFilename = null; Boolean updateTmxFile = false; Boolean useExternalTranslator = false; CultureInfo destinationLocale = null; /* initialize options */ for (int i = 0; i < args.Length; ++i) { string s = args[i]; if (s.StartsWith("-r")) { _resxFileName = args[i + 1]; } if (s.StartsWith("-l")) { destinationLocale = new CultureInfo(args[i + 1]); } if (s.StartsWith("-t")) { _tmxFilename = args[i + 1]; } if (s.StartsWith("-e")) { exportFilename = args[i + 1]; } if (s.StartsWith("-p")) { _projectExportFilename = args[i + 1]; } if (s.StartsWith("-f")) { _fuzziness = Double.Parse(args[i + 1]); } if (s.StartsWith("-g")) { useExternalTranslator = true; } if (s.StartsWith("-u")) { updateTmxFile = true; } if (s.StartsWith("-h")) { Usage(); return; } Console.WriteLine(s); } if (String.IsNullOrEmpty(exportFilename)) { Match match = Regex.Match(_resxFileName, @"\.[a-z]{2}(-[A-Z]{2})?\.", RegexOptions.None); String srcLocale = match.ToString().Replace(".", ""); if (!String.IsNullOrEmpty(srcLocale) && null != destinationLocale) { exportFilename = _resxFileName.Replace(srcLocale, destinationLocale.ToString()); } } /* check if all needed parameters are set */ if (String.IsNullOrEmpty(exportFilename) || String.IsNullOrEmpty(_resxFileName) || String.IsNullOrEmpty(_tmxFilename)) { Usage(); return; } /* init controller */ _controller = new TranslatorController { ExportFileName = exportFilename }; _controller.SessionModel.Fuzziness = _fuzziness; _controller.SessionModel.UpdateTmxFile = updateTmxFile; _controller.SessionModel.UseExternalTranslator = useExternalTranslator; try { Console.WriteLine(_controller.InitResx(_resxFileName)); } catch (Exception e) { Console.WriteLine(e.Message); return; } try { Console.WriteLine(_controller.InitTmx(_tmxFilename)); } catch (Exception e) { Console.WriteLine(e.Message); return; } if (destinationLocale != null) { _controller.SessionModel.DestinationLanguage = destinationLocale; } if (_controller.IsReadyToTranslate()) { /* we need to spawn a background worker here. * This is done, because the GUI has to do the * stuff in background to stay responsive and * both GUI and CLI sharing the same controller methods. */ Console.WriteLine("Translating..."); var backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; backgroundWorker.ProgressChanged += bw_ProgressChanged; backgroundWorker.RunWorkerCompleted += bw_RunWorkerCompleted; backgroundWorker.DoWork += _controller.PerformTranslations; backgroundWorker.RunWorkerAsync(); /* wait until all other tasks are finished */ while (!_isFinished) { Thread.Sleep(1000); } } else { Console.WriteLine("Not ready to translate"); } Console.WriteLine("Application will exit now!"); }