Merge pull request #7233 from ivandrofly/feature/refact-fix

Update/Fixes AdvancedTextBox
This commit is contained in:
Nikolaj Olsson 2023-08-17 18:50:38 -04:00 committed by GitHub
commit 7efaff923e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -591,6 +591,19 @@ namespace Nikse.SubtitleEdit.Controls
}
}
private static bool IsDictionaryAvailable(string language)
{
foreach (var downloadedDictionary in Utilities.GetDictionaryLanguagesCultureNeutral())
{
if (downloadedDictionary.Contains($"[{language}]", StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
public async Task InitializeLiveSpellCheck(Subtitle subtitle, int lineNumber)
{
if (lineNumber < 0)
@ -601,21 +614,9 @@ namespace Nikse.SubtitleEdit.Controls
if (_spellCheckWordLists is null && _hunspell is null)
{
var detectedLanguage = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle, 300);
var downloadedDictionaries = Utilities.GetDictionaryLanguagesCultureNeutral();
var isDictionaryAvailable = false;
foreach (var downloadedDictionary in downloadedDictionaries)
IsDictionaryDownloaded = false;
if (IsDictionaryAvailable(detectedLanguage))
{
if (downloadedDictionary.Contains($"[{detectedLanguage}]"))
{
isDictionaryAvailable = true;
break;
}
}
if (isDictionaryAvailable)
{
IsDictionaryDownloaded = true;
var languageName = LanguageAutoDetect.AutoDetectLanguageName(string.Empty, subtitle);
if (languageName.Split('_', '-')[0] != detectedLanguage)
{
@ -623,22 +624,18 @@ namespace Nikse.SubtitleEdit.Controls
}
await LoadDictionariesAsync(languageName);
IsDictionaryDownloaded = true;
IsSpellCheckerInitialized = true;
IsSpellCheckRequested = true;
TextChangedHighlight(this, EventArgs.Empty);
}
else
{
IsDictionaryDownloaded = false;
}
LanguageChanged = true;
CurrentLanguage = detectedLanguage;
}
}
private async Task LoadDictionariesAsync(string languageName) =>
await Task.Run(() => LoadDictionaries(languageName));
private Task LoadDictionariesAsync(string languageName) => new Task(() => LoadDictionaries(languageName));
private void LoadDictionaries(string languageName)
{
@ -848,7 +845,7 @@ namespace Nikse.SubtitleEdit.Controls
continue;
}
if (CurrentLanguage == "en " && (currentWordText.Equals("a", StringComparison.OrdinalIgnoreCase) || currentWordText == "I"))
if (CurrentLanguage == "en" && (currentWordText.Equals("a", StringComparison.OrdinalIgnoreCase) || currentWordText == "I"))
{
continue;
}