Esempio n. 1
0
        /// <summary>
        /// Create a new TranslationUnit object
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="sourceCulture"></param>
        /// <param name="targetCulture"></param>
        /// <returns></returns>
        private TranslationUnit GetNewTU(string source, string target, CultureInfo sourceCulture, CultureInfo targetCulture)
        {
            TranslationUnit tu = new TranslationUnit();

            tu.SourceSegment = new Segment(sourceCulture);
            tu.TargetSegment = new Segment(targetCulture);

            tu.SourceSegment.Add(source);
            tu.TargetSegment.Add(target);

            MultiplePicklistFieldValue picklistValue = new MultiplePicklistFieldValue("Sample field");

            picklistValue.Add("yes");

            tu.FieldValues.Add(picklistValue);

            MultipleStringFieldValue stringValue = new MultipleStringFieldValue("Sample text field");

            stringValue.Add("new item");
            stringValue.Add("new project");

            tu.FieldValues.Add(stringValue);

            //add structure context info
            tu.StructureContexts = new string[] { "H" };

            return(tu);
        }
Esempio n. 2
0
        /// <summary>
        /// Change target segment content of existing TU
        /// </summary>
        /// <param name="tmPath"></param>
        /// <param name="searchedText"></param>
        /// <param name="newTarget"></param>
        public void AdaptTU(string tmPath, string searchedText, string newTarget)
        {
            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath);
            SearchResults results         = tm.LanguageDirection.SearchText(GetSearchSettings(), searchedText);

            foreach (SearchResult item in results)
            {
                if (item.ScoringResult.Match == 100)
                {
                    item.MemoryTranslationUnit.TargetSegment.Clear();//remove existing target segment content
                    item.MemoryTranslationUnit.TargetSegment.Add(newTarget);
                    item.MemoryTranslationUnit.SystemFields.UseCount++;


                    MultiplePicklistFieldValue picklistValue = new MultiplePicklistFieldValue("Sample field");
                    picklistValue.Add("yes");
                    item.MemoryTranslationUnit.FieldValues.Add(picklistValue);

                    MultipleStringFieldValue stringValue = new MultipleStringFieldValue("Sample text field");
                    stringValue.Add("new item");
                    stringValue.Add("new project");
                    item.MemoryTranslationUnit.FieldValues.Add(stringValue);

                    WriteResult("TU found and changed.");
                    break;
                }
            }
        }
Esempio n. 3
0
        private FilterExpression GetFilter()
        {
            #region "SimpleCriterion"
            PicklistItem fieldName = new PicklistItem("Customer");
            MultiplePicklistFieldValue fieldValue = new MultiplePicklistFieldValue("Microsoft");
            fieldValue.Add(fieldName);
            #endregion

            #region "SimpleFilter"
            AtomicExpression filter = new AtomicExpression(fieldValue, AtomicExpression.Operator.Equal);
            return(filter);

            #endregion
        }
