PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV 25
→
Procedure Translate Message with Google Translate
Procedure Translate Message with Google Translate
Started by Boller, Aug., 31 2021 3:24 PM - No answer
Connect yourself…
Boller
#1
Registered member
3,657 messages
Popularité : +175 (223 votes)
Posted on August, 31 2021 - 3:24 PM
Procedure
Translate_Msg
(
s
Text
is ANSI string
,
s
Lang_Target
is string
)
s
Key
is string
=
"xxxxxxxxxxxxxxxxxxxxxxxxx"
// Chave do google Cloud
s
URL
is ANSI string
=
"https://translation.googleapis.com/language/translate/v2"
s
Param
is ANSI string
=
"?target="
+
s
Lang_Target
+
"&q="
+
s
Text
+
"&key="
+
s
Key
// Lista de idiomas: https://cloud.google.com/translate/docs/languages
// Translate
v
CallWS
is httpRequest
v
CallWS.Method
=
httpPost
v
CallWS.URL
=
s
URL
+
URLEncode
(
s
Param
)
ResponseWS
is restResponse
=
RESTSend
(
v
CallWS
)
//
//IF NOT Response_Verify(ResponseWS) THEN
//
RESULT False
//END
IF
ResponseWS
..
StatusCode
=
200
THEN
RESULT
ResponseWS.Content
// json
ELSE
RESULT
""
END
Procedure
Translate_msgX
(
LOCAL
TextoaTraduzir
is string UNICODE
,
IdiomaOrigem
is string
,
IdiomaDestino
is string
)
:
chaîne UNICODE
// Definicao dos Objetos REST
JSONRequest
is httpRequest
JSONReponse
is httpResponse
GOOGLE_KEY_TRANSLATE_API
is string
=
"xxxxxxxxxxxxxxxxxxxxxxxx"
JSONRequest.ContentType
=
typeMimeJSON
JSONRequest.URL
=
"https://translation.googleapis.com/language/translate/v2?key="
+
GOOGLE_KEY_TRANSLATE_API
JSONRequest.Content
= [
{"q":"%1",
"source":"%2",
"target":"%3",
"format":"text"
}
]
// Monta Conteudo
JSONRequest.Content
=
StringBuild
(
JSONRequest.Content
,
StringToUTF8
(
TextoaTraduzir
)
,
IdiomaOrigem
,
IdiomaDestino
)
JSONReponse
=
RESTSend
(
JSONRequest
)
IF
ErrorOccurred
THEN
Error
(
ErrorInfo
(
errFullDetails
)
)
RETURN
""
END
// Usei variant pq achei mais facil
let
v
=
JSONToVariant
(
JSONReponse.Content
)
// Usando este método é que o objeto v do tipo da variante deve conter
// toda a estrutura de árvore do objeto de retorno (que Windev reconstitui por si mesmo)
RETURN
""
+
v
.data.translations
[
1
]
.
translatedText
O macete esta na primeira linha
prezados bom dia
estou usando API google para traduzir etc
esta tudo ok
vem em Json com Unicode
o conteudo vem asim traduzido
{
"data"
:
{
"translations"
:
[ {
"translatedText"
:
"Charles Dickens levou uma vida muito ativa, sempre estabelecendo uma agenda cheia para si mesmo, a qual perseguiu com extrema energia. Al\u00e9m de trabalhar em seus romances, jornalismo semanal e leituras p\u00fablicas, ele produziu e apareceu em in\u00fameras produ\u00e7\u00f5es teatrais amadoras etc dist\u00e2ncias"
,
"detectedSourceLanguage"
:
"en"
} ] } }
ja usei utf8tostring etc etc e nao converte os caracteres acentos etc
onde estou errando
?
Resposta
StringToUTF8
(
…
--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Report
0
0
→ Go back to WINDEV 25
WINDEV 25
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text