Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Google Translate API support placeholders?

Let's say I have a tweet I'll like to translate through the google api.

Text: #sf #fiesta #verano #baile #vamos Fiesta aquí 😎 @my_friend

I'm sending the following to the API endpoint https://www.googleapis.com/language/translate/v2:

{1 /} {2 /} {3 /} {4 /} {5 /} Fiesta aquí 😎 {0 /}

This is the response:

{1} {2} {3}} {4} {5}} party over here {0}

This is not what I expected. However, I would like to put in placeholders otherwise the actual hashtags get translated and that doesn't point to the same results as the original tweet.

There's no mention of placeholders on the API docs, so I guess I'm not too surprised that it failed. Maybe they aren't supported. The only thing I've found is this and I'm not sure that it's related.

Is there a documented way to get this working ?

like image 877
cat3045 Avatar asked Jul 10 '17 18:07

cat3045


People also ask

Should placeholders be translated?

Some placeholders will include actual words, such as {{MoreInfoButton/}} to describe what the placeholder refers to. However, when translating, the entire placeholder (including any actual words that you would normally translate if they were not in a placeholder) should be kept intact and untranslated.

Does Google translation API support secure connections?

Does the Google Translate API support secure connections? Yes, we provide SSL connection support for secure connectivity to the Translate API.

Is there any API for Google Translate?

One of the most popular translation APIs out there is the Google Translate API. The Google Translate API uses machine learning to decipher text and allows developers to easily integrate translation functionality into their website(s) or mobile app(s).

How accurate is Google Translate API?

The answer to how accurate Google translate is is 85%, according to a survey conducted by Google in 2017. Google Translate is a simple-to-use software that allows you to interact quickly and learn foreign languages. The translation service switches text and speech back into any language.


1 Answers

I just tried the Google Translate API with the text containing the hashtags and the Translate API seems to be already taking care of the hashtags as well as @ mentions. It does not translate any of the hashtags or the @ mentions.

Example

$ echo '{q: ["#sf #fiesta #verano #baile #vamos Fiesta aquí 😎 @my_friend"], source: "es", target: "en" }' | http --print=bB POST 'https://translation.googleapis.com/language/translate/v2?key=MY_API_KEY'

{
    q: ["#sf #fiesta #verano #baile #vamos Fiesta aquí 😎 @my_friend"],
    source: "es",
    target: "en"
}


{
    "data": {
        "translations": [
            {
                "translatedText": "#sf #fiesta #verano #baile #vamos Party here 😎 @my_friend"
            }
        ]
    }
}

Skip translation for a portion of the text

If you want a piece of text to not be translated you can enclose it within <span class="notranslate">CONTENT_NOT_TO_BE_TRANSLATED</span>. You should then be able to replace all such span blocks in the result with just the content within using some simple regex pattern replace operation.

$ echo '{q: ["#sf #fiesta #verano #baile #vamos <span class=\"notranslate\">Fiesta</span> aquí 😎   @my_friend"], source: "es", target: "en" }' | http --print=bB POST 'https://translation.googleapis.com/language/translate/v2?key=MY_API_KEY'

{
    q: ["#sf #fiesta #verano #baile #vamos <span class=\"notranslate\">Fiesta</span> aquí 😎   @my_friend"],
    source: "es",
    target: "en"
}


{
    "data": {
        "translations": [
            {
                "#sf #fiesta #verano #baile #vamos <span class=\"notranslate\">Fiesta</span> here 😎 @my_friend"
            }
        ]
    }
}
like image 152
Tuxdude Avatar answered Nov 15 '22 09:11

Tuxdude