jresine

convert japan charactere to english for trad

2 posts in this topic

Hello

Here is a translation script that I found here and that works.
The problem is that the script does not translate the Japanese characters, would anyone have a solution?

 

$sString = "泉に歌う"
$sFrom = "jp"
$sTo = "en"
$sURL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $sString

$oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", $sURL, False)
$oHTTP.Send()
$sData = $oHTTP.ResponseText
$sData = StringRegExpReplace($sData, '.*?\["(.*?)(?<!\\)"[^\[]*', "$1" & @CRLF)
FileWrite(@ScriptDir & "\test.txt",$sData)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Japan is ja, you should probably use URI encoding as well for example:

$sString = "泉に歌う"
$sFrom = "ja"
$sTo = "en"
$sURL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & _URIEncode($sString)
$oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", $sURL, False)
$oHTTP.Send()
$sData = $oHTTP.ResponseText
FileWrite(@ScriptDir & "\test.txt",$sData)

;~ ProgAndy
Func _URIEncode($sData)
    ; Prog@ndy
    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

 

Edited by Subz

Share this post


Link to post
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