Esempio n. 4
0
        private FilterExpression GetExportFilter()
        {
            PicklistItem i1 = new PicklistItem("Sample field");
            MultiplePicklistFieldValue v1 = new MultiplePicklistFieldValue("yes");

            v1.Add(i1);
            AtomicExpression e1 = new AtomicExpression(v1, AtomicExpression.Operator.Contains);

            MultipleStringFieldValue v2 = new MultipleStringFieldValue("Sample text field");

            v2.Add("new item");
            AtomicExpression e2 = new AtomicExpression(v2, AtomicExpression.Operator.Contains);

            ComposedExpression filter = new ComposedExpression(e1, ComposedExpression.Operator.Or, e2);

            return(filter);
        }
        public void AddTu(string tmPath)
        {
            #region "open"
            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath);

            TranslationUnit tu = new TranslationUnit();
            #endregion

            #region "segments"
            tu.SourceSegment = new Segment(tm.LanguageDirection.SourceLanguage);
            tu.TargetSegment = new Segment(tm.LanguageDirection.TargetLanguage);

            tu.SourceSegment.Add("A dialog box will open.");
            tu.TargetSegment.Add("Es öffnet sich ein Dialogfenster.");
            #endregion

            #region "AddField"
            MultiplePicklistFieldValue value = new MultiplePicklistFieldValue("Customer");
            value.Add("Microsoft");
            tu.FieldValues.Add(value);
            #endregion

            #region "ConfirmationLevel"
            tu.ConfirmationLevel = ConfirmationLevel.ApprovedTranslation;
            #endregion

            #region "format"
            tu.Format = TranslationUnitFormat.SDLTradosStudio2009;
            #endregion

            #region "origin"
            tu.Origin = TranslationUnitOrigin.TM;
            #endregion

            #region "StuctureContext"
            tu.StructureContexts = new string[] { "H" };
            #endregion

            #region "AddTu"
            tm.LanguageDirection.AddTranslationUnit(tu, this.GetImportSettings());
            tm.Save();
            MessageBox.Show("TU has been added successfully.");
            #endregion
        }
        private FilterExpression GetFilterAdvanced()
        {
            #region "AdvancedCriterion1"
            PicklistItem fieldName1 = new PicklistItem("Customer");
            MultiplePicklistFieldValue fieldValue1 = new MultiplePicklistFieldValue("Microsoft");
            fieldValue1.Add(fieldName1);
            AtomicExpression expression1 = new AtomicExpression(fieldValue1, AtomicExpression.Operator.Equal);
            #endregion

            #region "AdvancedCriterion2"
            MultipleStringFieldValue fieldName2 = new MultipleStringFieldValue("Project id");
            fieldName2.Add("2010");
            AtomicExpression expression2 = new AtomicExpression(fieldName2, AtomicExpression.Operator.Contains);
            #endregion

            #region "AdvancedFilter"
            ComposedExpression filter = new ComposedExpression(expression1, ComposedExpression.Operator.Or, expression2);
            return(filter);

            #endregion
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the translation unit as it is later shown in the Translation Results
        /// window of SDL Trados Studio. This member also determines the match score
        /// (in our implementation always 100%, as only exact matches are supported)
        /// as well as the confirmation lelvel, i.e. Translated.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="searchSegment"></param>
        /// <param name="searchResultSegment"></param>
        /// <param name="sourceSegment"></param>
        /// <param name="formattingPenalty"></param>
        /// <returns></returns>

        #region "CreateSearchResult"
        private SearchResult CreateSearchResult(SearchSettings settings, Segment searchSegment, Sdl.Community.Taus.TM.Provider.Segment.Segment searchResultSegment,
                                                string sourceSegment, bool formattingPenalty)
        {
            #region "TranslationUnit"
            var tu = new TranslationUnit();



            var searchSegmentSource = new Segment();
            var searchSegmentTarget = new Segment();



            searchSegmentSource.Add(searchResultSegment.SourceText);
            searchSegmentTarget.Add(searchResultSegment.TargetText);


            tu.SourceSegment = searchSegmentSource;
            tu.TargetSegment = searchSegmentTarget;

            tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty);

            #endregion


            #region "TuProperties"
            var score = Convert.ToInt32(searchResultSegment.MatchPercentage);
            tu.Origin = TranslationUnitOrigin.TM;

            #region  |  properties  |
            if (searchResultSegment.Industry.Name.Trim() != string.Empty)
            {
                var fieldValue = new MultiplePicklistFieldValue("industry");
                fieldValue.Add(searchResultSegment.Industry.Name + " [" + searchResultSegment.Industry.Id + "]");
                tu.FieldValues.Add(fieldValue);
            }
            if (searchResultSegment.ContentType.Name.Trim() != string.Empty)
            {
                var fieldValue = new MultiplePicklistFieldValue("contentType");
                fieldValue.Add(searchResultSegment.ContentType.Name + " [" + searchResultSegment.ContentType.Id + "]");
                tu.FieldValues.Add(fieldValue);
            }
            if (searchResultSegment.Owner.Name.Trim() != string.Empty)
            {
                var fieldValue = new MultiplePicklistFieldValue("owner");
                fieldValue.Add(searchResultSegment.Owner.Name + " [" + searchResultSegment.Owner.Id + "]");
                tu.FieldValues.Add(fieldValue);
            }
            if (searchResultSegment.Product.Name.Trim() != string.Empty)
            {
                var fieldValue = new MultiplePicklistFieldValue("product");
                fieldValue.Add(searchResultSegment.Product.Name + " [" + searchResultSegment.Product.Id + "]");
                tu.FieldValues.Add(fieldValue);
            }
            if (searchResultSegment.Provider.Name.Trim() != string.Empty)
            {
                var fieldValue = new MultiplePicklistFieldValue("provider");
                fieldValue.Add(searchResultSegment.Provider.Name + " [" + searchResultSegment.Provider.Id + "]");
                tu.FieldValues.Add(fieldValue);
            }

            #endregion



            var searchResult = new SearchResult(tu)
            {
                ScoringResult = new ScoringResult {
                    BaseScore = score
                }
            };


            if (settings.Mode == SearchMode.ConcordanceSearch)
            {
                searchSegmentSource.Tokens = Tokenize(searchSegmentSource);
                searchResult.ScoringResult.MatchingConcordanceRanges = CollectConcordanceMatchRanges(searchSegmentSource, _visitor.PlainText);
            }
            else if (settings.Mode == SearchMode.TargetConcordanceSearch)
            {
                searchSegmentTarget.Tokens = Tokenize(searchSegmentTarget);
                searchResult.ScoringResult.MatchingConcordanceRanges = CollectConcordanceMatchRanges(searchSegmentTarget, _visitor.PlainText);
            }

            var providerPenalty = settings.FindPenalty(PenaltyType.ProviderPenalty);
            if (providerPenalty != null && providerPenalty.Malus > 0)
            {
                var penalty = new Penalty(PenaltyType.ProviderPenalty, settings.FindPenalty(PenaltyType.ProviderPenalty).Malus);
                searchResult.ScoringResult.ApplyPenalty(penalty);
            }

            if (searchResult.ScoringResult.BaseScore >= settings.MinScore)
            {
                searchResult.TranslationProposal = searchResult.MemoryTranslationUnit;

                if (searchSegment.HasTags)
                {
                    #region "Draft"
                    tu.ConfirmationLevel = ConfirmationLevel.Draft;
                    #endregion

                    #region "FormattingPenalty"
                    var penalty = new Penalty(PenaltyType.MemoryTagsDeleted, settings.FindPenalty(PenaltyType.MemoryTagsDeleted).Malus);
                    searchResult.ScoringResult.ApplyPenalty(penalty);
                    #endregion
                }
                else
                {
                    tu.ConfirmationLevel = ConfirmationLevel.Translated;
                }
            }
            else
            {
                searchResult = null;
            }
            #endregion

            return(searchResult);
        }
