示例#1
0
 private void context_CurrentResourceBundleChanged(object sender, EventArgs e)
 {
     // create a manager that will manage exclusion patterns, based on the patterns defined in the current
     // resource bundle
     this.exclusionManager = new ExclusionManager();
     exclusionManager.ExclusionPatterns = this.context.CurrentBaseResourceSet.Exclusions;
 }
示例#2
0
        public void ValidateTest()
        {
            // set up
            const string originalText = "Windows is an operating system created by Microsoft, which was founded by Bill Gates";
            const string correctTranslation = "Τα Windows είναι ένα λειτουργικό σύστημα που δημιουργήθηκε από την Microsoft, η οποία ιδρύθηκε από τον Bill Gates";
            const string incorrectTranslation = "Τα Παράθυρα είναι ένα λειτουργικό σύστημα που δημιουργήθηκε από την Microsoft, η οποία ιδρύθηκε από τον Bill Πύλες";

            var exclusionManager = new ExclusionManager();
            exclusionManager.ExclusionPatterns.Add(new Exclusion("Windows"));    // We want these words not to be translated
            exclusionManager.ExclusionPatterns.Add(new Exclusion("Gates"));    // We want these words not to be translated

            // correct case
            var actual = exclusionManager.Validate(correctTranslation, originalText);
            Assert.AreEqual(0, actual.Length);

            // incorrect case
            actual = exclusionManager.Validate(incorrectTranslation, originalText);
            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual("Windows", actual[0]);
            Assert.AreEqual("Gates", actual[1]);
        }
示例#3
0
        public void ExcludeRestoreTest()
        {
            // set up
            const string originalText = "Windows is an operating system created by Microsoft, which was founded by Bill Gates";

            var exclusionManager = new ExclusionManager();
            exclusionManager.ExclusionPatterns.Add(new Exclusion("Windows"));    // We want these words not to be translated
            exclusionManager.ExclusionPatterns.Add(new Exclusion("Gates"));    // We want these words not to be translated

            // run 1
            var textWithExclusions = exclusionManager.Exclude(originalText);

            // assert 1
            Assert.AreEqual("[### 0 ###] is an operating system created by Microsoft, which was founded by Bill [### 1 ###]", textWithExclusions);

            // run 2
            var restoredText = exclusionManager.Restore(textWithExclusions);

            // assert 2
            Assert.AreEqual(originalText, restoredText);
        }
示例#4
0
        private void CustomDataGrid1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (CustomDataGrid1.MainDataGridView.Columns[e.ColumnIndex].Name == ColumnNames.LocalValue)
            {
                DataGridViewRow row = CustomDataGrid1.MainDataGridView.Rows[e.RowIndex];
                ResourceItem baseResourceItem = (ResourceItem)row.Tag;
                object localValue = row.Cells[ColumnNames.LocalValue].Value;
                object baseValue = baseResourceItem.Value;

                if (baseResourceItem is ResourceStringItem)
                {
                    ResourceStringItem baseResourceStringItem = baseResourceItem as ResourceStringItem;

                    // check for ampersands (&)
                    if (!StringTools.ValueNullOrEmpty(localValue) && !StringTools.ValueNullOrEmpty(baseValue))
                    {
                        if (StringTools.CountInstances(localValue.ToString(), "&", StringComparison.Ordinal) != StringTools.CountInstances(baseValue.ToString(), "&", StringComparison.Ordinal))
                        {
                            const string Message = "The ampersands (&) of base value do not much with the local value. Is this correct?";
                            if (MessageBox.Show(Message, Tools.GetAssemblyProduct(), MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                e.Cancel = true;
                                return;
                            }
                        }
                    }

                    // check for placeholders in strings
                    if (!StringTools.ValueNullOrEmpty(localValue) && !StringTools.ValueNullOrEmpty(baseValue))
                    {
                        int counter = 0;
                        string counterElement = "{0}";
                        while (true)
                        {
                            if (baseValue.ToString().IndexOf(counterElement) == -1)
                            {
                                break;
                            }

                            if (localValue.ToString().IndexOf(counterElement) == -1)
                            {
                                string message = String.Format(My.Resources.Local.PlaceholderExpectedError, counterElement);
                                MessageBox.Show(message, Tools.GetAssemblyProduct(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                                e.Cancel = true;
                                return;
                            }

                            counter += 1;
                            counterElement = "{" + counter + "}";
                        }
                    }

                    // check for max length
                    if (!StringTools.ValueNullOrEmpty(localValue))
                    {
                        if (baseResourceStringItem.MaxLength != ResourceStringItem.UnlimitedLength)
                        {
                            if (localValue.ToString().Length > baseResourceStringItem.MaxLength)
                            {
                                string message = String.Format(My.Resources.Local.MaximumLengthError, baseResourceStringItem.MaxLength, localValue.ToString().Length);
                                MessageBox.Show(message, Tools.GetAssemblyProduct(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                                e.Cancel = true;
                                return;
                            }
                        }
                    }

                    // check for exclusions
                    if (!StringTools.ValueNullOrEmpty(localValue) && !StringTools.ValueNullOrEmpty(baseValue))
                    {
                        var manager = new ExclusionManager();
                        manager.ExclusionPatterns = this.Context.CurrentBaseResourceSet.Exclusions;
                        var notExcludedExclusion = manager.Validate(localValue.ToString(), baseValue.ToString());
                        if (notExcludedExclusion != null && notExcludedExclusion.Length > 0)
                        {
                            var message = string.Format("The following terms of base item should not be translated. See Exclusions list for more information.\r\n\r\n{0}\r\n\r\nFix your translation so that these terms exist.", string.Join(", ", notExcludedExclusion));
                            MessageBox.Show(message, Tools.GetAssemblyProduct(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                            e.Cancel = true;
                            return;
                        }
                    }
                }
            }
        }