• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Translate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.api.translate.Translate的典型用法代码示例。如果您正苦于以下问题:Java Translate类的具体用法?Java Translate怎么用?Java Translate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Translate类属于com.google.api.translate包,在下文中一共展示了Translate类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: translate

import com.google.api.translate.Translate; //导入依赖的package包/类
static String translate(String sourceLanguageCode, String targetLanguageCode, String sourceText) {
    Log.d(TAG, sourceLanguageCode + " -> " + targetLanguageCode);

    // Truncate excessively long strings. Limit for Google Translate is 5000 characters
    if (sourceText.length() > 4500) {
        sourceText = sourceText.substring(0, 4500);
    }

    GoogleAPI.setKey(API_KEY);
    GoogleAPI.setHttpReferrer("https://github.com/rmtheis/android-ocr");
    try {
        return Translate.DEFAULT.execute(sourceText, Language.fromString(sourceLanguageCode),
                Language.fromString(targetLanguageCode));
    } catch (Exception e) {
        Log.e(TAG, "Caught exeption in translation request.");
        return Translator.BAD_TRANSLATION_MSG;
    }
}
 
开发者ID:hujiaweibujidao,项目名称:android-ocr-demo,代码行数:19,代码来源:TranslatorGoogle.java


示例2: googleValidator

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * 访问goolge api以验证 Key是否可用。 ;
 */
private void googleValidator() {
	final String googleKey = googleKeyText.getText();
	BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

		public void run() {
			// TODO Auto-generated method stub
			if (googleKey != null && !googleKey.trim().equals("")) {
				GoogleAPI.setHttpReferrer("http://www.heartsome.net");
				GoogleAPI.setKey(googleKey);
				try {
					String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
							GoogleTransUtils.processLanguage("zh-CN"));
					if (result.equals("测试")) {
						googleState = true;
					}
				} catch (GoogleAPIException e) {
					googleState = false;
				}
			} else {
				googleState = false;
			}
		}
	});
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:28,代码来源:MachineTranslationPreferencePage.java


示例3: executeMatch

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher#executeMatch(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)
 */
public String executeMatch(TransUnitInfo2TranslationBean tuInfo) {
	try {
		String srcText = tuInfo.getSrcPureText();
		String srcLang = tuInfo.getSrcLanguage();
		String tgtLang = tuInfo.getTgtLangugage();
		String result = Translate.DEFAULT.execute(srcText, GoogleTransUtils.processLanguage(srcLang),
				GoogleTransUtils.processLanguage(tgtLang));
		result=TextUtil.convertMachineTranslateResult(result);
		if (result != null) {
			return InnerTagClearUtil.clearTmx4Xliff(result);
		}
	} catch (GoogleAPIException e) {
		return "";
	}
	return "";
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:21,代码来源:SimpleMatcherGoogleImpl.java


示例4: validator

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * 访问api以验证 Key是否可用。 ;
 */
private void validator() {
	final String googleKey = googleKeyText.getText();
	BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

		public void run() {
			// TODO Auto-generated method stub
			if (googleKey != null && !googleKey.trim().equals("")) {
				GoogleAPI.setHttpReferrer("http://www.heartsome.net");
				GoogleAPI.setKey(googleKey);
				try {
					String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
							GoogleTransUtils.processLanguage("zh-CN"));
					if (result.equals("测试")) {
						state = true;
					}
				} catch (GoogleAPIException e) {
					state = false;
				}
			} else {
				state = false;
			}
		}
	});
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:28,代码来源:GooglePreferencePage.java


示例5: executeMatch

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher#executeMatch(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)
 */
