Skip to content

Commit

Permalink
* Trim hard returns in the paragraph content being imported from word…
Browse files Browse the repository at this point in the history
… format.

* Introduced an information icon that is available directly right of the label 'Exclude Segments' with the following tool tip:
- Export Wizard: Exclude segments from being exported that match the properties selected.
- Import Wizard: Exclude segments from being updated that match the properties selected.
  • Loading branch information
Impertatore committed Mar 11, 2021
1 parent 960a78f commit fe3d357
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private UpdatedSegmentContent ProcessTargetCellContent(string segmentIdCell, Tab
CheckParagraphCount(targetCell);
currentContentList.TranslationHasTrackedChanges = SegmentHasChanges(targetCell);

var translationContent = targetCell.GetFirstChild<Paragraph>();
var translationContent = GetParagraphsTrimed(targetCell).FirstOrDefault();
if (translationContent != null)
{
var tagBuffer = "";//sometimes word is so stupid that tags are not in single runs, buffering is required.
Expand All @@ -177,7 +177,7 @@ private UpdatedSegmentContent ProcessTargetCellContent(string segmentIdCell, Tab
currentContentList.TranslationTokens = translationTokens;
}

var backTranslationContent = backTranslationCell?.GetFirstChild<Paragraph>();
var backTranslationContent = GetParagraphsTrimed(backTranslationCell).FirstOrDefault();
if (backTranslationContent != null)
{
CheckParagraphCount(backTranslationCell);
Expand Down Expand Up @@ -322,12 +322,64 @@ private void ProcessOpenXmlElement(OpenXmlElement item, ref List<Token> tokens,
/// <param name="targetCell"></param>
private void CheckParagraphCount(TableCell targetCell)
{
if (targetCell.Elements<Paragraph>().Count() > 1)
var paragraphs = GetParagraphsTrimed(targetCell);
if (paragraphs.Count > 1)
{
throw new TooManyParagraphsException();
}
}

private static List<Paragraph> GetParagraphsTrimed(TableCell targetCell)
{
if (targetCell == null)
{
return new List<Paragraph>();
}

var allParagraphs = targetCell.Elements<Paragraph>().ToList();
var excludeIndexes = new List<int>();
for (var i = 0; i < allParagraphs.Count; i++)
{
if (string.IsNullOrEmpty(allParagraphs[i].InnerText.Trim()))
{
if (!excludeIndexes.Contains(i))
{
excludeIndexes.Add(i);
}
}
else
{
break;
}
}

for (var i = allParagraphs.Count - 1; i >= 0; i--)
{
if (string.IsNullOrEmpty(allParagraphs[i].InnerText.Trim()))
{
if (!excludeIndexes.Contains(i))
{
excludeIndexes.Add(i);
}
}
else
{
break;
}
}

var paragraphs = new List<Paragraph>();
for (var i = 0; i < allParagraphs.Count; i++)
{
if (!excludeIndexes.Contains(i))
{
paragraphs.Add(allParagraphs[i]);
}
}

return paragraphs;
}

private void ProcessTextRun(ref List<Token> tokens, Run textRun, ref string tagbuffer)
{
string tagContent = "";
Expand Down
18 changes: 18 additions & 0 deletions SDLTranscreate/SDLTranscreate/PluginResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions SDLTranscreate/SDLTranscreate/PluginResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,10 @@
<data name="Question" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\question.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ToolTip_Label_ExcludeSegments_Import" xml:space="preserve">
<value>Exclude segments from being updated that match the properties selected.</value>
</data>
<data name="ToolTip_Label_ExcludeSegments_Export" xml:space="preserve">
<value>Exclude segments from being exported that match the properties selected.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion SDLTranscreate/SDLTranscreate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.4.12")]
[assembly: AssemblyFileVersion("2.0.4.15")]
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
IsEnabled="{Binding OverwriteExistingBackTranslationsEnabled}"
IsChecked="{Binding OverwriteExistingBackTranslations, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Image Grid.Row="0" Grid.Column="1" Margin="0,0,0,0" VerticalAlignment="Center" Stretch="UniformToFill"
Width="16" Height="16" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"
Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"
Source="../../../Resources/information.png"
ToolTip="{Binding OverwriteExistingBackTranslationsToolTip, Mode=OneWay}"/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock VerticalAlignment="Center" Text="Exclude Segments" Style="{StaticResource TextBlockColor}" Margin="5,10,5,5"/>
<Grid Grid.Row="0" Margin="5,10,5,5">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center"
Text="Exclude Segments" Style="{StaticResource TextBlockColor}" />
<Image Margin="5,0,0,0" VerticalAlignment="Center" Stretch="UniformToFill"
Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"
Source="../../../Resources/information.png"
ToolTip="{Binding ExcludeSegmentsToolTip, Mode=OneWay}"/>
</StackPanel>
</Grid>


<sdl:MultiSelectComboBox Grid.Row="1" Grid.Column="0"
Margin="5,0,5,0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,17 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock VerticalAlignment="Center" Text="Exclude Segments" Style="{StaticResource TextBlockColor}" Margin="5,10,5,5"/>
<Grid Grid.Row="0" Margin="5,10,5,5">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center"
Text="Exclude Segments" Style="{StaticResource TextBlockColor}"
/>
<Image Margin="5,0,0,0" VerticalAlignment="Center" Stretch="UniformToFill"
Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased"
Source="../../../Resources/information.png"
ToolTip="{Binding ExcludeSegmentsToolTip, Mode=OneWay}"/>
</StackPanel>
</Grid>

<sdl:MultiSelectComboBox Grid.Row="1" Grid.Column="0"
Margin="5,0,5,0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public WizardPageExportOptionsViewModel(Window owner, object view, TaskContext t

public ICommand SelectedItemsChangedCommand => _selectedItemsChangedCommand ?? (_selectedItemsChangedCommand = new CommandHandler(SelectedItemsChanged));

public string ExcludeSegmentsToolTip => PluginResources.ToolTip_Label_ExcludeSegments_Export;

public List<FilterItem> FilterItems
{
get => _filterItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public string OriginSystem
}
}

public string ExcludeSegmentsToolTip => PluginResources.ToolTip_Label_ExcludeSegments_Import;

public List<FilterItem> FilterItems
{
get => _filterItems;
Expand Down
2 changes: 1 addition & 1 deletion SDLTranscreate/SDLTranscreate/pluginpackage.manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PluginPackage xmlns="http://www.sdl.com/Plugins/PluginPackage/1.0">
<PlugInName>Trados Transcreate</PlugInName>
<Version>2.0.4.12</Version>
<Version>2.0.4.15</Version>
<Description>Trados Transcreate is a plugin for Trados Studio designed to help manage the Transcreation process.</Description>
<Author>Community Developers</Author>
<RequiredProduct name="SDLTradosStudio" minversion="16.1" />
Expand Down

0 comments on commit fe3d357

Please sign in to comment.