mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 03:33:18 +01:00
Fix for RTL language auto-detection - thx OmrSi :)
This commit is contained in:
parent
8acf54387a
commit
2c650dba24
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Nikse.SubtitleEdit.Core.DetectEncoding;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
@ -796,7 +798,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
if (GetCount(hewbrewEncoding.GetString(buffer), AutoDetectWordsHebrew) > 5)
|
||||
return hewbrewEncoding;
|
||||
|
||||
return DetectEncoding.EncodingTools.DetectInputCodepage(buffer);
|
||||
return EncodingTools.DetectInputCodepage(buffer);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -955,5 +957,33 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CouldBeRightToLeftLanguge(Subtitle subtitle)
|
||||
{
|
||||
var text = subtitle.GetAllTexts();
|
||||
if (text.Length > 1000)
|
||||
{
|
||||
int arabicCount = GetCount(text, AutoDetectWordsArabic);
|
||||
if (arabicCount > 1)
|
||||
return true;
|
||||
|
||||
int hebrewCount = GetCount(text, AutoDetectWordsHebrew);
|
||||
if (hebrewCount > 1)
|
||||
return true;
|
||||
|
||||
int farsiCount = GetCount(text, AutoDetectWordsFarsi);
|
||||
if (farsiCount > 1)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var letter in string.Join(string.Empty, AutoDetectWordsArabic.Concat(AutoDetectWordsHebrew).Concat(AutoDetectWordsFarsi)).Distinct())
|
||||
{
|
||||
if (text.Contains(letter))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14538,8 +14538,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
|
||||
{
|
||||
var la = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitleAlternate);
|
||||
if ((la == null && Configuration.Settings.General.RightToLeftMode) || la == "ar" || la == "he")
|
||||
if (LanguageAutoDetect.CouldBeRightToLeftLanguge(_subtitleAlternate))
|
||||
{
|
||||
textBoxListViewTextAlternate.RightToLeft = RightToLeft.Yes;
|
||||
}
|
||||
@ -14548,14 +14547,14 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
textBoxListViewTextAlternate.RightToLeft = RightToLeft.No;
|
||||
}
|
||||
}
|
||||
var l = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle);
|
||||
if ((l == null && Configuration.Settings.General.RightToLeftMode) || l == "ar" || l == "he")
|
||||
if (LanguageAutoDetect.CouldBeRightToLeftLanguge(_subtitle))
|
||||
{
|
||||
textBoxListViewText.RightToLeft = RightToLeft.Yes;
|
||||
textBoxSource.RightToLeft = RightToLeft.Yes;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
textBoxListViewText.RightToLeft = RightToLeft.No;
|
||||
textBoxSource.RightToLeft = RightToLeft.No;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user