Google translate - Disable translating of a part of my text
I want to add a simple way to not translate text between double quotes is using for loop.
var text = "This is the \"Word\" I dont want to translate.";
var splitText = text.Split(" ").ToList();
bool Found = false;
string temp = string.Empty;
for (int i = 0; i < splitText.Count; i++)
{
if (splitText[i].Contains("\"") && !Found)
{
splitText[i] = "<span class='notranslate'>" + splitText[i];
Found = true;
temp = splitText[i];
}
if (splitText[i].Contains("\"") && Found && splitText[i] != temp)
{
splitText[i] = splitText[i] + "</span>";
Found = false;
}
}
text = String.Join(" ", splitText).ToString();
As you can see, I add a span with notranslate class into every double quote.
Edit (Sep. 2020): Seems that with some API changes this solution is not applicable anymore (at least on the web).
Protecting parts of the string from translation is possible by wrapping them in a <span>
tag with a specific class value (as explained here):
<span class="notranslate">[bold]</span>
Example
Also, Google Translate API will provide you with more flexibility if you don't mind paying a small fee ($20 per 1 M characters).
Just add notranslate class class="notranslate"
where you need and google translator do not touch it..
https://cloud.google.com/translate/v2/faq#technical