11

How do I Google Translate such that all desired texts are left untranslated?

For example, when translating “Have you tried the Clipboard History window” to Hindi, the “Clipboard History Window” is translated to Hindi instead of being left as it is, as it is a technical term.

I have tried <span class=notranslate> but as it should be, it is valid only in HTML.

1
  • 1
    How about removing the respective text from the translation? Or replacing it with something generic?
    – Alex
    Dec 2, 2013 at 12:18

7 Answers 7

2

I don't think there's any special tag or character to insert to keep the text untranslated in Google's Translate form.

But since you are willing to manually add tags to keep your text untranslated, a trick is to prefix each word that you want to keep untranslated with a random string, for example "KEEP".

So Have you tried the KEEPClipboard KEEPHistory KEEPwindow will be translated to आप KEEPClipboard KEEPHistory KEEPwindow की कोशिश की and then with a text editor replace all "KEEP" with an empty string.

Definitely not the best work around, but there you go :)

4
  • That will do. I needed this in the program and so managing prefixed words and replacing them back wont be trouble.
    – Avi
    Dec 3, 2013 at 9:59
  • With Hindi that workaround seems to work, but with other languages Google Translate is being smart and translates each hump separately: OLOLOLOHistory -> OLOLOLOHИстория (russian)
    – Klesun
    Mar 2, 2021 at 11:41
  • Tried in french, it seems prefix + uppercase works but you will need some way to put the original case back somehow. Sep 5, 2023 at 7:02
  • @NicolasBraun I just posted an answer Oct 13, 2023 at 15:15
2

I found the answer, for anyone else who might be looking. You just add the class "notranslate" to your element and Google Translate will leave it untranslated.

Ref: https://cloud.google.com/translate/troubleshooting

2
  • 1
    Just tried it on my website and adding class="notranslate" is working. Thanks!
    – Chris
    Sep 19, 2018 at 6:30
  • It's not clear how this answers the question. The OP has provided a specific example using a link that opens the Text translation mode of Google Translate, actually, the OP mentioned having tried adding the class "notranslate". Using this alternative implies using a different Google Translate mode, either Document by providing an HTML document or Website. Oct 13, 2023 at 14:02
2

The "notranslate" trick does not seem to work anymore. What I came up with was such workaround:

  1. In the source text replace all occurrences of the phrase you want to preserve with some big unique number (using any text editor)
  2. Translate
  3. In the result of the translation replace all occurrences of this unique number back to the phrase

Example:

# source text
"Have you tried the Clipboard History window"
# 1. replace "Clipboard History" occurrences with a 0x18482facba482 ->
"Have you tried the 0x18482facba482 window"
# 2. translate -> 
"क्या आपने 0x18482facba482 विंडो की कोशिश की है"
# 3. replace number occurrences back to the phrase ->
"क्या आपने Clipboard History विंडो की कोशिश की है"
1

The question is about using the Text mode of Google Translate. It asks how to prevent Google Translate from translating a part of the text on the left side box.

Unfortunately, the Text mode has no built-in way to tell the tool not to translate a part of the text.

Options

  1. Do not include the part of the text not to be translated.
  2. Paste the complete text, then remove the part so as not to be translated.
  3. Replace the part(s) not to be translated by placeholder(s) to later replace it(them) with the corresponding part(s).

Placeholder

Sometimes, it is enough to put the word or phrase between symbols not used regularly, i.e., underscore. To have something that works all the time, it's better to use a sequence of symbols that are not letters and that do not have a direct word representation. One digit or small sequence of digits is unsuitable because, in some languages, they are written using words instead of numbers so that Google Translate might translate them.

If you have a creativity blockage, one option to quickly generate a unique placeholder is to use the JavaScript console of the Web Browser and Date.now() to generate a sequence of 13 digits, which is large enough to prevent from being translated, I think. It's not random, I know. Still, it will be unique whenever you type this JavaScript method, as it returns the current time in milliseconds.

Complex cases

If you have complex cases, forget about using the Text mode of Google Translate. Google Translate has other modes, is integrated into Google Chrome, Google Docs, and Google Apps Scripts, and has an API. There are browser extensions and apps that use it and other services.

0

to expand on the "replace html with unique placeholders" solution:

i found that google, in rare cases, also translates numbers!
for example google translated [15] to [fünfzehn] in english to german.

my current solution is to encode my index numbers with special characters.
the 12 safe symbols that are never changed by google are []^'*-/_{}<> (can change in future).
(todo: test more combinations of symbols and languages. can be automated.)
note: google can replace -- with -, for example, so i also avoid repetitions.
$ is also preserved, but the order can be changed, e.g. from @$ to $@

const codeNumKey = "^'*-/_{}<>"; // 10 digits = 0123456789
const codeNumBase = codeNumKey.length;

const encodeNumTable = Object.fromEntries(codeNumKey.split('').map((c, i) => [i, c]));
function encodeNum(num) {
  return num.toString(codeNumBase).split('').map(i => encodeNumTable[i]).join('');
}

