示例#1
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     if (BaseDataGrid.Items.Count > 0 && !Dialog.Ask("Translator", "Do you really wish to close?", "Don't forget to export your translation, if you started translating but not exported yet."))
         e.Cancel = true;
 }
示例#2
0
        private async void Load_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                AddExtension     = true,
                CheckFileExists  = true,
                Title            = "Open a Resource Dictionary",
                Filter           = "Resource Dictionay (*.xaml)|*.xaml;",
                InitialDirectory = Path.GetFullPath(TempPath)
            };

            var result = ofd.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            //Replaces the special chars.
            var text = await Task.Factory.StartNew(() => File.ReadAllText(ofd.FileName, Encoding.UTF8).Replace("&#", "&amp;#").Replace("<!--<!--", "<!--").Replace("-->-->", "-->"));

            await Task.Factory.StartNew(() => File.WriteAllText(ofd.FileName, text, Encoding.UTF8));

            var dictionary = await Task.Factory.StartNew(() => new ResourceDictionary { Source = new Uri(Path.GetFullPath(ofd.FileName), UriKind.Absolute) });

            _resourceList.Add(dictionary);

            var baseCulture     = FromComboBox.SelectedValue as string;
            var specificCulture = Path.GetFileName(ofd.FileName).Replace("StringResources.", "").Replace(".xaml", "");

            string properCulture;

            //Catching here, because we can access UI thread easily here to show dialogs
            try
            {
                properCulture = await Task.Factory.StartNew(() => CheckSupportedCulture(specificCulture));
            }
            catch (CultureNotFoundException)
            {
                Dialog.Ok("Action Denied", "Unknown Language.",
                          $"The \"{specificCulture}\" and its family were not recognized as a valid language codes.");

                return;
            }
            catch (Exception ex)
            {
                Dialog.Ok("Action Denied", "Error checking culture.", ex.Message);

                return;
            }

            if (properCulture != specificCulture)
            {
                Dialog.Ok("Action Denied", "Redundant Language Code.",
                          $"The \"{specificCulture}\" code is redundant. Try using \'{properCulture}\" instead");

                return;
            }

            ToComboBox.SelectedValue = specificCulture;

            ShowTranslations(baseCulture, specificCulture);

            BaseDataGrid.IsEnabled = true;
        }