Hi everyone
Following Ben's reply I've put together my solution for handling
machine translation of our texts. Ben encouraged me to post the code
here, so here it is. If anyone can use it great. It's very much cut
down to getting the job done (translating non-html texts). It's in
classic ASP and MSSQL, but it can easily be translated to any
scripting language.
I've decided to store the translations in a field in the same database
table as the original texts are in. In order to keep track of when a
text was updated the last time, I've added a datetime field too.
In order not to violate the TOS, all the texts must be translated
every 1-2 of days. To do this I use a cron job that runs every hour.
(Actually a free site uptime checker tool that calls a page on our
site every hour). Every time this runs, my script will take the 2 % of
texts that has gone the longest time since the last update. Having it
set at 2 % will get all the texts updated in about 2 days (48 hours x
2 % = 96 %). This is within the rules, but at the same time requests
to Google are kept to a minimum and spread out as much as possible -
No need to waste Google's resources on unneccesary requests.
CRON JOB:
[CODE]
strSQL = "SELECT TOP 2 PERCENT IdField, OriginalText, TranslatedText,
LanguageCode FROM YourTable ORDER BY LastTranslated ASC"
Set rs = database.Execute(strSQL, adCmdText)
If Not rs.EOF Then arrTexts = rs.GetRows
rs.Close
Set rs = Nothing
For i = 0 To Ubound(arrTexts, 2)
If Len(arrTexts(1, i)) > 0 Then
strText = Translate(Trim(arrTexts(1, i)), strFromLang,
strToLang, false)
If strText <> "" Then
strSQL = "SET DATEFORMAT DMY;UPDATE YourTable SET
TranslatedText = '" & Replace(strText, "'", "''") & "', LastTranslated
= '" & FormatSQLTime(Now) & "' WHERE IdField = " & arrTexts(0, i)
Set opdatering = database.Execute(komtekst, adCmdText)
End If
End If
Next
[/CODE]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-AJAX-Search-API?hl=en
-~----------~----~----~----~------~----~------~--~---