const decodeNumTable = Object.fromEntries(codeNumKey.split('').map((c, i) => [c, i]));
function decodeNum(str) {
  return parseInt(str.replace(/[\s+\u200B]/sg, '').split('').map(c => decodeNumTable[c]).join(''), codeNumBase);
}

// google can translate -- to -
// so we use "safe" ids without repetition
function getNextSafeId(lastId) {
  for (let id = (lastId + 1); ; id++) {
    let idStr = id.toString();
    let idSafe = true;
    for (let charIdx = 0; charIdx < (idStr.length - 1); charIdx++) {
      if (idStr[charIdx] == idStr[charIdx + 1]) {
        // found repetition
        idSafe = false;
        //if (showDebug) console.log(`skip unsafe id ${id}`);
        break;
      }
    }
    if (idSafe) return id;
  }
}

google will insert spaces (\x20) and zero-width spaces (\u200B) between the characters, so we must parse them too. i remove \u200B completely, cos i dont have it in my input text

i also encode indents, because google will change indent, for example add one space before every line

sample input:

  <div>
    <b>hello</b>
  </div>

encoded:

[}^_]

[}^{]
hello
[}^}]

[}^<]

translated:

[ } ^ _ ]

[ } ^ { ]
こんにちは
[ } ^ } ]

[ } ^ < ]

decoded numbers:

decodeNum(String.raw`[ } ^ _ ]`) == 705
decodeNum(String.raw`[ } ^ { ]`) == 706
decodeNum(String.raw`[ } ^ } ]`) == 707
decodeNum(String.raw`[ } ^ < ]`) == 708

output:

  <div>
    <b>こんにちは</b>
  </div>

my translate script has 700 lines, but also includes code to extract and insert text into my html source files. maybe someone wants to refactor this into a library? : )

im using the official webinterface of google translate, so i can fix translations with the help of google's dictionary. this can be an advantage, compared to other tools like doctranslate

my use case: translate my book of 30 pages html, with bold text, custom xml tags, custom html entities, pre tags, tables, ... working stable so far

update: this fails on complex texts, where google translate can change the order of words in a sentence, and then also the order of html tags is broken. so currently, im converting my html to docx, let google translate the docx file, and then i convert back from docx to html.

2
  • It's not clear how this answers the question. The OP has provided a specific example using a link that opens the Text translation mode of Google Translate. Please bear in mind that each post should be self-contained and answers, should answer the question. Ref. How to Answer. Oct 13, 2023 at 13:57
  • agree, my answer is not very helpful. im still in the process of fighting google translate... i prefer the text mode, because it preserves sentences until \n, so translation quality is better. but the translation is lossy, for example, it can remove random sentences. my input has about 100*5000 characters. probably i will use some offline translator like argos-translate
    – milahu
    Oct 14, 2023 at 9:11
-1

I replace each unique "tag" that I want to preserve in the text untranslated with a big unique number. After receiving the translation, google keeps it unaltered, so I can look for it and replace it back.

With the catches:

  • for some languages, the number gets commas inserted in them. So on your way back, look for both "20,397,620,437,620,342,340,200" and "20397620437620342340200".
  • If the tag is usually included inside brackets or so, you don't need empty spaces around the number inserted. If it might not, then safer to add spaces around it, to make sure the translator doesn't consider the word before/after as part of the non-lingual alphanumeric and omit translating that word.
  • You will have to assign a big number for each tag you want to preserve. So your dictionary can't be infinite. And it adds cycles to your parser.
1
-1

Failed Attempt

I tried to URL encode my text and slap that as part of a url, for example:

#Source line
When Bluetooth is on, you should see a <i class="fa fa-bluetooth-b" aria-hidden="true"></i> icon in the top bar of your phone. 
#Text to keep untranslated
<i class="fa fa-bluetooth-b" aria-hidden="true"></i>
#Text URL escaped in line with a site attached
When Bluetooth is on, you should see a https://www.donttranslate.com/%3Ci%20class%3D%22fa%20fa-bluetooth-b%22%20aria-hidden%3D%22true%22%3E%3C%2Fi%3E icon in the top bar of your phone.

And use the REGEX of:

\bhttps://www.donttranslate.com/([a-zA-Z0-9%.\-_]*)\b

If the non-replace text includes a % sign, this seems to often fail, and since encoding is about turning symbols into %xx, it's a crap shoot. It can work with some two word combined, such as MyLogo, but I noticed for the above example, aiming for IceCream caused German to do:

When Bluetooth is on, you should see a IceCream icon in the top bar of your phone. 
Wenn Bluetooth eingeschaltet ist, sollten Sie ein https://www.donttranslate.com/IceCream-Symbol in der oberen Leiste Ihres Telefons.

I was really hopeful that URLs would be recognized as a "don't mess with so that the link still works" but this isn't the case.

Solution Used

A different solution I tried was using [§1] similar to how Rafik Mikhael and Klesun did, and having a lookup table for what each number translated to. This ran into the issue that languages would do one of three things to it. Leave it as [§1], move it to [§ 1], or move it to [1.§]. This has been my most consistent solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.