How to Make a Translator

Материал из Поле цифровой дидактики
Описание 120px-Tranlate_scratch.png
  • Как создать программу переводчик используя расширение перевода в среде Scratch
Область знаний
Область использования (ISTE)
Возрастная категория


Поясняющее видео
Близкие рецепту понятия
Среды и средства для приготовления рецепта:

Tranlate scratch.png

A Translator is a project which can change words into different languages using the Translate Extension. This tutorial will show how to make a translator.

Preparation

You will need one sprite to store all the code:

  • Button

Two variables will be also needed to store the language entered as well as the word the user wants to translate.

  • (to language)
  • (word)

Two broadcasts will be needed to tell the project when to ask for the language. (It will do this after the word is given by the user.):

  • broadcast (original v)
  • broadcast (to what v)

Programming The Translator

Add the following code to the button.

    
when green flag clicked 
broadcast (original v) //This broadcasts a message so that the project knows to ask for the word.

when I receive [original v]
say [Click this button to translate.]
wait until <<touching (mouse-pointer v)> and <mouse down?>> //This waits until the button is clicked.
say []//This is so it stops saying "Click this button to translate."
ask [What shall be translated? Please only enter real words or the translator will not work.] and wait
set [word v] to (answer) //This stores the word that the user entered inside of a variable. This is an important part!
broadcast (to what v) //This tells the program that it should ask for the language next.

when I receive [to what v]
ask [To what language?] and wait
set [to language v] to (answer)
if <(translate (word) to (to language)) = (word)> then //This is to make sure a supported language is entered.
say [Please enter a supported language.] for (2) seconds //If a supported language isn't entered, this code will say "Please enter a supported language."
broadcast (to what v) //This asks the project to ask the user "What language?" again.
else
say (translate (word) to (to language)) 
wait until <<touching (mouse-pointer v)> and <mouse down?>>
say []
broadcast (original v)

Your translator is now ready!