This commit is contained in:
niksedk 2014-10-05 09:49:53 +02:00
parent a57e593411
commit b6f514a2cf
2 changed files with 93 additions and 10 deletions

View File

@ -201,6 +201,15 @@ namespace Nikse.SubtitleEdit.Forms
return "en";
return ci.TwoLetterISOLanguageName;
}
set
{
for (int index = 0; index < comboBoxLanguage.Items.Count; index++)
{
var item = comboBoxLanguage.Items[index];
if (item.ToString() == value)
comboBoxLanguage.SelectedIndex = index;
}
}
}
public void RunBatch(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language)
@ -1335,6 +1344,7 @@ namespace Nikse.SubtitleEdit.Forms
public void FixMissingSpaces()
{
string languageCode = Language;
string fixAction = _language.FixMissingSpace;
int missingSpaces = 0;
for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
@ -1347,17 +1357,19 @@ namespace Nikse.SubtitleEdit.Forms
{
while (match.Success)
{
if (!@"""”<.".Contains(p.Text[match.Index + 2]))
{
if (AllowFix(p, fixAction))
{
_totalFixes++;
missingSpaces++;
bool doFix = !@"""”<.".Contains(p.Text[match.Index + 2]);
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]);
AddFixToListView(p, fixAction, oldText, p.Text);
}
if (doFix && languageCode == "el" && (p.Text.Substring(match.Index).StartsWith("ό,τι") || p.Text.Substring(match.Index).StartsWith("ο,τι")))
doFix = false;
if (doFix && AllowFix(p, fixAction))
{
_totalFixes++;
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]);
AddFixToListView(p, fixAction, oldText, p.Text);
}
match = match.NextMatch();
}

View File

@ -576,6 +576,18 @@ namespace Test
}
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingSpacesChange2()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be,or not to be!");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingSpacesNoChange2()
@ -612,8 +624,67 @@ namespace Test
}
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingSpacesNoChange5Greek()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Aφαίρεσαν ό,τι αντρικό είχες.");
target.Language = "el"; // Greek
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Aφαίρεσαν ό,τι αντρικό είχες.");
}
}
#endregion Fix missing spaces
#region Fix unneeded spaces
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixUnneededSpaces1()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
public void FixUnneededSpaces2()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, " To be, or not to be!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, " To be, or not to be!");
}
}
public void FixUnneededSpaces3()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be! ");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
public void FixUnneededSpaces4()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be! " + Environment.NewLine + " Line two.");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!" + Environment.NewLine + "Line two.");
}
}
#endregion Fix unneeded spaces
#region Start with uppercase after paragraph
[TestMethod]