Google Translation Extension

Google Translate Extension


Hello everyone,
I hope you all are doing well, before some time I have seen someone has requested for translation function in his/her app, so I have created a simple GoogleTranslate extension with the help of Google App Script.

Blocks


GotTranslatedText

component_event

Description: Event raised when translated text got.
Params:

  1. translatedText: String value of source text in the target language.

TranslateText

component_method

Description: Translate your text to the target language from the source language.
Params:

  1. text: String value of source text that you want to translate.
  2. sourceLang: Source language code given by Google.
  3. targetLang: Target language code given by Google,

language codes

APIKey

Description: Set your own deployment key after deployment in case if you don't want to deploy your own web app use this key

KEY

AKfycbwUHkkdLJU5eIgLxErRCxtDpbs4_qz3P48RXbWstMYvA8ClmU56qT7pdcBpQ_S_7FX1

Google App Script


Step: 1

Go to Google App Script and create a new project. link

Step: 2

Copy the given script and paste it into your project.
Click on the save button and deploy it.

function doGet(e) {
  let sourceLang = e.parameters.sl;
  let destLang = e.parameters.dl;
  let text = e.parameters.text;
  let transletedText = LanguageApp.translate(text.toString(), sourceLang.toString(), destLang.toString());
  return ContentService.createTextOutput(transletedText).setMimeType(ContentService.MimeType.JSON);
}

Step : 3

Set the deployment configuration shown in the given picture, now hit on the deploy button and copy-paste it into App Inventor.

Note


  1. The default deployment key and the key which you see in the picture is only for testing, I am not sure it will help you in the future or not, so I recommend you deploy your own script as a web app.
  2. If you find any kind of problem then, please write in this thread.

Download Link


GoogleTranslate (2).aix (6.5 KB)

Thanks and Regards
Preet P. Vadaliya

13 Likes

You can request 5000 times in a day with your free Google account, for more information you can see this page...

Quotas for Google Services  |  Apps Script  |  Google Developers

Nice extension...

But I think you should rename APIKey to ApiKey, since API is one term.

The YandexTranslate component uses the ApiKey naming convention.

But still, great extension.

3 Likes

https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=hi&dt=t&q=you+can+use+this

you can use this also to translate

1 Like

(added to FAQ)

1 Like

I have everything setup but when I translate the label is blank

Have you deployed your own version of Google Apps Script?

Yes I deployed my own google apps script and put my key into the correct block


That is what I have as far as blocks and I am doing
Source: en
Target: es
Text: Hello

You are doing wrong.

First you need to call TranslateText method using button when text translated it will raised GotTranslatedText event.

What am I doing wrong?

blocks(1)

2 Likes

hi guys good morning, with my key the translator doesn’t work.
How can I find my exact key?

i copied the script

I clicked on SHARE
I went to public, then distribute as a web application, I put on ANYONE, I copied current web app url and I took the highlighted part:

Nowhere are you told to click on SHARE.....the script should remain restricted to you.

Your problem is possibly when you publish the script. You appear to be using the legacy script editor. When you publish the web app, the app should be run as Me - your google account and accessible to Anyone - even anonymous

2 Likes

@TIMAI2 nice guidence.

2 Likes

So I have everything set up similar to how you have it set up but when I try to translate the text it says that is can't find the google translate component. If you could help me I would appreciate it.
-Thanks

Use Android to test extensions. iOS does not have extension functionality.