예제 #1
0
        /// <summary>
        /// Handles the Click event of the loadTmxToolStripMenuItem 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 loadTmxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create an instance of the open file dialog box.
            var openFileDialog = new OpenFileDialog
            {
                Filter =
                    Resources
                    .ResourceTranslatorForm_loadTmxToolStripMenuItem_Click_Text_Files___tmx____tmx_All_Files__________,
                FilterIndex = 1,
                Multiselect = false
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                tmxStatusLabel.Text = _controller.InitTmx(openFileDialog.FileName);
                destLocaleBtn.DropDownItems.Clear();
                foreach (var destinationCulture in _controller.GetDestinationCultures())
                {
                    destLocaleBtn.DropDownItems.Add(destinationCulture.ToString());
                }
                destLocaleBtn.Text  = _controller.SessionModel.DestinationLanguage.ToString();
                startButton.Enabled = _controller.IsReadyToTranslate();
                loadTmxToolStripMenuItem.Enabled = false;
            }
        }
예제 #2
0
        /// <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!");
        }