从日语翻译到罗马字 [英] Translate from Japanese to Romaji

查看:90
本文介绍了从日语翻译到罗马字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写将日语翻译为罗马字的C#程序.我已经安装了Microsoft Visual Studio International Pack v.1.0和2.0.

I need to write C# program that translate from Japanese to Romaji. I have installed Microsoft Visual Studio International Pack v.1.0 and 2.0.

但是,它只能从罗马字转换为日语.请让我知道还能用来将日语翻译为罗马字的其他内容.

However, it has only conversion from Romaji to Japanese. Please let me know what else I can use to be able to translate from Japanese to Romaji.

谢谢

KlimG

推荐答案

对于翻译,我过去曾使用下面显示的G​​oogle api(可通过网页访问). ;下面显示的网页代码在VBA中,但是可以轻松转换为C#.可以通过XML文档访问getElementById()方法 class().

For translations, I have used in the past the google api shown below that I access through a webpage.  The webpage code shown below is in VBA but can be easily translated to C#.  the getElementById() method can be accessed through an XML document class().

--------------------------------------------------- -------------------------------------------------- -------------

--------------------------------------------------------------------------------------------------------------

HTML代码-可以放入文件中

HTML Code - Can be put into a file

<!DOCTYPE html PUBLIC``-//W3C//DTD XHTML 1.0 Transitional//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. dtd ">
< html xmlns =" http://www.w3.org/1999/xhtml " xml:lang ="zh-cn" lang ="en">
< head>
< meta http-equiv ="Content-Type" content =" text/html; charset = UTF-8"; />
< title> Google翻译API</title>
</head>
< body>
< form name ="f" id ="f" action =#" onsubmit =" translate();返回false;>
< textarea name ="foreign_text"; id ="foreign_text";行="4"
cols ="60"</textarea>
< br/>
< br/>
<输入类型=提交"; id ="submit_button" value =翻译成英文"
onfocus =" this.blur();"; />
< br/>
< br/>
< textarea name =翻译"; id ="translation"行="4" cols ="60"
onfocus ="this.select();"; readonly ="true"</textarea>//form>
< br/>
< script type ="文本/javascript" src =" http://www.google.com/jsapi"</script>
< script type ="文本/javascript">
google.load("language","1"));
函数translate(){var
originaltext = document.forms ["f"].foreign_text.value;
google.language.translate(原始文字,","en",function(result){
document.forms ["f"].translation.value =(result.error)?(错误:
"+ result.error.message):结果翻译; }); }
</script>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Google Translate API</title>
</head>
<body>
<form name="f" id="f" action="#" onsubmit="translate(); return false;">
<textarea name="foreign_text" id="foreign_text" rows="4"
cols="60"></textarea>
<br />
<br />
<input type="submit" id="submit_button" value="Translate into English"
onfocus="this.blur();" />
<br />
<br />
<textarea name="translation" id="translation" rows="4" cols="60"
onfocus="this.select();" readonly="true"></textarea></form>
<br />
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("language", "1");
function translate() {var
originaltext=document.forms["f"].foreign_text.value;
google.language.translate(originaltext, "", "en", function(result) {
document.forms["f"].translation.value = (result.error)?("Error:
"+result.error.message):result.translation; }); }
</script>
</body>
</html>

--------------------------------------------------- -------------------------------------------------- ----------

-----------------------------------------------------------------------------------------------------------

VBA代码

Sub translation()

Sub translate()

将objIE视作对象
将strServAcct设为字符串昏暗

Dim objIE As Object
Dim strServAcct As String

URL ="c:\ temp \ working \ translation.html"
'打开Internet Explorer
设置IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate网址

URL = "c:\temp\working\translation.html"
'Open Internet Explorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate URL

在IE.Busy = True或IE.readystate时执行<> 4
DoEvents
循环

Do While IE.Busy = True Or IE.readystate <> 4
DoEvents
Loop

设置ForeignCells = Range("A1:B1")
对于ForeignCells中的每个单元格
设置ForeignText = IE.document.getElementById("foreign_text")
设置Submit = IE.document.getElementById("submit_button")

Set ForeignCells = Range("A1:B1")
For Each cell In ForeignCells
Set ForeignText = IE.document.getElementById("foreign_text")
Set submit = IE.document.getElementById("submit_button")

ForeignText.innertext =单元格值
提交.选择
提交.点击
IE.Busy = True或IE.readystate<> 4
DoEvents
循环
设置翻译= IE.document.getElementById(翻译"))
Translation.innertext = cell.Offset(1,0).Value
下一个单元格
结束

ForeignText.innertext = cell.Value
submit.Select
submit.Click
Do While IE.Busy = True Or IE.readystate <> 4
DoEvents
Loop
Set Translation = IE.document.getElementById("Translation")
Translation.innertext = cell.Offset(1, 0).Value
Next cell
End Sub

 


这篇关于从日语翻译到罗马字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