I am currently working on a translation project where one aspect is to convert a certain amount of Rtf data. I get the text out of the RTF into an array that I send through an AWS translator. The particular language is Bengali.
154 = Customer Code
LID = the Laguage Identifier for AWS
Text2Translate = the Rtf.Text Split on the linefeed.
foreach ( DataRow CTDV in calcTranslationsDV.Rows )
{ string LID = getLID(CTDV["Det_User_Field_29"].ToString());
foreach ( DataRow FT in FText.ToTable().Rows )
{ RichTextBox FrText = new RichTextBox() {Rtf = FT["Free_Text"].ToString() };
string[] Text2Translate = StripTabsandOtherText(FrText.Text.Split('\n'));
XMLDocument Translation = AWSAPIWrapper.getTranslation(154, LID, Text2Translate);
foreach ( XmlElement xlate in Translation.DocumentElement )
{ string myString = FrText.Rtf;
FrText.Rtf = myString.Replace(xlate["TextToTranslate"].InnerText, xlate["TranslatedText"].InnerText);
}
This code actually works really well and returns all the translations in the Translation XMLDocument. The Only problem is the the myString.Replace() places ????????????? in the Rtf for the resulting string value.
xlate["TranslatedText"].InnerText Contains মান অতিক্রম
What I have tried:
Before Replace FrText.Rtf Contains this top row of the word table in the Rtf field:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
\viewkind4\uc1\trowd\trgaph108\trleft-180\trbrdrl\brdrs\brdrw10 \clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs \cellx354\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15\brdrs \cellx5609\pard\intbl\sl252\slmult1\f0\fs17 4\cell EXCEEDING STANDARDS\cell\row
After Replace FrText.Rtf Contains this top row of the word table in the Rtf field:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
\viewkind4\uc1\trowd\trgaph108\trleft-180\trbrdrl\brdrs\brdrw10 \clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs \cellx354\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15\brdrs \cellx5609\pard\intbl\sl252\slmult1\f0\fs17 4\cell ??? ???????\cell\row
Note: for brevity I did not include the entirety of the Rtf nor of the first tdrow. I included enough to show the initial state and the result state after the Replace.
Further, the Replace statement works in the debug window but not in code. So, I attempted to add some font control on the Rtf object being used to no avail:
FrText.Font = new Font("Calibri", (float)8, FontStyle.Regular, (GraphicsUnit)3);