package org.myrobotlab.service;

import org.myrobotlab.framework.Service;
import org.myrobotlab.framework.repo.ServiceType;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.Logging;
import org.myrobotlab.logging.LoggingFactory;
import org.slf4j.Logger;

public class AzureTranslator extends Service {

	private static final long serialVersionUID = 1L;

	public final static Logger log = LoggerFactory.getLogger(AzureTranslator.class);

	public static void main(String[] args) {
		LoggingFactory.getInstance().configure();
		LoggingFactory.getInstance().setLevel(Level.INFO);

		try {

			AzureTranslator translator = (AzureTranslator) Runtime.start("translator", "AzureTranslator");
			Runtime.start("gui", "GUIService");

		} catch (Exception e) {
			Logging.logError(e);
		}
	}

	public AzureTranslator(String n) {
		super(n);
	}
	
	/**
	 * This static method returns all the details of the class without
	 * it having to be constructed.  It has description, categories,
	 * dependencies, and peer definitions.
	 * 
	 * @return ServiceType - returns all the data
	 * 
	 */
	static public ServiceType getMetaData(){
		
		ServiceType meta = new ServiceType(AzureTranslator.class.getCanonicalName());
		meta.addDescription("interface to Azure translation services");
		meta.addCategory("translation", "cloud", "ai");		
		meta.addDependency("com.azure.translator");
		return meta;		
	}

	
}

@@ -1,8 +1,217 @@
+/**%0A * Azure Translator by Microsoft - Service%0A * %0A * @author Giovanni Mirulla (Papaouitai), thanks GroG and kwatters%0A * %0A *         References : https://github.com/boatmeme/microsoft-translator-java-api %0A */%0A
 package 
@@ -517,16 +517,178 @@
 .Logger;
+%0Aimport com.memetix.mst.language.Language;%0Aimport com.memetix.mst.detect.Detect;%0Aimport com.memetix.mst.translate.Translate;%0Aimport com.sun.tools.javac.util.List;
 %0A%0Apublic
@@ -779,17 +779,77 @@
 D = 1L;%0A
+    %0A%09String toLanguage = %22it%22;%0A%09String fromLanguage = null;
 %0A
-
 %09public 
@@ -962,16 +962,33 @@
 %5B%5D args)
+ throws Exception
  %7B%0A%09%09Log
@@ -1079,17 +1079,16 @@
 .INFO);%0A
-%0A
 %09%09try %7B%0A
@@ -1337,16 +1337,937 @@
 );%0A%09%7D%0A%09%0A
+%09public String translate(String toTranslate) throws Exception%7B%0A%09%09String translatedText = null;%0A%09%09if (fromLanguage == null)%7B%0A%09%09%09translatedText = Translate.execute(toTranslate, Language.AUTO_DETECT, Language.fromString(toLanguage));%0A%09%09%7D%0A%09%09else%7B%0A%09%09%09translatedText = Translate.execute(toTranslate, Language.fromString(fromLanguage), Language.fromString(toLanguage));%0A%09%09%7D%0A%09%09return translatedText;%0A%09%7D%0A%09public Language detectLanguage(String toDetect) throws Exception%7B%0A%09    Language detectedLanguage = Detect.execute(toDetect);%0A%09%09return detectedLanguage;%0A%09%7D%0A%09public void setCredentials(String clientID, String clientSecret)%7B%09%0A%09%09Translate.setClientId(clientID);%0A%09    Translate.setClientSecret(clientSecret);%0A%09%09Detect.setClientId(clientID);%0A%09    Detect.setClientSecret(clientSecret);%0A%09%7D%0A%0A    public void fromLanguage(String from)%7B%09%0A    fromLanguage = from;%0A    %7D%0A    public void toLanguage(String to)%7B%09%0A    toLanguage = to;%0A    %7D%0A
 %09/**%0A%09 *
@@ -2811,10 +2811,11 @@
 %09%0A%09%7D%0A%0A%09%0A
-
 %7D%0A
+%0A

Update AzureTranslator.java