All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hn.translation.impl.JinshanTranslator Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.translation.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hn.translation.AbstractOnlineTranslator;
import com.hn.translation.LANG;
import com.hn.translation.annotation.TranslatorComponent;

import java.util.HashMap;
import java.util.Map;

@TranslatorComponent(id="jinshan")
public final class JinshanTranslator
  extends AbstractOnlineTranslator
{
  public JinshanTranslator()
  {
    this.langMap.put(LANG.EN, "en");
    this.langMap.put(LANG.ZH, "zh");
  }
  
  protected String getResponse(LANG from, LANG targ, String query)
    throws Exception
  {
    Map params = new HashMap();
    params.put("f", (String)this.langMap.get(from));
    params.put("t", (String)this.langMap.get(targ));
    params.put("w", query);
    
    return HttpUtil.get("http://fy.iciba.com/ajax.php?a=fy",params);
  }
  
  protected String parseString(String jsonString)
  {
    JSONObject jsonObject = JSONUtil.parseObj(jsonString);
    String result = jsonObject.getJSONObject("content").getStr("out");
    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy