I have a richtextbox and I would like to change dynamically the flow direction of the text when I click on alt+shift
to change from the Arabic language to the English language ( the flow direction should be changed from RightToLeft
to LefttoRight
).
Is this possible using .Net libraries?
private void RichText_TextChanged(object sender, TextChangedEventArgs e)
{
var factory = new RankedLanguageIdentifierFactory();
try
{
var identifier = factory.Load("Core14.profile.xml");
// can be an absolute or relative path. Beware of 260 chars limitation of the path length in Windows. Linux allows 4096 chars.
string text = new TextRange(RichText.Document.ContentStart, RichText.Document.ContentEnd).Text;
var languages = identifier.Identify(text);
var mostCertainLanguage = languages.FirstOrDefault();
if (mostCertainLanguage != null)
if ((mostCertainLanguage.Item1.Iso639_3.Equals("eng")) || (mostCertainLanguage.Item1.Iso639_3.Equals("fra")))
{
RichText.FlowDirection = FlowDirection.LeftToRight;
}
else if (mostCertainLanguage.Item1.Iso639_3.Equals("dan"))
{
RichText.FlowDirection = FlowDirection.RightToLeft;
}
}
catch (Exception es)
{
Console.WriteLine("Exception " + es);
}
}
This what I have tried using this Nuget package ntextcat library
question from:
https://stackoverflow.com/questions/65830813/richtextbox-change-the-flow-direction-when-the-language-change-ar-eng-c-sharp 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…