Odd translation when using HTML string from MySql

I have stored in MySql the following HTML that is used to send an email:

<p>Thank you for signing up to our <a translate="no" href="$WebsiteURL">$WebsiteName - $WebsiteDescription</a></p>
<p>You will find instructions on what options are available for you as soon as you sign into your account.</p>
<p>Your username is $Username</p>
<p  translate="no">Regards,</p>
<p  translate="no">The xxx Team</p>

The $WebsiteURL, $WebsiteName, $WebsiteDescription and $Username is just replaced when sending the email so this isnt the issue.

The issue is if I paste the above code into the LibreTranslate web UI xxx:5000 it translates ok (for example into Thai):

<p>ขอบคุณที่ลงทะเบียนให้ <a href="$WebsiteURL" translate="no">$WebsiteName - $WebsiteDescription</a></p>
<p>คุณ จะ พบ คํา แนะ นํา ว่า จะ หา ทาง เลือก อะไร ได้ บ้าง เมื่อ คุณ เซ็น ชื่อ ใน บัญชี.</p><p>ชื่อผู้ใช้ของคุณเป็น $ ชื่อผู้ใช้ </p>
<p translate="no">Regards,</p>
<p translate="no">The xxx Team</p>

but when I get this HTML from the DB as a string it has " surrounding any quotation marks.

Example:

<p>Thank you for signing up to our <a translate=\"no\" href=\"$WebsiteURL\">$WebsiteName - $WebsiteDescription</a></p>\n
<p>You will find instructions on what options are available for you as soon as you sign into your account.</p>\n
<p>Your username is $Username</p>\n<p  translate=\"no\">Regards,</p>\n
<p  translate=\"no\">The xxx Team</p>`

So when I try to translate using the DB string with the " in the string using the following:

var TranslateAsyncTask = oTranslate.TranslateAsync(new Translate()
  {
      // ApiKey = "MySecretApiKey",
      Source = sOriginalLanguageCode.Substring(0, 2),
      Target = sTranslatedLanguageCode.Substring(0, 2),
      Text = sOriginalText
  });

I end up with a completly different translation:

<p> ขอบคุณที่ลงชื่อใน <a ของเรา แปลว่า "ไม่" (REFF=$WebsiteURL") $ website " - $ website
<p> คุณจะพบคําแนะนําเกี่ยวกับตัวเลือกต่าง ๆ ที่จะมีให้คุณทันทีที่คุณเซ็นในบัญชีของคุณ
<p> ชื่อผู้ใช้ของคุณคือ $ ชื่อผู้ใช้
<p = "no"> Recert, [p]
<p = "no"> ทีม AMS

What am I doing wrong?

Regards
J

1 Like

I think you need format=html when you call the LibreTranslate API so that your string is interpreted as HTML.

https://libretranslate.com/docs/#/translate/post_translate

1 Like

About 30 mins ago I downloaded the source code for the C# LibreTranslate wrapper and added the following in the LibreTranslate.cs:

var formUrlEncodedContent = new FormUrlEncodedContent(new Dictionary<string, string>()
{
    { "q", translate.Text },
    { "source", translate.Source },
    { "target", translate.Target },
    { "api_key", translate.ApiKey },
    **{ "format", "html" }**
});

I got it working so thank you for your time in replying, really appreciate it.

Regards

J

1 Like