Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requieres PSImaging module, here's the oneliner to install it :
- #& ([scriptblock]::Create((iwr -uri http://tinyurl.com/Install-GitHubHostedModule).Content)) -GitHubUserName Positronic-IO -ModuleName PSImaging -Branch 'master' -Scope CurrentUser
- #Requieres Greenshot https://getgreenshot.org/downloads/
- #And the following settings : enable Quick Preferences/ Destination/ Copy to clipboard
- # disable Quick Preferences/ Effects/ Show Notifications
- #Requieres AHK https://www.autohotkey.com/download/?
- #Hot key will be ALT+Z
- #
- #<!z::
- #Path_To_File = "C:\Temp\Get-TextfromImage.ps1"
- #MsgBox,,Traduction, % JEE_RunGetStdOut("PowerShell.exe -ExecutionPolicy Bypass -File " Path_To_File)
- #return
- #
- #JEE_RunGetStdOut(vTarget, vSize:="")
- #{
- # DetectHiddenWindows, On
- # vComSpec := A_ComSpec ? A_ComSpec : ComSpec
- # Run, % vComSpec,, Hide, vPID
- # WinWait, % "ahk_pid " vPID
- # DllCall("kernel32\AttachConsole", "UInt",vPID)
- # oShell := ComObjCreate("WScript.Shell")
- # oExec := oShell.Exec(vTarget)
- # vStdOut := ""
- # if !(vSize = "")
- # VarSetCapacity(vStdOut, vSize)
- # while !oExec.StdOut.AtEndOfStream
- # vStdOut := oExec.StdOut.ReadAll()
- # DllCall("kernel32\FreeConsole")
- # Process, Close, % vPID
- # return vStdOut
- #}
- #C:\Temp\Get-TextfromImage.ps1 :
- Function TranslateText ([string]$TextToTranslate, [string]$TargetLanguage) {
- <#
- .SYNOPSIS
- Translate text to the specified language.
- The exhaustive languages list is available in $LanguagesList.
- .EXAMPLE
- TranslateText "hello" "es"
- TranslateText $Text "fr"
- #>
- $LanguagesList = @('af','sq','am','ar','hy','az','eu','be','bn','bs','bg','ca','ceb','zh-CN','zh-TW','co','hr','cs','da','nl','en','eo','et','fi','fr','fy','gl','ka','de','el','gu','ht','ha','haw','he','hi','hmn','hu','is','ig','id','ga','it','ja','jv','kn','kk','km','rw','ko','ku','ky','lo','lv','lt','lb','mk','mg','ms','ml','mt','mi','mr','mn','my','ne','no','ny','or','ps','fa','pl','pt','pa','ro','ru','sm','gd','sr','st','sn','sd','si','sk','sl','so','es','su','sw','sv','tl','tg','ta','tt','te','th','tr','tk','uk','ur','ug','uz','vi','cy','xh','yi','yo','zu')
- $PhrasesList = New-Object -TypeName 'System.Collections.ArrayList'
- $Uri = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$TextToTranslate"
- $RawResponse = (Invoke-WebRequest -Uri $Uri -Method Get).Content
- $RawResponse = $RawResponse -replace '\[','' -replace '\]','' -replace '\"','' -replace '\\r\\n',''
- $RawResponse = $RawResponse -split ',' | foreach {
- If($_ -ne "null" -And (-Not $LanguagesList.Contains($_)) -And $_ -ne "true" -And $_ -notmatch "^[\d\.]+$" -And $_ -notlike "*.md" -And $TextToTranslate -notmatch $_ -And $_ -notmatch "[0123456789abcdef]{$($_.length)}") {
- $PhrasesList.Add($_)
- }
- }
- Return $PhrasesList
- }
- Add-Type -Assembly PresentationCore
- [void][reflection.assembly]::loadwithpartialname("system.windows.forms")
- [Windows.Clipboard]::Clear()
- [system.windows.forms.sendkeys]::sendwait('{PRTSC}')
- While(-Not [Windows.Clipboard]::ContainsImage()) {
- Start-Sleep -Milliseconds 200
- }
- $ImgFullPath = "$env:TEMP\textImg.png"
- Get-Clipboard -Format Image | ForEach-Object -MemberName Save -ArgumentList $ImgFullPath
- $TextImg = Get-ChildItem $ImgFullPath | Export-ImageText
- TranslateText $TextImg "fr"
- $ErrorActionPreference = "silentlycontinue"
- Remove-Item $ImgFullPath
- $ErrorActionPreference = "Continue"
Add Comment
Please, Sign In to add comment