Jump to content

Language translation


Recommended Posts

hi

I'm a small language translation program

but there are some problems

%S, %d  ,\n 
to
% s or % S  \\n  or \\N  converted and unicode problem   exam u200 ?

and save  as    ansi ,utf-8 ,unicode select  save file converted file

some time

MAINMENU_FILE_SAVE_DIFFERENTS = "Save Differents To File...

to

MAINMENU_FILE_SAVE_DIFFERENTS =

why ı dont now

and translation is very slow

how to provide a solution

next time then I need to do to other languages

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
Local $laFileLines[5000],$laFileLines_1[5000],$aDays[5000]
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("[#] Form1 [#]", 624, 130, 192, 124)
$Input1 = GUICtrlCreateInput("", 40, 40, 345, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
$Button1 = GUICtrlCreateButton("SELECT EN", 392, 40, 65, 25)
$Input2 = GUICtrlCreateInput("", 40, 72, 345, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
$Button2 = GUICtrlCreateButton("SAVE TR", 392, 72, 65, 25)
$Button3 = GUICtrlCreateButton("Translate to", 536, 40, 73, 57)
$Input3 = GUICtrlCreateInput("<<>>", 472, 72, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label1 = GUICtrlCreateLabel("Reagent", 480, 48, 33, 17)
$Label2 = GUICtrlCreateLabel("", 56, 96, 305, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
Case $Button1
Local $message = "Choose the language file."
Local $var_123 = FileOpenDialog($message, @desktopDir & "\", "Lang file(*.*)", 1 + 4)
If @error Then
   MsgBox(4096, "", "No File(s) chosen")
Else
    $var_123 = StringReplace($var_123, "|", @CRLF)
$var_12345 =  StringSplit($var_123, '.')
GUICtrlSetData($Input1, $var_123)
EndIf

Case $Button2
Local $var = FileSaveDialog("Choose the language file.", @desktopDir & "\", "Lang file (*."&$var_12345[2]&")", 2)
If @error Then
 MsgBox(4096, "", "Save cancelled.")
else
  $mmm_1= $var&"."&$var_12345[2]
  GUICtrlSetData($Input2,  $mmm_1)
EndIf

Case $Button3
 GUICtrlSetData($Label2, "Please wait translation is done")
$ayir = GUICtrlRead($Input3)
ttt( GUICtrlRead($Input1))
 _k88k(GUICtrlRead($Input1),"turkish.dat");turkishconverted.dat 
GUICtrlSetData($Label2, "")
    EndSwitch
WEnd

func ttt($var )
_FileReadToArray($var ,$laFileLines)
For $i = 1 To $laFileLines[0]
 GUICtrlSetData($Label2, "Please wait translation is done")
$laFileLines[$i] = StringReplace($laFileLines[$i], $ayir, "=")
$laFileLines[$i] = StringReplace($laFileLines[$i], "&", "")
$aDays = StringSplit($laFileLines[$i], '=')
if $aDays[0]=2 then 
filewrite("deneme.dat",$aDays[2]& @CRLF);Convert to go file
$kkk= _GoogleTranslate($aDays[2], "en", "tr")
filewrite("turkish.dat",StringUpper(stringleft($kkk, 1))&StringTrimleft($kkk, 1)& @CRLF)
sleep(100)
else
filewrite("deneme.dat",$aDays[1]& @CRLF)
filewrite("turkish.dat",$aDays[1]& @CRLF)
endif 
next
endfunc


func _k88k($var,$var_1)
_FileReadToArray($var ,$laFileLines)
_FileReadToArray($var_1 ,$laFileLines_1)
For $i = 1 To $laFileLines[0]
$laFileLines[$i] = StringReplace($laFileLines[$i], "<<>>", "=")
$aDays = StringSplit($laFileLines[$i], '=')
if $aDays[0]=2 then 
$laFileLines[$i] = StringReplace($laFileLines[$i], "="&$aDays[2], $ayir&$laFileLines_1[$i])
filewrite(GUICtrlRead($Input2),$laFileLines[$i]& @CRLF)
else
filewrite(GUICtrlRead($Input2),$laFileLines[$i]& @CRLF)
endif 
next
endfunc 

Func _GoogleTranslate($sText, $sFrom = "en", $sTo = "tr")
$Translation = InetRead('http://translate.google.com/translate_a/t?client=t&text=' & $sText & '&hl=en&sl=' & $sFrom & '&tl=' & $sTo)
If @error Then Return SetError(1, 0, 0)
$Translation = StringRegExp(BinaryToString($Translation), '"(?i)(.*?)"', 3)
If @error Then Return SetError(2, 0, 0)
If StringStripWS($Translation[0], 3) = "" Then Return $Translation[2]
Return $Translation[0]
EndFunc   ;==>_GoogleTranslate

Thank you now

look this  files

 

dosya_tranlate.rar

Edited by mesale0077
Link to comment
Share on other sites

This is due to your use of FileWrite with a file name. See the remark section under this function in the help file.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Did you try jchd's suggestion?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Longer story: you need to open the output file as UTF-8 by using $handle = FileOpen(...) with the encoding option set to UTF-8 (with or without BOM depending on context), then use FileWrite($handle, ...) to write to the file and FileClose($handle).

FileWrite("myfile.txt", $string) will convert $string to ANSI and writes it. Conversion from many languages to system-ANSI is not always possible.

Is that clear?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

$s5HTML[$i] = StringReplace($s5HTML[$i], "%s","-s-")

$s5HTML[$i]= StringReplace($s5HTML[$i], "%d","-d-" )

$s5HTML[$i] = StringReplace($s5HTML[$i], "n", "-n-")

 

or

$m = StringRegExp($s5HTML[$i], '%(.*?)', 3)

$s5HTML[$i] = StringReplace($s5HTML[$i],$m[0],"-"&$m[0]&-")

 

 some time fast ,some time slow why ?

but

%S, %d ,n

to

% s or % S n or N or %d to % D

converted and unicode problem exam u200 ?

 

 

% nearly find ?

%s ,  %d  ,   %I64d   %.0f  %.1f.....

 

error problem  source

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("[#]Dil dosyalarını çevirme programı[#]", 625, 131, 192, 124)
$Input1 = GUICtrlCreateInput("", 40, 40, 345, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
$Button1 = GUICtrlCreateButton("SELECT EN", 392, 40, 65, 25)
$Input2 = GUICtrlCreateInput("", 40, 72, 345, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
$Button2 = GUICtrlCreateButton("SAVE TR", 392, 72, 65, 25)
$Button3 = GUICtrlCreateButton("Translate to", 536, 40, 73, 57)
GUICtrlSetState($Button3, 128)
$Input3 = GUICtrlCreateInput("<<>>", 472, 72, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label1 = GUICtrlCreateLabel("Reagent", 480, 48, 33, 17)
$Progress1 = GUICtrlCreateProgress(40, 104, 329, 17)
$Label2 = GUICtrlCreateLabel("", 400, 104, 58, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            Case $Button1
Local $message = "Çevrilecek dil dosyasını seçiniz."
Local $var_123 = FileOpenDialog($message, @desktopDir & "\", "Lang file(*.*)", 1 + 4)
If @error Then
   MsgBox(4096, "", "Dosya seçilemedi.")
   
Else
     $var_123 = StringReplace($var_123, "|", @CRLF)
$var_12345 =  StringSplit($var_123, '.')
GUICtrlSetData($Input1, $var_123)
EndIf
Case $Button2
Local $var = FileSaveDialog("Dil dosyasını kaydedin.", @desktopDir & "\", "Lang file (*."&$var_12345[2]&")", 2)
If @error Then
 MsgBox(4096, "", "Kayıt yeri seçilemedi.")
else
  $mmm_1= $var&"."&$var_12345[2]
  GUICtrlSetData($Input2,  $mmm_1)
  GUICtrlSetState($Button3, 64)
EndIf
        
Case $Button3
 GUICtrlSetData($Label2, "Translation....")
$ayir = GUICtrlRead($Input3)
$Inputgg = GUICtrlRead($Input2)
GUICtrlSetState($Input3, 128)
GUICtrlSetState($Button1, 128)
GUICtrlSetState($Button2, 128)
GUICtrlSetState($Button3, 128)
ttt(GUICtrlRead($Input1))
 GUICtrlSetData($Progress1, "")
 GUICtrlSetData($Label2, "")
 GUICtrlSetState($Input3, 64)
  GUICtrlSetState($Button1, 64)
  GUICtrlSetState($Button2, 64)
 GUICtrlSetState($Button3, 64)
    EndSwitch
WEnd

func ttt($var_11)
$s5HTML = StringSplit(fileread($var_11), @LF)
$mmm00=100/$s5HTML[0]
$mmm_11=""
For $i = 1 To $s5HTML[0]
if GUIGetMsg()=-3 then exit
$m = StringRegExp($s5HTML[$i], '%(.*?)', 3)
$s5HTML[$i] = StringReplace($s5HTML[$i],$m[0] , "-"&$m[0]&"-")
$s5HTML[$i] = StringReplace($s5HTML[$i], "\n","-n-" )
$aDays = StringSplit(StringReplace(StringReplace($s5HTML[$i], $ayir, "="), "&", ""), '=')
if $aDays[0]=2 then 
GUICtrlSetData($Progress1, $mmm00*$i)
$mmm= _GoogleTranslate($aDays[2], "en", "tr")
$mmm = StringUpper(stringleft($mmm, 1))&StringTrimleft($mmm, 1)
$m = StringRegExp($mmm , '-(.*?)-', 3)
$mmm= StringReplace($mmm,$m[0],'%'&$m[0])
$mmm_11 &=$aDays[1]&$ayir&$mmm& @CRLF
else
$mmm_11 &=$s5HTML[$i]& @CRLF
endif 
if GUIGetMsg()=-3 then exit
next
$mmm_11 = StringReplace($mmm_11, "-n-","\n" )
filewrite($Inputgg,$mmm_11)
endfunc


Func _GoogleTranslate($sText, $sFrom = "en", $sTo = "tr")
$Translation = InetRead('http://translate.google.com/translate_a/t?client=t&text=' & $sText & '&hl=en&sl=' & $sFrom & '&tl=' & $sTo)
If @error Then Return SetError(1, 0, 0)
$Translation = StringRegExp(BinaryToString($Translation), '"(?i)(.*?)"', 3)
If @error Then Return SetError(2, 0, 0)
If StringStripWS($Translation[0], 3) = "" Then Return $Translation[2]
Return $Translation[0]
EndFunc   ;==>_GoogleTranslate
Edited by mesale0077
Link to comment
Share on other sites

Please try to explain what your problem is by using simple code, sample input and expected output. Write down the problem with simple construction in you language and try Google translate for posting your text.

Is the problem with converting printf style specifications to something that Google translate will keep alone then convert back to what they were?

Is the problem slowness with ... what?

Is the problem handling of Unicode?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

example

%s door %d window <%d> = %s door %d window <%d>  

this text goto translate google when

to converted

%s door %d window <%d> =% s kapı % d pencere u003c % d u003e

this problem %s to % s or %d to % d or % D  converted  and this problem  u003c % d u003e

no translation  %s to % s or %d to % d or % D

thank you now

 

Link to comment
Share on other sites

I think it will be simpler to go thru the input string and divide it (using regexp for instance) in parts that are not translatable and words sequences that may be passed to google translate for processing.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  :)

; by Mrbenkali
Opt("GUIONEVENTMODE", 1)
Global $link = "http://translate.google.com/"
Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Global $TITEL = "AUTOIT IS SIMPL ! "
Global $SCRIPTGUI = GUICreate($TITEL, 846, 550, -1, -1, 0X00040000)
GUISetOnEvent(-3, "__EXIT")
Global $EDIT1 = GUICtrlCreateEdit("", 0, 0, 844, 212)
GUICtrlSetFont($EDIT1, 24, 400, 0, "Arial")
Global $Edit2 = GUICtrlCreateEdit("", 0, 216, 844, 212)
GUICtrlSetFont($Edit2, 24, 400, 0, "Arial")
GUICtrlSetBkColor($Edit2, 0XFFFFFF)
GUICtrlCreateGroup("TRANSLATE TO  ", 8, 432, 830, 89)
Global $COMBO1 = GUICtrlCreateCombo("", 36, 471, 127, 25, 2097155)
GUICtrlSetOnEvent($COMBO1, "GOTRAN")
GUICtrlSetResizing($COMBO1, 65)
GUICtrlSetData($COMBO1, lGUI())
Global $Group1 = GUICtrlCreateGroup("SPEAK  ", 364, 448, 437, 65)
Global $Label1 = GUICtrlCreateLabel("", 380, 476, 100, 17)
Global $BUTTON1 = GUICtrlCreateButton("SPEAK", 499, 468, 99, 33)
GUICtrlSetOnEvent($BUTTON1, "GOSPEAK")
GUICtrlSetResizing($BUTTON1, 65)
Global $Checkbox1 = GUICtrlCreateCheckbox("TRANSLATE TEXT", 647, 475, 121, 17)
GUISetState()
While True
    Sleep(1000)
WEnd
Func GOSPEAK()
    Local $readtxt
    If GUICtrlRead($Checkbox1) = 1 Then
        $readtxt = GUICtrlRead($Edit2)
    Else
        $readtxt = GUICtrlRead($EDIT1)
    EndIf
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    GOOGLESPEEK($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>GOSPEAK
Func GOTRAN()
    Local $readtxt = GUICtrlRead($EDIT1)
    If $readtxt = "" Then Return
    WinSetTitle($SCRIPTGUI, "", "WAIT DOWNLOAD DATA...")
    GOOGLETRANS($readtxt)
    WinSetTitle($SCRIPTGUI, "", $TITEL)
EndFunc   ;==>GOTRAN
Func LANGOG()
    Return SLANG(GUICtrlRead($COMBO1), 2, 1)
EndFunc   ;==>LANGOG
Func GOOGLETRANS($TEXTTOTRANS)
    Local $TXT, $STEXT1, $STEXT, $STEXT2, $STEXT3, $STEXT4, $STEXT5, $GETTT
    GUICtrlSetData($Label1, SLANG(DETLANG(StringLeft(StringRegExpReplace($TEXTTOTRANS, "\r\n|\r|\n", Chr(32)), 90), 1), 1))
    GUICtrlSetData($Edit2, "")
    $STEXT = StringSplit($TEXTTOTRANS, @CRLF, 1)
    For $i = 1 To $STEXT[0]
        $STEXT1 = StringSplit($STEXT[$i], Chr(32), 1)
        For $O = 1 To $STEXT1[0]
            $TXT &= $STEXT1[$O] & Chr(32)
            If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
                $STEXT2 = StringSplit($TXT, ".")
                For $z = 1 To $STEXT2[0]
                    $STEXT3 = StringSplit($STEXT2[$z], '"')
                    For $L = 1 To $STEXT3[0]
                        $STEXT4 = StringSplit($STEXT3[$L], '?')
                        For $M = 1 To $STEXT4[0]
                            $STEXT5 = StringSplit($STEXT4[$M], '!')
                            For $S = 1 To $STEXT5[0]
                                If StringIsSpace($STEXT5[$S]) Then ContinueLoop
                                $GETTT = TRANTXT($STEXT5[$S])
                                GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & $GETTT & " ")
                                $TXT = ""
                                If $S <> $STEXT5[0] Then GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & '!')
                            Next
                            If $M <> $STEXT4[0] Then GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & '?')
                        Next
                        If $L <> $STEXT3[0] Then GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & '"')
                    Next
                    If $z <> $STEXT2[0] Then GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & ".")
                Next
            EndIf
        Next
        If $i <> $STEXT[0] Then GUICtrlSetData($Edit2, GUICtrlRead($Edit2) & @CRLF)
    Next
EndFunc   ;==>GOOGLETRANS
Func GOOGLESPEEK($TEXTTOSPEEK)
    Local $TXT, $OPEN, $STEXT1, $READ = "", $ENCODESSTRING, $RESTRING, $LANG, $MPFIL = FileGetShortName(@ScriptDir & "\" & Random(1, 99, 1) & ".MP3")
    $RESTRING = StringRegExpReplace($TEXTTOSPEEK, "\r\n|\r|\n", " ")
    $LANG = DETLANG(StringLeft($RESTRING, 90), 1)
    GUICtrlSetData($Label1, SLANG($LANG, 1))
    $STEXT1 = StringSplit($RESTRING, " ")
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & " "
        If StringLen($TXT) > 90 Or $O = $STEXT1[0] Then
            $ENCODESSTRING = URIENCODE($TXT)
            $READ &= StringTrimLeft(InetRead($link & "translate_tts?ie=UTF-8&tl=" & $LANG & "&q=" & $ENCODESSTRING, 1), 2)
            $TXT = ""
        EndIf
    Next
    $OPEN = FileOpen($MPFIL, 18)
    FileWrite($OPEN, "0X" & $READ)
    FileClose($OPEN)
    ShellExecute(@AutoItExe, '/AUTOIT3EXECUTELINE  "IF SOUNDPLAY(''' & $MPFIL & ''' ,1) THEN FILEDELETE(''' & $MPFIL & ''')"')
EndFunc   ;==>GOOGLESPEEK
Func TRANTXT($TXT)
    Local $ENCODESSTRING, $READ, $DATA
    $ENCODESSTRING = URIENCODE($TXT)
    $lghg = LANGOG()
    If StringInStr("ar fa iw ur yi", $lghg) > 0 Then
        GUICtrlSetStyle($Edit2, 3152064 + 2)
    Else
        GUICtrlSetStyle($Edit2, 3152064 + 0)
    EndIf
    $READ = DOWN($link & "translate_a/t?client=t&sl=auto&text=" & $ENCODESSTRING & "&tl=" & $lghg)
    $DATA = StringSplit($READ, '"')
    Return $DATA[2]
EndFunc   ;==>TRANTXT
Func DOWN($URL)
    $oHTTP.Open("GET", $URL, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1")
    $oHTTP.Send("")
    $oReceived = $oHTTP.ResponseText
    Return $oReceived
EndFunc   ;==>DOWN
Func URIENCODE($SDATA)
    Local $ADATA = StringSplit(BinaryToString(StringToBinary($SDATA, 4), 1), "")
    Local $NCHAR
    $SDATA = ""
    For $i = 1 To $ADATA[0]
        $NCHAR = Asc($ADATA[$i])
        Switch $NCHAR
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $SDATA &= $ADATA[$i]
            Case 32
                $SDATA &= "+"
            Case Else
                $SDATA &= "%" & Hex($NCHAR, 2)
        EndSwitch
    Next
    Return $SDATA
EndFunc   ;==>URIENCODE
Func DETLANG($STRI, $OPTT)
    Local $TST, $LANGGG
    $TST = DOWN($link & "translate_a/t?client=t&sl=auto&text=" & URIENCODE(StringLeft($STRI, 33)))
    $LANGGG = StringLeft(StringTrimLeft($TST, StringInStr($TST, '[["', 0, -1) + 2), 2)
    Return $LANGGG
EndFunc   ;==>DETLANG
Func SLANG($LANGG, $OPT, $OOPT = 2)
    $SLIS = StringSplit(LISL(), ";")
    For $i = 1 To $SLIS[0]
        Local $GETl = StringSplit($SLIS[$i], "|")
        If StringInStr($GETl[$OOPT], $LANGG, 2) Then
            Return $GETl[$OPT]
        EndIf
    Next
EndFunc   ;==>SLANG
Func lGUI()
    Local $llol, $SLIS
    $SLIS = StringSplit(LISL(), ";")
    For $i = 1 To $SLIS[0]
        $llol &= StringLeft($SLIS[$i], StringInStr($SLIS[$i], "|"))
    Next
    Return $llol
EndFunc   ;==>lGUI
Func LISL()
    Local $langlis = "Afrikaans|af;Albanian|sq;Arabic|ar;Armenian|hy;Azerbaijani|az;Basque|eu;Belarusian|be;Bengali|bn;Bulgarian|bg;Catalan|ca;Chinese|zh-CN;Croatian|hr;Czech|cs;Danish|da;Dutch|nl;English|en;Esperanto|eo;" & _
            "Estonian|et;Filipino|tl;Finnish|fi;French|fr;Galician|gl;Georgian|ka;German|de;Greek|el;Gujarati|gu;Haitian Creole|ht;Hebrew|iw;Hindi|hi;Hungarian|hu;Icelandic|is;Indonesian|id;Irish|ga;Italian|it;" & _
            "Japanese|ja;Kannada|kn;Khmer|km;Korean|ko;Lao|lo;Latin|la;Latvian|lv;Lithuanian|lt;Macedonian|mk;Malay|ms;Maltese|mt;Norwegian|no;Persian|fa;Polish|pl;Portuguese|pt;Romanian|ro;Russian|ru;" & _
            "Serbian|sr;Slovak|sk;Slovenian|sl;Spanish|es;Swahili|sw;Swedish|sv;Tamil|ta;Telugu|te;Thai|th;Turkish|tr;Ukrainian|uk;Urdu|ur;Vietnamese|vi;Welsh|cy;Yiddish|yi"
    Return $langlis
EndFunc   ;==>LISL
Func __EXIT()
    Exit
EndFunc   ;==>__EXIT
Edited by Mrbenkali
Link to comment
Share on other sites

What I did so far using Bing as translator:

;coded by UEZ 2013
#include <Array.au3>
$sFile = FileRead("c:\Temp\Test\English.properties")
$sText = StringStripCR(StringRegExpReplace($sFile, "(.*)(<<>>.*)", "$1"))
$aText = StringSplit($sText, @LF, 2)
Global $sInput
For $i = 0 To UBound($aText) - 1
    $sInput &= $aText[$i] & "^"
Next

$sResult = BingTranslator($sInput, "en", "tr")

$hFile = FileOpen(@ScriptDir & "\Translated.properties", 2)
FileWrite($hFile, $sResult)
FileClose($hFile)

Exit

Func BingTranslator($sText, $sLanguageFrom, $sLanguageTo, $iID = "68D088969D79A8B23AF8585CC83EBA2A05A97651", $sDelim = "<<>>")
;~  Local Const $sURL = "http://api.microsofttranslator.com/V2/ajax.svc/Translate?appId=" & $iID & "&from=" & $sLanguageFrom & "&to=" & $sLanguageTo & "&text=" & $sText & "&options=text/html"
    Local $iL = 3000, $iPerc
    Local $iLenght = Int(StringLen($sText) / $iL), $sTokens, $i, $j, $y, $sTranslated, $bTrans, $sTrans, $sResult, $sURL
    If $iLenght Then
        Local $aSplit = StringSplit($sText, "^", 2)
        ProgressOn("Progress", "Translating", "Translating ... 0 %")
        Local $iUB = UBound($aSplit) - 1, $iSleep = 1000
        $y = 0
        Do
            If StringLen($sTokens) + $aSplit[$i + 1] > $iL Then
                Sleep($iSleep)
                $sURL = "http://api.microsofttranslator.com/V2/Http.svc/Translate?appId=" & $iID & "&from=" & $sLanguageFrom & "&to=" & $sLanguageTo & "&text=" & StringRegExpReplace($sTokens, "[&%]*", "")
                $bTrans = InetRead($sURL)
                If @error Then ConsoleWrite("InetRead error " & @error & @CRLF)
                $sTrans = BinaryToString($bTrans, 4)
                $sResult = StringRegExpReplace($sTrans, ".*>(.*)<.*", "$1")
                $aTmp = StringSplit($sResult, "^", 2)
                For $j = 0 To UBound($aTmp) - 2
                    $sTranslated &= $aSplit[$y] & $sDelim & $aTmp[$j] & @CRLF
                    $y += 1
                Next
                $sTokens = ""
            EndIf
            $iPerc = Round(100 * ($i - 1) / $iUB, 0)
            ProgressSet($iPerc, "Translating ... " & $iPerc & " %")
            $sTokens &= StringStripWS($aSplit[$i], 3) & "^"
            $i += 1
        Until $i = $iUB
        Sleep($iSleep)
        $sURL = "http://api.microsofttranslator.com/V2/Http.svc/Translate?appId=" & $iID & "&from=" & $sLanguageFrom & "&to=" & $sLanguageTo & "&text=" & StringRegExpReplace($sTokens, "[&%]*", "")
        $bTrans = InetRead($sURL)
        If @error Then ConsoleWrite("InetRead error " & @error & @CRLF)
        $sTrans = BinaryToString($bTrans, 4)
        $sResult = StringRegExpReplace($sTrans, ".*>(.*)<.*", "$1")
        $aTmp = StringSplit($sResult, "^", 2)
        If Not @error Then
            For $j = 0 To UBound($aTmp) - 2
                $sTranslated &= $aSplit[$y] & $sDelim & $aTmp[$j] & @CRLF
                $y += 1
            Next
        EndIf
        ProgressOff()
        Return $sTranslated
    Else
        $sURL = "http://api.microsofttranslator.com/V2/Http.svc/Translate?appId=" & $iID & "&from=" & $sLanguageFrom & "&to=" & $sLanguageTo & "&text=" & StringRegExpReplace($sText, "[%&]*", ""); & "&options=text/html"
        Local $sTranslated = InetRead($sURL)
        If @error Then Return SetError(1, @error, 0)
        $sTranslated = StringRegExpReplace(BinaryToString($sTranslated, 4), ".*>(.*)<.*", "$1")
        Return $sTranslated
    EndIf
EndFunc

I've not much experiences with this kind of stuff. 

Modify the paths appropriately.

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 1 year later...

There was a post that made me look at this stuff again, but I have no desire to drop the code there as no effort has been extended.  At least if it is found here the person will have searched.

I combined your bing text, with google audio, you may have to extend the sleep if you return 0 consistently:

#include <IE.au3>

$sInput = "Merry Christmas"
$sInLang = "en"
$sOutLang = "es"

$sResult = BingTranslator($sInput, $sInLang, $sOutLang)

$oIE = _IECreate("http://translate.google.com/translate_tts?tl=" & $sOutLang & "&q=" & $sResult , 0 , 0 , 1 , 0)
msgbox(0, '' , $sInLang & " --> " & $sOutLang & @LF & @LF & $sResult)

run("taskkill /IM wmplayer.exe")
_IEQuit($oIE)
exit

Func BingTranslator($sText, $sLanguageFrom, $sLanguageTo, $iID = "68D088969D79A8B23AF8585CC83EBA2A05A97651", $sDelim = "<<>>")

    Local  $sTranslated,  $sURL

        $sURL = "http://api.microsofttranslator.com/V2/Http.svc/Translate?appId=" & $iID & "&from=" & $sLanguageFrom & "&to=" & $sLanguageTo & "&text=" & StringRegExpReplace($sText, "[%&]*", ""); & "&options=text/html"
        Sleep(3000)
        Local $sTranslated = InetRead($sURL , 3)
        Sleep(1000)
        If @error Then Return SetError(1, @error, 0)
        $sTranslated = StringRegExpReplace(BinaryToString($sTranslated, 4), ".*>(.*)<.*", "$1")
        Return $sTranslated
EndFunc

I have no idea why the sleep after inetread made for more consistent behavior, could have been purely coincidental and unnecessary.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...