public String executeMatch(TransUnitInfo2TranslationBean tuInfo) {
	try {
		String srcText = tuInfo.getSrcPureText();
		String srcLang = tuInfo.getSrcLanguage();
		String tgtLang = tuInfo.getTgtLangugage();
		String result = Translate.DEFAULT.execute(srcText, GoogleTransUtils.processLanguage(srcLang),
				GoogleTransUtils.processLanguage(tgtLang));

		// 处理字符转义,有可能翻译的字符有一部分是转义了的,而另一部没有转义
		//bug:3317 fixed by yule 2013-7-26
		String resetSpecialString = TextUtil.resetSpecialString(result);
		result = TextUtil.cleanSpecialString(resetSpecialString);
		if (result != null) {
			return result;
		}
	} catch (GoogleAPIException e) {
		return "";
	}
	return "";
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:25,代码来源:SimpleMatcherGoogleImpl.java


示例6: executeMatch

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher#executeMatch(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)
 */
public String executeMatch(TransUnitInfo2TranslationBean tuInfo) {
	try {
		String srcText = tuInfo.getSrcPureText();
		String srcLang = tuInfo.getSrcLanguage();
		String tgtLang = tuInfo.getTgtLangugage();
		String result = Translate.DEFAULT.execute(srcText, GoogleTransUtils.processLanguage(srcLang),
				GoogleTransUtils.processLanguage(tgtLang));
		if (result != null) {
			return result;
		}
	} catch (GoogleAPIException e) {
		return "";
	}
	return "";
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:20,代码来源:SimpleMatcherGoogleImpl.java


示例7: translateString

import com.google.api.translate.Translate; //导入依赖的package包/类
public String translateString( String source ) {
    String translatedText = "";
    GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
    //Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
    try {
        translatedText = Translate.execute(source, Language.ENGLISH, Language.FRENCH);
    } catch (Exception e) {
        System.err.println( "Exception " + e.getMessage() );
    }
    return removeSpaces ( translatedText );
}
 
开发者ID:dozed,项目名称:align-api-project,代码行数:12,代码来源:RenameThings.java


示例8: translate

import com.google.api.translate.Translate; //导入依赖的package包/类
public static String translate(String from, String to, String string) {
    try {
        Language lfrom = Language.fromString(from);
        Language lto = Language.fromString(to);
        log.debug("translate: {}, {}, {}", string, lfrom, lto);

        return Translate.DEFAULT.execute(string, lfrom, lto);
    } catch (Exception e) {
        log.error("translate: ", e.getMessage(), e);
        return null;
    }
}
 
开发者ID:esutoniagodesu,项目名称:egd-web,代码行数:13,代码来源:GoogleTranslateService.java


示例9: bingValidator

import com.google.api.translate.Translate; //导入依赖的package包/类
/**
 * 访问bing api是否可用 ;
 */
private void bingValidator() {

	BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
		public void run() {
			String id = idText.getText();
			String bingKey = bingKeyText.getText();
			if (bingKey != null && !bingKey.trim().equals("") && id != null && !id.equals("")) {
				com.memetix.mst.translate.Translate.setClientId(id);
				com.memetix.mst.translate.Translate.setClientSecret(bingKey);
				try {
					String result = com.memetix.mst.translate.Translate.execute("test",
							BingTransUtils.processLanguage("en-US"), BingTransUtils.processLanguage("zh-CN"));
					if (result.equals("测试")) {
						bingState = true;
					} else {
						bingState = false;
					}
				} catch (Exception e) {
					bingState = false;
				}
			} else {
				bingState = false;
			}
		}
	});

}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:31,代码来源:MachineTranslationPreferencePage.java


示例10: translate

