Search code examples
google-translategoogle-translation-api

Skip specific terms with google tranlsate API


I'm using Google Translate API and I want to know how to make it "skip" some phrases which should not be translated.

I found that if I surround the phrase with <> it seems to be working:

client.translate('Hey friend, bring me a <cold beer>.', target_language='it', source_language='en')

Output:

{'input': 'Hey friend, bring me a <cold beer>.', 'translatedText': 'Ehi amico, portami un <cold beer> .'}

While if I remove the <> it's translated:

{'input': 'Hey friend, bring me a cold beer.', 'translatedText': 'Ehi amico, portami una birra fredda.'}

It this the right way to do it? I couldn't find it anywhere in the docs


Solution

  • The correct way would be using these HTML tags as Translation API doesn't translate any HTML tags. The API is thinking that you're using an HTML tag when you're using the caret brackets within your request.