VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Language translation webpage - screen scrapes Google's language tools (http://www.google.com/langua

by Tom Reed (1 Submission)
Category: String Manipulation
Compatability: VB Script
Difficulty: Unknown Difficulty
Originally Published: Thu 28th April 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Language translation webpage - screen scrapes Google's language tools (https://www.google.com/language_tools?hl=en) page for text translations.

API Declarations


Remove the above and below comment tags from the Code section and paste into an ASP page. Find more code snippets at http://code.tomsexplorer.com.
------->

Rate Language translation webpage - screen scrapes Google's language tools (http://www.google.com/langua



<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
lang = Request("lang") & ""
i = LEFT(lang,2)
o = RIGHT(lang,2)

function getFrench(var)
on error resume next
  set xmlhttp = server.CreateObject("Msxml2.XMLHTTP") 
  strURL = "http://translate.google.com/translate_t" 
  xmlhttp.open "POST", strURL, false
  xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"

  xmlhttp.send "text=" + var + "&langpair=" & i & "|" & o & "&hl=" & i & "&ie=UTF-8&oe=UTF-8" 
  
  if err.number = 0 then
    sText = xmlhttp.responseText
    x = 0
    alldata = sText
    Do Until x = 1
x = x + 1

findstart=instr(alldata,"<textarea")
findend=instr(alldata,"</textarea>")
findlength = findend - findstart
tag = mid(alldata,findstart, findlength) & "</textarea><br>"
''Response.Write tag

''DELETE BEGINNING textarea tag in its entirety
findstart = instr(tag,"<")
findend = instr(tag, ">")
findlength = findend - findstart
tag = Replace(tag, mid(tag,findstart,findlength +1), "")

''DELETE ENDING textarea tag in its entirety
findstart = instr(tag,"<")
findend = instr(tag, ">")
findlength = findend - findstart
tag = Replace(tag, mid(tag,findstart,findlength +1), "")

''TRANSLATION SHOULD BE ALL THAT IS LEFT IN tag variable
Response.Write tag

alldata = Replace(alldata,Left(alldata,findend), "")
Loop
  end if
end function
%>
<center>
<b>TRANSLATOR TOOL</b>
<form name="frmCAPATesting" method="POST" >
<table width="550">
<tr>
<td>
<textarea name="french" cols="65" rows="10"><%=request("french")%></textarea>
</td>
</tr>

<tr>
<td align="right">
<select name="lang">
<option value="en|de" <%if lang="en|de" then%> selected <%end if%>>English to German</option>
<option value="en|es" <%if lang="en|es" then%> selected <%end if%>>English to Spanish</option>
<option value="en|fr" <%if lang="en|fr" then%> selected <%end if%>>English to French</option>
<option value="en|it" <%if lang="en|it" then%> selected <%end if%>>English to Italian</option>
<option value="en|pt" <%if lang="en|pt" then%> selected <%end if%>>English to Portuguese</option>
<option value="de|en" <%if lang="de|en" then%> selected <%end if%>>German to English</option>
<option value="es|en" <%if lang="es|en" then%> selected <%end if%>>Spanish to English</option>
<option value="fr|en" <%if lang="fr|en" then%> selected <%end if%>>French to English</option>
<option value="it|en" <%if lang="it|en" then%> selected <%end if%>>Italian to English</option>
<option value="pt|en" <%if lang="pt|en" then%> selected <%end if%>>Portuguese to English</option>
<option value="fr|de" <%if lang="fr|de" then%> selected <%end if%>>French to German</option>
<option value="de|fr" <%if lang="de|fr" then%> selected <%end if%>>German to French</option>
</select>
<input type="submit" value="submit" id=submit1 name=submit1>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="action" value="translate"><br>
</td>
</tr>
<tr>
<td>
<%
if request("action") & "" = "translate" then
Response.Write "<b>Translation:</b>"
getFrench request("french")
end if
%>
</td>
</tr>
</table>
</form>
</center>

</BODY>
</HTML>
---->



Download this snippet    Add to My Saved Code

Language translation webpage - screen scrapes Google's language tools (http://www.google.com/langua Comments

No comments have been posted about Language translation webpage - screen scrapes Google's language tools (http://www.google.com/langua. Why not be the first to post a comment about Language translation webpage - screen scrapes Google's language tools (http://www.google.com/langua.

Post your comment

Subject:
Message:
0/1000 characters