import com.google.api.translate.Translate; //导入依赖的package包/类
public static String translate(String text, Language sourceLang, Language targetLang, boolean markTranslation) {
    String translatedText = null;
    if(text != null && sourceLang != null && targetLang != null) {
        try {
            System.out.println("Google Translating '"+text+"' from '"+sourceLang+"' to '"+targetLang+"'");
            GoogleAPI.setHttpReferrer("http://wandora.org");
            if(apikey == null || apikey.length() == 0) {
                apikey = WandoraOptionPane.showInputDialog(Wandora.getWandora(), "Give your Google Translate API key?", "", "Give your Google Translate API key?");
                if(apikey != null) apikey = apikey.trim();
            }
            if(apikey != null) {
                GoogleAPI.setKey(apikey);
                translatedText = Translate.DEFAULT.execute(text, sourceLang, targetLang);
                if(translatedText != null && translatedText.length() == 0) {
                    translatedText = null;
                }
                if(translatedText != null && markTranslation) {
                    translatedText += " [GOOGLE TRANSLATION]";
                }
            }
        }
        catch(Exception e) {
            Wandora.getWandora().handleError(e);
            //e.printStackTrace();
        }
    }
    return translatedText;
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:29,代码来源:GoogleTranslateBox.java


示例11: main

import com.google.api.translate.Translate; //导入依赖的package包/类
public static void main (String[] args) {
	try {
		String translatedText = Translate.translate("Salut le monde", Language.SPANISH, Language.ENGLISH);
		System.out.println(translatedText);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:lgsilvestre,项目名称:Jogre,代码行数:9,代码来源:Test.java


示例12: onLoad

import com.google.api.translate.Translate; //导入依赖的package包/类
@Override
public void onLoad(Map<String, String> settings){
    Translate.setHttpReferrer("http://code.google.com/p/silvertrout/");
}
 
开发者ID:reggna,项目名称:silvertrout,代码行数:5,代码来源:Translator.java


示例13: getGoogleTranslation

import com.google.api.translate.Translate; //导入依赖的package包/类
private String getGoogleTranslation(String text, String originLangStr, String targetLangStr) throws GoogleAPIException {
	
	if (text.equals("") || text.equals(" ")) //avoid empty text
		return "";
	
	//String translatedText;
	String translatedText=text;// + "_" + num_tranlated_characters;
	
	//Check if text is in local dictionary
	if (isInLocalDictionary(text))
		return getLocalTranslation(text);
	
	else if(Parameters.call_online_translator){		
		// Set Google key here
		//GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
		//GoogleAPI.setKey("AIzaSyALd_XsjljQ0U0n8SB_3q6Iocc8kPeLsCo"); //api yuan gong
		GoogleAPI.setHttpReferrer("https://code.google.com/p/logmap-matcher/");
		//GoogleAPI.setKey("AIzaSyCXIH0M0Ya4WpnbHYIqNrRC4wXOqtszQuU"); //university of oxford api, max 100,000. Old key
		GoogleAPI.setKey("AIzaSyCOXm6fqYcqJtpFSrlMsgAy1VPkgNcrD2k"); //New key
		
		
		Language originLang = LanguageMap.get(originLangStr);
		Language targetLang = LanguageMap.get(targetLangStr);
		
		num_tranlated_characters+=text.length();
		num_calls++;
		
		LogOutput.printAlways("Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. Num chars translated so far: " + num_tranlated_characters);
		
		//Google call
		if (!Parameters.is_test_mode_multilingual){
			try{
				translatedText = Translate.DEFAULT.execute(text, originLang, targetLang);
			}
			catch (Exception e){
				LogOutput.printError("Error Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. " + e.getMessage());
				e.printStackTrace();
				return "";
			}
			//System.out.println(translatedText.length());
		}
		else{ //This is for test only!
			translatedText=text + "_" + num_tranlated_characters + "_g";
		}
		
		
	    //System.out.println(translatedText);
		
		//Store in on-the-fly dictionary
		addTranslation2Map(text, translatedText);		
	}
	
    return translatedText;

}
 
开发者ID:ernestojimenezruiz,项目名称:logmap-matcher,代码行数:56,代码来源:GoogleBasedTranslator.java



注:本文中的com.google.api.translate.Translate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Configurable类代码示例发布时间:2022-05-22
下一篇:
Java LocatedBlockProto类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap