include "console.iol"
include "json_utils.iol"
include "exec.iol"

outputPort GoogleTranslate {
Location: "socket://translate.googleapis.com:443/translate_a/single"
Protocol: https {
  .osc.translate.alias = "?client=gtx&sl=it&tl=%{tolang}&dt=t&q=%{q}";
  .osc.translate.method = "get"
}
RequestResponse: translate 
}

main
{
  tinyRequest = "dotnet.exe ./TinyGrammar/NetCore/MB.TinyGrammar.NetCoreConsoleApp.dll ./TinyGrammar/tecnicheseGrammarExample.txt";
  tinyRequest.stdOutConsoleEnable = false;

  exec@Exec( tinyRequest )( tecnichese );
  translate@GoogleTranslate( { .q = tecnichese, .tolang = args[0] } )( response );

  // Print results
  println@Console( tecnichese )();

  // Google Translate splits response in sentences, loop is needed
  for( line in response._._ ) {
    println@Console( line._ )()
  }
}