Another cool extension in Scratch is the Google Translate extension. Follow along to create an interactive translator inside Scratch!
Create a new project. Then, as before, click the “Add Extension” button; this time, select the “Translate” extension. Click the picture to enlarge it.
We will need two variables for this project. As in previous projects, navigate to the “variables” section and click “Make a variable.” Make one variable named “language” and one named “message.”
You can leave them checked or unchecked, depending on if you would like them to appear in your finished project.
The code above will create a program that prompts the user for what language they would like to translate to, as well as the message they would like translated, and then translates the message
from English to their chosen language. Read below to see how each block works!
-
When green flag clicked: The blocks below will run every time the green flag is clicked.
-
Ask (What language would you like to translate to?) and wait: This block will pose the question, “What language would
you like to translate to?” and wait until the user types an answer before continuing. The answer will be stored in a temporary variable called “answer,” which is automatically created.
-
Set (language) to (answer): As mentioned before, “answer” is a temporary variable, and it will be overwritten the next
time a question is asked. To save the language preference the user has specified, we will save “answer” to “language” so we can keep it permanently.
-
Ask (What would you like translated?) and wait: As before, our sprite will ask the question “What would you like
translated?” and wait for the user to type a response. The response will then be stored in the “answer” variable (this will overwrite what was previously stored here, which is why it was
important to create a copy in the previous step)
-
Set (message) to (answer): As before, we want to save what is stored in “answer” permanently, so we will copy it to our
“message” variable
-
Say (join <in> <language>) for (1) seconds: The join block will combine the word “In” with the language the
user specified. For example, if a user typed “Spanish,” the final product after this join block would be “In Spanish.” The say block will make the sprite say “In Spanish.”
-
Say (join <That’s…> <translate {message} to {language}>) for (20) seconds): There’s quite a bit going on in
this block, so let’s unpack it! The language block takes two inputs - the message in English to be translated, and the language it is to be translated to. Since the user’s message is stored
in “message” and their preferred language is stored in “language,” we feed these variables to the translate block so that it can translate our message. Then, we join “That’s…” with that
result to create a final result of “Thats…(translated message).” Finally, the say block makes our sprite say this for 20 seconds.
To give an example of what this program may look like in practice, assume the user types in “Spanish” as their language and “I have a red house” as their message. The final dialogue from our
sprite would be “In Spanish that’s…tengo una casa roja.” Voila, a fully functional translator embedded inside Scratch!
Source: https://www.create-learn.us