From 5c535606689764396deb5d8e016f4aab118058e5 Mon Sep 17 00:00:00 2001 From: niksedk Date: Mon, 9 Oct 2023 06:47:30 +0200 Subject: [PATCH] Interjections split to _se and _user file - thx Andrebavila :) Fix #7491 --- ...erjections.xml => da_interjections_se.xml} | 0 ...erjections.xml => en_interjections_se.xml} | 0 ...erjections.xml => es_interjections_se.xml} | 0 installer/Subtitle_Edit_Installer.iss | 12 +- .../Forms/RemoveTextForHearImpairedTest.cs | 194 ++++++++++-------- src/libse/Common/InterjectionsRepository.cs | 109 ++++++++++ src/libse/Forms/RemoveTextForHI.cs | 21 +- src/ui/Forms/BatchConvert.cs | 3 +- src/ui/Forms/RemoveTextForHearImpaired.cs | 30 +-- .../CommandLineConverter.cs | 3 +- 10 files changed, 248 insertions(+), 124 deletions(-) rename Dictionaries/{da_interjections.xml => da_interjections_se.xml} (100%) rename Dictionaries/{en_interjections.xml => en_interjections_se.xml} (100%) rename Dictionaries/{es_interjections.xml => es_interjections_se.xml} (100%) create mode 100644 src/libse/Common/InterjectionsRepository.cs diff --git a/Dictionaries/da_interjections.xml b/Dictionaries/da_interjections_se.xml similarity index 100% rename from Dictionaries/da_interjections.xml rename to Dictionaries/da_interjections_se.xml diff --git a/Dictionaries/en_interjections.xml b/Dictionaries/en_interjections_se.xml similarity index 100% rename from Dictionaries/en_interjections.xml rename to Dictionaries/en_interjections_se.xml diff --git a/Dictionaries/es_interjections.xml b/Dictionaries/es_interjections_se.xml similarity index 100% rename from Dictionaries/es_interjections.xml rename to Dictionaries/es_interjections_se.xml diff --git a/installer/Subtitle_Edit_Installer.iss b/installer/Subtitle_Edit_Installer.iss index 27cf05791..436163908 100644 --- a/installer/Subtitle_Edit_Installer.iss +++ b/installer/Subtitle_Edit_Installer.iss @@ -245,9 +245,9 @@ Source: ..\Dictionaries\ita_WordSplitList.txt; DestDir: {userappdata}\Subtit Source: ..\Dictionaries\pol_WordSplitList.txt; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\spa_WordSplitList.txt; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\deu_Nouns.txt; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main -Source: ..\Dictionaries\da_interjections.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main -Source: ..\Dictionaries\en_interjections.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main -Source: ..\Dictionaries\es_interjections.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main +Source: ..\Dictionaries\da_interjections_se.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main +Source: ..\Dictionaries\en_interjections_se.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main +Source: ..\Dictionaries\es_interjections_se.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Ocr\Latin.db; DestDir: {userappdata}\Subtitle Edit\Ocr; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main @@ -399,9 +399,9 @@ Type: files; Name: {app}\Dictionaries\ita_WordSplitList.txt; Check: Is Type: files; Name: {app}\Dictionaries\pol_WordSplitList.txt; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\spa_WordSplitList.txt; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\deu_Nouns.txt; Check: IsUpgrade() -Type: files; Name: {app}\Dictionaries\da_interjections.txt; Check: IsUpgrade() -Type: files; Name: {app}\Dictionaries\en_interjections.txt; Check: IsUpgrade() -Type: files; Name: {app}\Dictionaries\es_interjections.txt; Check: IsUpgrade() +Type: files; Name: {app}\Dictionaries\da_interjections_se.xml; Check: IsUpgrade() +Type: files; Name: {app}\Dictionaries\en_interjections_se.xml; Check: IsUpgrade() +Type: files; Name: {app}\Dictionaries\es_interjections_se.xml; Check: IsUpgrade() Type: dirifempty; Name: {app}\Dictionaries; Check: IsUpgrade() Type: files; Name: {app}\TessData\eng.DangAmbigs; Check: IsUpgrade() diff --git a/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs b/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs index 6cda15a92..a6340df51 100644 --- a/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs +++ b/src/Test/Logic/Forms/RemoveTextForHearImpairedTest.cs @@ -23,7 +23,7 @@ namespace Test.Logic.Forms /// public TestContext TestContext { get; set; } - private static string _interjectionsFileName; + private static string _interjectionsLanguageCode; private static RemoveTextForHI GetRemoveTextForHiLib() { @@ -35,10 +35,42 @@ namespace Test.Logic.Forms private static void SetInterjections() { - if (_interjectionsFileName == null) + if (_interjectionsLanguageCode == null) { - _interjectionsFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); - File.WriteAllText(_interjectionsFileName, " Ah Ahem Ahh Ahhh Ahhhh Eh Ehh Ehhh Erm Gah Hm Hmm Hmmm Huh Mm Mmm Mmmm Oh Ohh Ohhh Ow Oww Owww Phew Ugh Ughh Uh Uhh Uhhh Whew", Encoding.UTF8); + _interjectionsLanguageCode = "en"; + InterjectionsRepository.SaveInterjections(_interjectionsLanguageCode, new List() + { + "Ah", + "Ahem", + "Ahh", + "Ahhh", + "Ahhhh", + "Eh", + "Ehh", + "Ehhh", + "Erm", + "Gah", + "Hm", + "Hmm", + "Hmmm", + "Huh", + "Mm", + "Mmm", + "Mmmm", + "Oh", + "Ohh", + "Ohhh", + "Ow", + "Oww", + "Owww", + "Phew", + "Ugh", + "Ughh", + "Uh", + "Uhh", + "Uhhh", + "Whew", + }); } } @@ -49,7 +81,7 @@ namespace Test.Logic.Forms return new InterjectionRemoveContext { OnlySeparatedLines = onlyInSeparatedLine, - Interjections = RemoveTextForHI.GetInterjectionList(_interjectionsFileName), + Interjections = RemoveTextForHI.GetInterjectionList(_interjectionsLanguageCode), Text = text, }; } @@ -262,7 +294,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColonOnlyUppercase = false; string text = "- He's got the clap." + Environment.NewLine + "- SAM: (gasps) What?"; string expected = "- He's got the clap." + Environment.NewLine + "- What?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -299,7 +331,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "- Aw, save it. Storm?\r\n- [Storm]\r\nWe're outta here."; const string expected = "- Aw, save it. Storm?\r\n- We're outta here."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -317,7 +349,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "[Chuckles,\r\nCoughing]\r\nBut we lived through it."; const string expected = "But we lived through it."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -334,7 +366,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "is the body of a mutant kid\r\non the 6:00 news."; const string expected = "is the body of a mutant kid\r\non the 6:00 news."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -353,7 +385,7 @@ namespace Test.Logic.Forms string text = "NARRATOR:" + Environment.NewLine + "Previously on NCIS"; const string expected = "Previously on NCIS"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -372,7 +404,7 @@ namespace Test.Logic.Forms string text = "NARRATOR:" + Environment.NewLine + "Previously on NCIS"; const string expected = "Previously on NCIS"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -390,7 +422,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; string text = "- JOHN: Hey." + Environment.NewLine + "- ...hey."; string expected = "- Hey." + Environment.NewLine + "- ...hey."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -414,7 +446,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "[MAN]Where?![MAN]"; const string expected = "Where?!"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -430,7 +462,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; string text = "HECTOR: Hi." + Environment.NewLine + "-Oh, hey, Hector."; string expected = "- Hi." + Environment.NewLine + "- Oh, hey, Hector."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -446,7 +478,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "HECTOR: Hi."; const string expected = "Hi."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -722,7 +754,7 @@ namespace Test.Logic.Forms target.Settings.ColonSeparateLine = false; const string text = "MICHAEL: How are you?"; const string expected = "How are you?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -940,7 +972,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; string text = "- I insist." + Environment.NewLine + "- [ Woman Laughing]"; const string expected = "I insist."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -967,7 +999,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; string text = "WOMAN: A glass of champagne, please." + Environment.NewLine + "- (Laughter)"; const string expected = "A glass of champagne, please."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -986,7 +1018,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenQuestionMarks = true; string text = "? My Paul ?" + Environment.NewLine + "? I give you all ?"; string expected = string.Empty; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1052,7 +1084,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "- A man who wants to make his mark..." + Environment.NewLine + "- [ Coughing]"; const string expected = "A man who wants to make his mark..."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1063,7 +1095,7 @@ namespace Test.Logic.Forms target.Settings.RemoveIfAllUppercase = true; string text = "- And you?" + Environment.NewLine + "- I—"; string expected = "- And you?" + Environment.NewLine + "- I—"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1073,7 +1105,7 @@ namespace Test.Logic.Forms var target = GetRemoveTextForHiLib(); target.Settings.RemoveIfAllUppercase = true; string text = string.Empty; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(text, actual); } @@ -1086,7 +1118,7 @@ namespace Test.Logic.Forms target.Settings.RemoveIfTextContains = null; const string text = "♪♪[Ambient Electronic]"; const string expected = "♪♪"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1100,7 +1132,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; const string text = "Oh — Oh, that's nice!"; const string expected = "That's nice!"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1112,7 +1144,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- Uh—uh, my God!" + Environment.NewLine + "- Uh, my God."; string expected = "- My God!" + Environment.NewLine + "- My God."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1124,7 +1156,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- Uh — uh, my God!" + Environment.NewLine + "- Uh, my God."; string expected = "- My God!" + Environment.NewLine + "- My God."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1136,7 +1168,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- I just, uh —" + Environment.NewLine + "- What?"; string expected = "- I just —" + Environment.NewLine + "- What?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1148,7 +1180,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenParentheses = true; const string text = "I'm trying to! (MASTER): Faster now. evacuate."; const string expected = "I'm trying to! Faster now. evacuate."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1160,7 +1192,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- Mr. Harding?" + Environment.NewLine + "Uh--"; const string expected = "Mr. Harding?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1172,7 +1204,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- Mr. Harding?" + Environment.NewLine + "- Mm-hm. Oh."; const string expected = "Mr. Harding?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1184,7 +1216,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "-Sit down. Sit down." + Environment.NewLine + "-Oh! Oh!"; const string expected = "Sit down. Sit down."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1196,7 +1228,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "Oh." + Environment.NewLine + "-I'm awfully tired."; const string expected = "I'm awfully tired."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1233,7 +1265,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; string text = "WOMAN: Mr. Sportello?" + Environment.NewLine + "- Mm-hm."; string expected = "- Mr. Sportello?" + Environment.NewLine + "- Mm-hm."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1246,7 +1278,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "WOMAN: Mr. Sportello?" + Environment.NewLine + "- Mm-hm."; string expected = "Mr. Sportello?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1259,7 +1291,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = true; string text = "- \"My father doesn't want me to be him.\"" + Environment.NewLine + "EAMES: Exactly."; string expected = "- \"My father doesn't want me to be him.\"" + Environment.NewLine + "- Exactly."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1280,7 +1312,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "-[gurgling]" + Environment.NewLine + "-Mom?"; const string expected = "Mom?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1291,7 +1323,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "-[Ronnie laughs]" + Environment.NewLine + "-[sighs] Wow, Ronnie."; const string expected = "Wow, Ronnie."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1302,7 +1334,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; const string text = "[Whistling] Hallo everybody!"; const string expected = "Hallo everybody!"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1313,7 +1345,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; const string text = "♪ [LIGHT SWITCH CLICKS]"; const string expected = "♪"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1324,7 +1356,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; const string text = "Foobar [CHAINS RATTLING] Foobar"; const string expected = "Foobar Foobar"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1350,7 +1382,7 @@ namespace Test.Logic.Forms target.Settings.RemoveWhereContains = false; string text = "- ♪♪[Continues ]" + Environment.NewLine + "- It's pretty strong stuff."; const string expected = "It's pretty strong stuff."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1365,7 +1397,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "♪ Trotting down the paddock" + Environment.NewLine + "on a bright, sunny day ♪♪"; string expected = string.Empty; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1380,7 +1412,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "♪ Trotting down the paddock" + Environment.NewLine + "on a bright, sunny day ♪♪"; string expected = string.Empty; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1395,7 +1427,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenBrackets = true; string text = "- ♪ Honey, honey, yeah ♪" + Environment.NewLine + "- ♪ Heard it through|the grapevine ♪"; string expected = string.Empty; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1409,11 +1441,11 @@ namespace Test.Logic.Forms target.Settings.CustomEnd = "♪"; target.Settings.RemoveTextBetweenBrackets = true; Configuration.Settings.General.DialogStyle = DialogType.DashBothLinesWithSpace; - string text = "The meal is ready. Let's go!" + Environment.NewLine + "- [Nick] J. T. Lancer!"; - string expected = "- The meal is ready. Let's go!" + Environment.NewLine + "- J. T. Lancer!"; + var text = "The meal is ready. Let's go!" + Environment.NewLine + "- [Nick] J. T. Lancer!"; + var expected = "- The meal is ready. Let's go!" + Environment.NewLine + "- J. T. Lancer!"; var sub = new Subtitle(); sub.Paragraphs.Add(new Paragraph(text, 0, 2000)); - string actual = target.RemoveTextFromHearImpaired(text, sub, 0, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, sub, 0, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1471,7 +1503,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenCustomTags = true; target.Settings.CustomStart = "♪"; target.Settings.CustomEnd = "♪"; - string actual = target.RemoveTextFromHearImpaired("- ♪ To defeat ♪" + Environment.NewLine + "- Referee: Salute.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- ♪ To defeat ♪" + Environment.NewLine + "- Referee: Salute.", _interjectionsLanguageCode); Assert.AreEqual("Salute.", actual); } @@ -1516,7 +1548,7 @@ namespace Test.Logic.Forms string text = "Let's count!" + Environment.NewLine + "1.. 2... 3!"; string expected = "Let's count!" + Environment.NewLine + "1.. 2... 3!"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1533,7 +1565,7 @@ namespace Test.Logic.Forms const string text = "ENGINE STARTING"; const string expected = ""; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1551,7 +1583,7 @@ namespace Test.Logic.Forms string text = "- NORA: Sir?" + Environment.NewLine + "- (CAR DOOR CLOSES)"; string expected = "Sir?"; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1569,7 +1601,7 @@ namespace Test.Logic.Forms string text = "- Well, received, technically." + Environment.NewLine + "- KEVIN: Mmm-hmm."; string expected = "- Well, received, technically." + Environment.NewLine + "- Mmm-hmm."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1588,7 +1620,7 @@ namespace Test.Logic.Forms string text = "- Well, received, technically." + Environment.NewLine + "- KEVIN: Mmm-hmm."; string expected = "Well, received, technically."; - string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1639,7 +1671,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenParentheses = true; target.Settings.RemoveInterjections = true; string expected = "- How many, sir?" + Environment.NewLine + "- 275."; - string actual = target.RemoveTextFromHearImpaired("- How many, sir?" + Environment.NewLine + "- Uh — (clears throat) 275.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- How many, sir?" + Environment.NewLine + "- Uh — (clears throat) 275.", _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -1650,7 +1682,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenParentheses = false; target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; - string actual = target.RemoveTextFromHearImpaired("[scoffs]: Nice try.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("[scoffs]: Nice try.", _interjectionsLanguageCode); Assert.AreEqual("Nice try.", actual); } @@ -1663,7 +1695,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenCustomTags = true; target.Settings.CustomStart = "♪"; target.Settings.CustomEnd = "♪"; - string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- ♪ [Ominous tone plays] ♪", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- ♪ [Ominous tone plays] ♪", _interjectionsLanguageCode); Assert.AreEqual("Ferguson, Kaz...", actual); } @@ -1674,7 +1706,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- ♪ [Ominous tone plays] ♪", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- ♪ [Ominous tone plays] ♪", _interjectionsLanguageCode); Assert.AreEqual("Ferguson, Kaz...", actual); } @@ -1686,7 +1718,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:", _interjectionsLanguageCode); Assert.AreEqual("Captain's log, stardate 1514. 1:", actual); } @@ -1697,7 +1729,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:", _interjectionsLanguageCode); Assert.AreEqual("Captain's log, stardate 1514. 1:", actual); } @@ -1708,7 +1740,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.", _interjectionsLanguageCode); Assert.AreEqual("--and trespassed into our star systems.", actual); } @@ -1719,7 +1751,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.", _interjectionsLanguageCode); Assert.AreEqual("--and trespassed into our star systems.", actual); } @@ -1730,7 +1762,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "—and trespassed into our star systems.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "—and trespassed into our star systems.", _interjectionsLanguageCode); Assert.AreEqual("—and trespassed into our star systems.", actual); } @@ -1742,7 +1774,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; target.Settings.RemoveTextBetweenCustomTags = false; - string actual = target.RemoveTextFromHearImpaired(" -JOHN: Hvordan går det?" + Environment.NewLine + "-Marry: Det går fint!", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired(" -JOHN: Hvordan går det?" + Environment.NewLine + "-Marry: Det går fint!", _interjectionsLanguageCode); Assert.AreEqual("- Hvordan går det?" + Environment.NewLine + "- Det går fint!", actual); } @@ -1806,7 +1838,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBetweenCustomTags = true; target.Settings.CustomStart = "♪"; target.Settings.CustomEnd = "♪"; - string actual = target.RemoveTextFromHearImpaired("♪ Give me hope and" + Environment.NewLine + "give me patience ♪", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("♪ Give me hope and" + Environment.NewLine + "give me patience ♪", _interjectionsLanguageCode); Assert.AreEqual(string.Empty, actual); } @@ -1816,7 +1848,7 @@ namespace Test.Logic.Forms var target = GetRemoveTextForHiLib(); target.Settings.RemoveTextBeforeColon = false; target.Settings.RemoveTextBetweenParentheses = true; - string actual = target.RemoveTextFromHearImpaired("(Not, it's not (a secret).)", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("(Not, it's not (a secret).)", _interjectionsLanguageCode); Assert.AreEqual(string.Empty, actual); } @@ -1826,7 +1858,7 @@ namespace Test.Logic.Forms var target = GetRemoveTextForHiLib(); target.Settings.RemoveTextBeforeColon = false; target.Settings.RemoveTextBetweenParentheses = true; - string actual = target.RemoveTextFromHearImpaired("(MAN) Not, it's... (WOMAN) not.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("(MAN) Not, it's... (WOMAN) not.", _interjectionsLanguageCode); Assert.AreEqual("Not, it's... not.", actual); } @@ -1902,7 +1934,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; target.Settings.RemoveTextBeforeColonOnlyUppercase = true; target.Settings.OnlyIfInSeparateLine = true; - string actual = target.RemoveTextFromHearImpaired("-Era stato avveritito." + Environment.NewLine + "-(PARLA IN SPANOLO)", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("-Era stato avveritito." + Environment.NewLine + "-(PARLA IN SPANOLO)", _interjectionsLanguageCode); Assert.AreEqual("Era stato avveritito.", actual); } @@ -1913,7 +1945,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; target.Settings.RemoveTextBeforeColonOnlyUppercase = true; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("Senti, [si schiarisce la voce]," + Environment.NewLine + "dille semplicemente che ti e mancata.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("Senti, [si schiarisce la voce]," + Environment.NewLine + "dille semplicemente che ti e mancata.", _interjectionsLanguageCode); Assert.AreEqual("Senti," + Environment.NewLine + "dille semplicemente che ti e mancata.", actual); } @@ -1930,7 +1962,7 @@ namespace Test.Logic.Forms var target = GetRemoveTextForHiLib(); target.Settings.RemoveTextBeforeColon = false; target.Settings.RemoveTextBetweenBrackets = true; - string actual = target.RemoveTextFromHearImpaired("Spoken text." + Environment.NewLine + "- [hearing impaired text] Spoken text.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("Spoken text." + Environment.NewLine + "- [hearing impaired text] Spoken text.", _interjectionsLanguageCode); Assert.AreEqual("- Spoken text." + Environment.NewLine + "- Spoken text.", actual); } @@ -1941,7 +1973,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; target.Settings.RemoveTextBeforeColonOnlyUppercase = true; target.Settings.RemoveInterjections = false; - string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsLanguageCode); Assert.AreEqual("Mr. Wylie!", actual); } @@ -1952,7 +1984,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColon = true; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; target.Settings.RemoveInterjections = false; - string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsLanguageCode); Assert.AreEqual("Mr. Wylie!", actual); } @@ -1966,7 +1998,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = true; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsLanguageCode); Assert.AreEqual("Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", actual); } @@ -1979,7 +2011,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = true; target.Settings.OnlyIfInSeparateLine = true; - string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsLanguageCode); Assert.AreEqual("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", actual); } @@ -1992,7 +2024,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = true; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("- You're weird!" + Environment.NewLine + "- [sigh]", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- You're weird!" + Environment.NewLine + "- [sigh]", _interjectionsLanguageCode); Assert.AreEqual("You're weird!", actual); } @@ -2005,7 +2037,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = true; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("\u2010 You're weird!" + Environment.NewLine + "\u2010 [sigh]", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("\u2010 You're weird!" + Environment.NewLine + "\u2010 [sigh]", _interjectionsLanguageCode); Assert.AreEqual("You're weird!", actual); } @@ -2057,7 +2089,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = false; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("- Oh. No." + Environment.NewLine + "-", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("- Oh. No." + Environment.NewLine + "-", _interjectionsLanguageCode); Assert.AreEqual("Oh. No.", actual); } @@ -2070,7 +2102,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = false; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("-" + Environment.NewLine + "- Oh. No.", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("-" + Environment.NewLine + "- Oh. No.", _interjectionsLanguageCode); Assert.AreEqual("Oh. No.", actual); } @@ -2083,7 +2115,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = false; target.Settings.OnlyIfInSeparateLine = true; - var actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsFileName); + var actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsLanguageCode); Assert.AreEqual("What's going on...?! [gasps]", actual); } @@ -2096,7 +2128,7 @@ namespace Test.Logic.Forms target.Settings.RemoveInterjections = false; target.Settings.RemoveTextBetweenBrackets = false; target.Settings.OnlyIfInSeparateLine = false; - string actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsFileName); + string actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsLanguageCode); Assert.AreEqual("What's going on...?!", actual); } @@ -2232,7 +2264,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColonOnlyUppercase = false; var text = "Oh, I was just in my office" + Environment.NewLine + "and-and it was... 10:00."; var expected = "I was just in my office" + Environment.NewLine + "and-and it was... 10:00."; - var actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + var actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -2249,7 +2281,7 @@ namespace Test.Logic.Forms target.Settings.RemoveTextBeforeColonOnlyUppercase = false; var text = "and that is gonna take..." + Environment.NewLine + "[STAMMERS] ... real deep pockets."; var expected = "and that is gonna take..." + Environment.NewLine + "... real deep pockets."; - var actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName); + var actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } } diff --git a/src/libse/Common/InterjectionsRepository.cs b/src/libse/Common/InterjectionsRepository.cs new file mode 100644 index 000000000..f31e1e229 --- /dev/null +++ b/src/libse/Common/InterjectionsRepository.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Xml; + +namespace Nikse.SubtitleEdit.Core.Common +{ + public static class InterjectionsRepository + { + + private const string UserFileName = "_interjections_user.xml"; + private const string SeFileName = "_interjections_se.xml"; + + public static List LoadInterjections(string twoLetterIsoLanguageName) + { + var seFileName = twoLetterIsoLanguageName + SeFileName; + var userFileName = twoLetterIsoLanguageName + UserFileName; + var interjections = new List(); + var se = LoadInterjections(seFileName, out _); + var user = LoadInterjections(userFileName, out var ignoreList); + + foreach (var w in se) + { + if (!interjections.Contains(w) && !ignoreList.Contains(w)) + { + interjections.Add(w); + } + } + + foreach (var w in user) + { + if (!interjections.Contains(w) && !ignoreList.Contains(w)) + { + interjections.Add(w); + } + } + + return interjections.OrderBy(p => p).ToList(); + } + + public static void SaveInterjections(string twoLetterIsoLanguageName, List interjections) + { + var seFileName = twoLetterIsoLanguageName + SeFileName; + var userFileName = twoLetterIsoLanguageName + UserFileName; + var se = LoadInterjections(seFileName, out _); + var ignoreList = new List(); + + foreach (var w in se) + { + if (!interjections.Contains(w) && !ignoreList.Contains(w)) + { + ignoreList.Add(w); + } + } + + var xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(""); + var ignoreNode = xmlDocument.DocumentElement.SelectSingleNode("ignore"); + foreach (var w in ignoreList) + { + var node = xmlDocument.CreateElement( "word"); + node.InnerText = w; + ignoreNode.AppendChild(node); + } + + foreach (var w in interjections) + { + var node = xmlDocument.CreateElement("word"); + node.InnerText = w; + xmlDocument.DocumentElement.AppendChild(node); + } + + var fullFileName = Path.Combine(Configuration.DictionariesDirectory, userFileName); + xmlDocument.Save(fullFileName); + } + + private static List LoadInterjections(string fileName, out List ignoreList) + { + ignoreList = new List(); + var interjections = new List(); + var fullFileName = Path.Combine(Configuration.DictionariesDirectory, fileName); + if (File.Exists(fullFileName)) + { + var xmlDocument = new XmlDocument(); + xmlDocument.Load(fullFileName); + foreach (XmlNode node in xmlDocument.DocumentElement.SelectNodes("word")) + { + var w = node.InnerText.Trim(); + if (!string.IsNullOrEmpty(w) && !interjections.Contains(w)) + { + interjections.Add(w); + } + } + + foreach (XmlNode node in xmlDocument.DocumentElement.SelectNodes("ignore/word")) + { + var w = node.InnerText.Trim(); + if (!string.IsNullOrEmpty(w) && !ignoreList.Contains(w)) + { + ignoreList.Add(w); + } + } + + } + + return interjections; + } + } +} diff --git a/src/libse/Forms/RemoveTextForHI.cs b/src/libse/Forms/RemoveTextForHI.cs index 60cc38841..a84aeed9f 100644 --- a/src/libse/Forms/RemoveTextForHI.cs +++ b/src/libse/Forms/RemoveTextForHI.cs @@ -849,12 +849,12 @@ namespace Nikse.SubtitleEdit.Core.Forms private static readonly char[] TrimStartNoiseChar = { '-', ' ' }; - public string RemoveTextFromHearImpaired(string input, string interjectionsFileName) + public string RemoveTextFromHearImpaired(string input, string twoLetterIsoLanguageName) { - return RemoveTextFromHearImpaired(input, null, -1, interjectionsFileName); + return RemoveTextFromHearImpaired(input, null, -1, twoLetterIsoLanguageName); } - public string RemoveTextFromHearImpaired(string inputWithoutUnicodeReplace, Subtitle subtitle, int index, string interjectionsFileName) + public string RemoveTextFromHearImpaired(string inputWithoutUnicodeReplace, Subtitle subtitle, int index, string twoLetterIsoLanguageName) { if (StartsAndEndsWithHearImpairedTags(HtmlUtil.RemoveHtmlTags(inputWithoutUnicodeReplace, true).TrimStart(TrimStartNoiseChar))) { @@ -1023,7 +1023,7 @@ namespace Nikse.SubtitleEdit.Core.Forms { if (_interjections == null) { - ReloadInterjection(interjectionsFileName); + ReloadInterjection(twoLetterIsoLanguageName); } // reusable context @@ -1595,15 +1595,10 @@ namespace Nikse.SubtitleEdit.Core.Forms return words; } - public static string GetInterjectionsFileName(string twoLetterLanguage) - { - return Path.Combine(Configuration.DictionariesDirectory, twoLetterLanguage + "_interjections.xml"); - } - - public static IList GetInterjectionList(string fileName) + public static IList GetInterjectionList(string twoLetterIsoLanguageName) { var interjectionList = new HashSet(); - foreach (var s in GetInterjections(fileName)) + foreach (var s in InterjectionsRepository.LoadInterjections(twoLetterIsoLanguageName)) { if (s.Length <= 0) { @@ -1621,9 +1616,9 @@ namespace Nikse.SubtitleEdit.Core.Forms return sortedList; } - public void ReloadInterjection(string fileName) + public void ReloadInterjection(string twoLetterIsoLanguageName) { - _interjections = GetInterjectionList(fileName); + _interjections = GetInterjectionList(twoLetterIsoLanguageName); } } } diff --git a/src/ui/Forms/BatchConvert.cs b/src/ui/Forms/BatchConvert.cs index 3faa58516..4bf90f1cb 100644 --- a/src/ui/Forms/BatchConvert.cs +++ b/src/ui/Forms/BatchConvert.cs @@ -2057,13 +2057,12 @@ namespace Nikse.SubtitleEdit.Forms var prev = sub.GetParagraphOrDefault(0); var first = true; var lang = LanguageAutoDetect.AutoDetectGoogleLanguage(sub); - var interjectionsFileName = RemoveTextForHI.GetInterjectionsFileName(lang); foreach (var p in sub.Paragraphs) { if (IsActionEnabled(CommandLineConverter.BatchAction.RemoveTextForHI)) { _removeTextForHearingImpaired.Settings = _removeTextForHiSettings; - p.Text = _removeTextForHearingImpaired.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), interjectionsFileName); + p.Text = _removeTextForHearingImpaired.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), lang); } if (IsActionEnabled(CommandLineConverter.BatchAction.RemoveFormatting)) diff --git a/src/ui/Forms/RemoveTextForHearImpaired.cs b/src/ui/Forms/RemoveTextForHearImpaired.cs index 69caa6d33..70fc99ab8 100644 --- a/src/ui/Forms/RemoveTextForHearImpaired.cs +++ b/src/ui/Forms/RemoveTextForHearImpaired.cs @@ -156,8 +156,7 @@ namespace Nikse.SubtitleEdit.Forms _removeTextForHiLib.Settings = GetSettings(Subtitle); _removeTextForHiLib.Warnings = new List(); - var fileName = GetInterjectionsFileName(); - _removeTextForHiLib.ReloadInterjection(fileName); + _removeTextForHiLib.ReloadInterjection(_interjectionsLanguage); listViewFixes.BeginUpdate(); listViewFixes.Items.Clear(); @@ -176,7 +175,7 @@ namespace Nikse.SubtitleEdit.Forms } else { - var newText = _removeTextForHiLib.RemoveTextFromHearImpaired(p.Text, Subtitle, index, GetInterjectionsFileName()); + var newText = _removeTextForHiLib.RemoveTextFromHearImpaired(p.Text, Subtitle, index, _interjectionsLanguage); if (p.Text.RemoveChar(' ') != newText.RemoveChar(' ')) { count++; @@ -306,8 +305,13 @@ namespace Nikse.SubtitleEdit.Forms private void buttonEditInterjections_Click(object sender, EventArgs e) { - var fileName = GetInterjectionsFileName(); - using (var editInterjections = new InterjectionsEditList(RemoveTextForHI.GetInterjections(fileName))) + var lang = "en"; + if (comboBoxLanguage.SelectedIndex >= 0 && comboBoxLanguage.Items[comboBoxLanguage.SelectedIndex] is LanguageItem l) + { + lang = l.Code.TwoLetterISOLanguageName; + } + + using (var editInterjections = new InterjectionsEditList(InterjectionsRepository.LoadInterjections(lang))) { if (editInterjections.ShowDialog(this) == DialogResult.OK) { @@ -321,20 +325,6 @@ namespace Nikse.SubtitleEdit.Forms } private void SaveInterjections(List interjections) - { - var xml = new XmlDocument(); - xml.LoadXml(""); - foreach (var s in interjections) - { - XmlNode node = xml.CreateElement("word"); - node.InnerText = s; - xml.DocumentElement.AppendChild(node); - } - - xml.Save(GetInterjectionsFileName()); - } - - private string GetInterjectionsFileName() { var lang = "en"; if (comboBoxLanguage.SelectedIndex >= 0 && comboBoxLanguage.Items[comboBoxLanguage.SelectedIndex] is LanguageItem l) @@ -342,7 +332,7 @@ namespace Nikse.SubtitleEdit.Forms lang = l.Code.TwoLetterISOLanguageName; } - return RemoveTextForHI.GetInterjectionsFileName(lang); + InterjectionsRepository.SaveInterjections(lang, interjections); } private void FormRemoveTextForHearImpaired_Resize(object sender, EventArgs e) diff --git a/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs b/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs index 6a31efcd6..08f961ca5 100644 --- a/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs +++ b/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs @@ -2197,10 +2197,9 @@ namespace Nikse.SubtitleEdit.Logic.CommandLineConvert var hiSettings = new Core.Forms.RemoveTextForHISettings(sub); var hiLib = new Core.Forms.RemoveTextForHI(hiSettings); var lang = LanguageAutoDetect.AutoDetectGoogleLanguage(sub); - var interjectionsFileName = RemoveTextForHI.GetInterjectionsFileName(lang); foreach (var p in sub.Paragraphs) { - p.Text = hiLib.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), interjectionsFileName); + p.Text = hiLib.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), lang); } break;