百度百科:
Google 翻译是谷歌公司提供一项免费的翻译服务,可提供103 种语言之间的即时翻译,支持任意两种语言之间的字词、句子和网页翻译。可分析的人工翻译文档越多,译文的质量就会越高。
Google 翻译生成译文时,会在数百万篇文档中查找各种模式,以便决定最佳翻译。Google 翻译通过在经过人工翻译的文档中检测各种模式,进行合理的猜测,然后得出适当的翻译。这种在大量文本中查找各种范例的过程称为“统计机器翻译”。由于译文是由机器生成的,因此并不是所有的译文都是完美的。
从百度百科上我们了解到谷歌翻译是非常强大的!
《声明》
本制作只做技术交流,切勿用作非法用途,商业用途等违法行为!如发现有以上行为均和本人无关,请自行承担后果!大家且行且珍惜。
源码和软件地址:
https://www.lanzous.com/i5upsle
------------------------------------------------------------------------
比较简单哈!就是一个字符串转码即可!
那就直接上源码吧!
#Region Project Attributes
#ApplicationLabel: B4A谷歌翻译示例
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ht As HttpJob
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private BT_FY As Button
Private TXT_IN As EditText
Private TXT_JSON As AutoCompleteEditText
Private TXT_RES As AutoCompleteEditText
Private su As StringUtils
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("FY")
Activity.AddMenuItem("GY", "关于")
End Sub
Sub GY_Click
Msgbox("更多精彩内容请关注微信公众号:VB小源码","关于")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub BT_FY_Click
If TXT_IN.Text<>"" Then
Dim fy_str As String
fy_str=su.EncodeUrl(TXT_IN.Text, "UTF8")
ht.Initialize("gl",Me)
ht.Download("https://translate.google.cn/translate_a/single?dj=1&q="& fy_str &"&sl=zh-CN&tl=en&hl=zh-CN&ie=UTF-8&oe=UTF-8&client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dt=md&dt=ss&dt=ex&otf=3")
ProgressDialogShow("正在翻译,请稍等...")
End If
End Sub
Sub JobDone(job As HttpJob)
Try
If job.Success Then
ProgressDialogHide
If job.JobName="gl" Then
Dim Reader As TextReader,tmp As String,str As StringBuilder
str.Initialize
Reader.Initialize(job.GetInputStream)
tmp=Reader.ReadAll
TXT_JSON.Text=tmp
'----------------------
Dim text, pattern As String
text = tmp
pattern = $"trans":.+?","$
Dim mh As Matcher
mh = Regex.Matcher(pattern, text)
Do While mh.Find
str.Append(mh.Match)
Loop
''------------------------
TXT_RES.Text=str.ToString.SubString(8).SubString2(0,str.ToString.SubString(8).Length-2)
End If
Else
ProgressDialogHide
ToastMessageShow("翻译失败",True)
End If
Catch
ToastMessageShow("出错啦!",True)
End Try
End Sub
今天教程就到此结束了!