/// <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; } } }
/// <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); }
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); }
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 }
/// <summary> /// Change default import settigns /// </summary> /// <param name="importSettings"></param> private void AdaptImportSettigns(ImportSettings importSettings) { importSettings.CheckMatchingSublanguages = true; importSettings.ExistingTUsUpdateMode = TUUpdateMode.Overwrite; //set behavior of existing field values during import importSettings.ExistingFieldsUpdateMode = ImportSettings.FieldUpdateMode.Merge; //set behavior of new fields during import importSettings.NewFields = ImportSettings.NewFieldsOption.AddToSetup; //create a field (now using field already existing in the TM setup) //set the field value object MultipleStringFieldValue cruVal = new MultipleStringFieldValue("Sample text field"); //add new value (this time we use multiple string field value cruVal.Add("Added during import"); //create field values object FieldValues fields = new FieldValues(); //add the field value fields.Add(cruVal); //set the field values to the import settigns importSettings.ProjectSettings = fields; }