Purpose
Automatically translate a long text in an SAP transaction

Solution
Use an online tool for automatic translation (like DeepL, Google Translate,...) in an invisible window.

Example
In transaction MM02 we offer the automatic translation of the sales text into several languages:


The translation is done in the background:

 

The sales text is now created in all desired languages:

 

The new translations are also inserted when existing texts are changed:

 

Outcome:

 

 

Video


Show video in full screen


GuiXT Script:

Pushbutton  (25,1)  "Translate English text to French/German/Italian"                 process="translate.txt"


InputScript:

// read text from SAP text control (aynchronously)

CallVBAsync guinet.textcontrol.gettext textname:="oldtext"

 

// create an invisible webview window

webview (0,0) (30,200)  "about:blank" name="deepl"  -invisible

 

// connect to this window

connectHTML name="deepl"

 

// target languages

set V[languages] "F=fr,D=de,I=it"  // to French, German and Italian

 

// show status message

StatusMessage title="Automatic translation..."

 

label translate

 

// current language

set V[current_language] "&V[languages](1-1)"

set V[current_language2] "&V[languages](3-4)"

 

StatusMessage addString="Translating to &V[current_language2]"

 

// Create text

Enter "=TEAN"          

 

// set source and target language

Screen SAPLMG19.1000

  Set F[Create text in] "&V[current_language]"

  Set F[Copy from]      "E"

  Enter 

 

Screen SAPLMGMM.4040

 

  // open deepl with correct languages

  connectHTML  

    seturl="https://www.deepl.com/translator/en//&V[current_language2]"

 

  // clear text areas in deepl window 

  Clear html[textarea]

  Clear html[textarea.2]

 

  // set text to translate

  connectHTML  item="textarea" fromText="oldtext"

 

  // we now need to wait a little bit until the translated text appears

  Set V[repeatcount] 0

  label repeat

  connectHTML item="textarea.2" toText="newtext"

  if text[oldtext] and not text[newtext]

    Set V[repeatcount] &V[repeatcount] + 1

    if V[repeatcount<1000]

      goto repeat

    endif

    copyText fromText="oldtext" toText="newtext"

    Message "E: No translation" 

  endif

 

  // set translated text into SAP text control

  CallVBAsync guinet.textcontrol.settext textname:="newtext"

 

 

  // next language

  Set V[languages] "&V[languages](6-100)"

 

  // any language left?

  if V[languages]

    goto translate

  endif

 

  // close the hidden deepl window 

  connectHTML  -closewindow

 

  // close the status message window

  StatusMessage -remove

 

  // no further action on this screen

  Enter ?

 

Components
InputAssistant + Controls