From afb5778c7523bb33efe6afb8d2de76b9721e906f Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 19 Jul 2022 12:46:59 +0200 Subject: [PATCH] Allow for "SE" spell check dictionary file (besides user file) --- Dictionaries/{en_US_user.xml => en_US_se.xml} | 0 installer/Subtitle_Edit_installer.iss | 3 +++ src/libse/SpellCheck/SpellCheckWordLists.cs | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+) rename Dictionaries/{en_US_user.xml => en_US_se.xml} (100%) diff --git a/Dictionaries/en_US_user.xml b/Dictionaries/en_US_se.xml similarity index 100% rename from Dictionaries/en_US_user.xml rename to Dictionaries/en_US_se.xml diff --git a/installer/Subtitle_Edit_installer.iss b/installer/Subtitle_Edit_installer.iss index 14a618fb3..d567aa828 100644 --- a/installer/Subtitle_Edit_installer.iss +++ b/installer/Subtitle_Edit_installer.iss @@ -223,6 +223,7 @@ Source: ..\Dictionaries\sr_NoBreakAfterList.xml; DestDir: {userappdata}\Subtit Source: ..\Dictionaries\da_DK_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\de_DE_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\en_US_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main +Source: ..\Dictionaries\en_US_se.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion; Components: main Source: ..\Dictionaries\es_MX_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\fi_FI_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main Source: ..\Dictionaries\nl_NL_user.xml; DestDir: {userappdata}\Subtitle Edit\Dictionaries; Flags: ignoreversion onlyifdoesntexist; Components: main @@ -359,6 +360,7 @@ Type: files; Name: {app}\Dictionaries\en_US.aff; Check: Is Type: files; Name: {app}\Dictionaries\en_US.dic; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\en_names.xml; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\en_US_user.xml; Check: IsUpgrade() +Type: files; Name: {app}\Dictionaries\en_US_se.xml; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\eng_OCRFixReplaceList.xml; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\names.xml; Check: IsUpgrade() Type: files; Name: {app}\Dictionaries\no_names.xml; Check: IsUpgrade() @@ -678,6 +680,7 @@ begin DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\da_DK_user.xml')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\de_DE_user.xml')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\en_US_user.xml')); + DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\en_US_se.xml')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\es_MX_user.xml')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\fi_FI_user.xml')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries\nl_NL_user.xml')); diff --git a/src/libse/SpellCheck/SpellCheckWordLists.cs b/src/libse/SpellCheck/SpellCheckWordLists.cs index e7c74ddfb..b315c7304 100644 --- a/src/libse/SpellCheck/SpellCheckWordLists.cs +++ b/src/libse/SpellCheck/SpellCheckWordLists.cs @@ -31,6 +31,7 @@ namespace Nikse.SubtitleEdit.Core.SpellCheck private readonly HashSet _namesListWithApostrophe = new HashSet(); private readonly HashSet _wordsWithDashesOrPeriods = new HashSet(); private readonly HashSet _userWordList = new HashSet(); + private readonly HashSet _seWordList = new HashSet(); private readonly HashSet _userPhraseList = new HashSet(); private readonly string _dictionaryFolder; private HashSet _skipAllList = new HashSet(); @@ -93,6 +94,29 @@ namespace Nikse.SubtitleEdit.Core.SpellCheck } } } + + if (File.Exists(dictionaryFolder + languageName + "_se.xml")) + { + var userWordDictionary = new XmlDocument(); + userWordDictionary.Load(dictionaryFolder + languageName + "_se.xml"); + var xmlNodeList = userWordDictionary.DocumentElement?.SelectNodes("word"); + if (xmlNodeList != null) + { + foreach (XmlNode node in xmlNodeList) + { + var word = node.InnerText.Trim().ToLowerInvariant(); + if (word.Contains(' ')) + { + _userPhraseList.Add(word); + } + else + { + _userWordList.Add(word); + } + } + } + } + // Add names/userdic with "." or " " or "-" foreach (var word in namesMultiWordList) {