Translator Component


Properties

apiKey
  The API Key to use. MIT App Inventor will automatically fill this value in. You should not need to change it.
Data type: string
Designer Writable true <translator name="translatorName" apiKey="">
Code Writeable true translatorName.apiKey = ""
Code Readable false

class
  The styling class of the the component
Data type: string
Designer Writable true <translator name="translatorName" class="Test class">
Code Writeable false
Code Readable false

id
  The styling id of the the component
Data type: string
Designer Writable true <translator name="translatorName" id="Test id">
Code Writeable false
Code Readable false

name
  The name of the component that will be used to refer to it in code.
Data type: string
Designer Writable true <translator name="translatorName" name="testComponent">
Code Writeable false
Code Readable false

Methods

Method name Description Parameters
requestTranslation By providing a target language to translate to (for instance, 'es' for Spanish, 'en' for English, or 'ru' for Russian), and a word or sentence to translate, this method will request a translation. Once the text is translated by the external service, the event GotTranslation will be executed. Note: Translator will attempt to detect the source language. You can also specify prepending it to the language translation, e.g., es-ru will specify Spanish to Russian translation.
translatorName.requestTranslation(languageToTranslateTo, textToTranslate)
translatorName.requestTranslation("en-es", "Hello world!")
languageToTranslateTo string
textToTranslate string
addEventListener Method used to create event listeners.
See Events below for samples.
eventName string
eventCallbackFunction callback

Events

Event name Description Parameters
gotTranslation Event indicating that a request has finished and has returned data (translation).
translatorName.addEventListener(
    "gotTranslation",
    function (responseCode, translation) {
        //Your code here
    }
)
responseCode string
translation string