Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/12/2024 in all areas

  1. ...moreover, a Function, plays a function that in turn can Return a value. Forget programming until you can get some reading comprehension as otherwise you would not know what is been presented in front of your eyes.
    1 point
  2. Here is the final reworked script taking care of UTF-8 encoding, so cyrillic characters shouldn't be a problem anymore. Now that all original text is always converted to UTF-8 (no matter they were Ascii characters, Ansi, Unicode, mix) then my initial issue with end of lines has disappeared as EOL's will be restored correctly at their right place, when the translation is done (no more workaround !) I notice the script needs the last version of AutoIt (because of Maps in Json.au3) Though some translations will work with older versions of AutoIt (because Maps aren't always used during translation, depending on the original text), it's better to use last version of AutoIt (3.3.16.1) to cover all cases. @AspirinJunkie I would like to know : this is what is found in your version of Json.au3 I found on the net : ; Title .........: JSON-UDF ; Version .......: 0.9 ; AutoIt Version : 3.3.16.1 ... ; Author(s) .....: AspirinJunkie ; Last changed ..: 2023-01-16 In case there is a newer version, could you please indicate where it can be downloaded ? Thanks to everybody involved in this script #include "Json.au3" ; (by @AspirinJunkie) #include <StringConstants.au3> ;======================== Local $sLangFROM = "auto" Local $sLangTO = "en" ; <===== change this line for the language of the translated text ;======================== Local $sInput, $sClipGet = StringToBinary(ClipGet(), $SB_UTF8) ; for example ะป (russian) becomes 0xD0BB For $i = 3 To StringLen($sClipGet) Step 2 ; start at 3 to bypass "0x" $sInput &= "%" & StringMid($sClipGet, $i, 2) Next Local $sTranslated = _GoogleAPITranslate($sInput, $sLangFROM, $sLangTO) ; If (Not @compiled) And ProcessExists("scite.exe") Then ; not 100% proof to bypass the 3 following ConsoleWrite, but better than nothing. If Not @compiled Then ; probably a bit faster than preceding line. It will be enough when script run from .a3x shortcut placed on Desktop. ConsoleWrite("ORIGINAL: " & BinaryToString($sClipGet, $SB_ANSI) & @crlf) ; in case of accented characters in Scite console. ConsoleWrite("----------------------------------------------------------------------------------------------------------------" & @crlf) ConsoleWrite(BinaryToString(StringToBinary($sTranslated, $SB_UTF8), $SB_ANSI) & @crlf) EndIf MsgBox(262144, "Translated From " & $sLangFROM & " To " & $sLangTO, $sTranslated) ; $MB_TOPMOST = 262144 ;============================================== Func _GoogleAPITranslate($sMytext, $sFrom, $sTo) Local $sUrl, $oHTTP, $sResponse, $JSONData, $sOutput = "", $aData $sUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $sMytext $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $sUrl, False) $oHTTP.Send() $sResponse = $oHTTP.ResponseText $JSONData = _JSON_Parse($sResponse) If VarGetType($JSONData) = 'Array' Then $aData = $JSONData[0] If VarGetType($aData) = 'Array' Then For $i = 0 To UBound($aData) -1 $sOutput &= ($aData[$i])[0] Next EndIf EndIf Return $sOutput EndFunc ;==>_GoogleAPITranslate * Update May 11, 2024 : Added a test on @compiled to bypass (or not) all ConsoleWrite lines and the functions included in them. Though it's not 100% proof, it's better than nothing. Other ways to detect more precisely how the script was launched can be found on the Forum, for example by using _WinAPI_GetParentProcess and _WinAPI_GetProcessName, but do we really need all this just to bypass 3 ConsoleWrite lines ? Let's test on @compiled for the moment, we'll see...
    1 point
×
×
  • Create New...