Esempio n. 8
0
        public void ConfigureTmSettings(FileBasedProject project)
        {
            #region "GetSettingsBundle"
            ISettingsBundle           settings   = project.GetSettings();
            TranslationMemorySettings tmSettings = settings.GetSettingsGroup <TranslationMemorySettings>();
            #endregion

            #region "TmSearchSettings"
            tmSettings.TranslationMinimumMatchValue.Value = 80;
            tmSettings.TranslationMaximumResults.Value    = 10;
            tmSettings.TranslationFullSearch.Value        = true;
            #endregion

            #region "ConcordanceSettings"
            tmSettings.ConcordanceMinimumMatchValue.Value = 30;
            tmSettings.ConcordanceMaximumResults.Value    = 50;
            #endregion

            #region "Penalties"
            tmSettings.MissingFormattingPenalty.Value    = 0;
            tmSettings.DifferentFormattingPenalty.Value  = 0;
            tmSettings.MultipleTranslationsPenalty.Value = 2;
            #endregion

            #region "AutoLocalization"
            tmSettings.NumbersAutoLocalizationEnabled.Value      = true;
            tmSettings.DatesAutoLocalizationEnabled.Value        = true;
            tmSettings.MeasurementsAutoLocalizationEnabled.Value = true;
            tmSettings.TimesAutoLocalizationEnabled.Value        = true;
            #endregion

            #region "DatePatterns"
            tmSettings.ShortDatePattern.Value = "dd.MM.yy";
            #endregion

            #region "FieldUpdate"
            FieldValues fieldValuesCollection = new FieldValues();
            FileBasedTranslationMemory tm     = new FileBasedTranslationMemory(@"c:\ProjectFiles\Tms\General En-De.sdltm");
            FieldDefinition            field  = tm.FieldDefinitions["Type"];
            FieldValue fv = field.CreateValue();
            fv.Name = "Technical documentation";
            fieldValuesCollection.Add(fv);
            tmSettings.ProjectSettings.Value = fieldValuesCollection;
            #endregion

            #region "TmFilterPenalty"
            PicklistItem fieldName = new PicklistItem("Type");
            MultiplePicklistFieldValue fieldValue = new MultiplePicklistFieldValue("Technical documentation");
            fieldValue.Add(fieldName);

            AtomicExpression filter       = new AtomicExpression(fieldValue, AtomicExpression.Operator.Equal);
            Filter           updateFilter = new Filter(filter, "Filter_name", 1);
            List <Filter>    filterList   = new List <Filter>();
            filterList.Add(updateFilter);

            tmSettings.Filters.Value = filterList;
            #endregion

            #region "TmHardFilter"
            PicklistItem hardFilterFieldName = new PicklistItem("Type");
            MultiplePicklistFieldValue hardFilterFieldValue = new MultiplePicklistFieldValue("Technical documentation");
            hardFilterFieldValue.Add(hardFilterFieldName);
            AtomicExpression hardFilterExpression = new AtomicExpression(hardFilterFieldValue, AtomicExpression.Operator.Equal);
            tmSettings.HardFilter.Value = hardFilterExpression;
            #endregion

            #region "update"
            project.UpdateSettings(settings);
            #endregion
        }